Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: ios/chrome/browser/ui/qr_scanner/qr_scanner_transitioning_delegate.mm

Issue 2589803002: Upstream Chrome on iOS source code [6/11]. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/ui/qr_scanner/qr_scanner_transitioning_delegate.h"
6
7 #include "base/ios/block_types.h"
8
9 namespace {
10
11 // The default animation duration.
12 const NSTimeInterval kDefaultDuration = 0.25;
13
14 enum QRScannerTransition { PRESENT, DISMISS };
15
16 } // namespace
17
18 // Animates the QR Scanner transition. If initialized with the |PRESENT|
19 // transition, positions the QR Scanner view below its presenting view
20 // controller's view in the container view and animates the presenting view to
21 // slide up. If initialized with the |DISMISS| transition, positions the
22 // presenting view controller's view above the QR Scanner view in the container
23 // view and animates the presenting view to slide down.
24 @interface QRScannerTransitionAnimator
25 : NSObject<UIViewControllerAnimatedTransitioning> {
26 QRScannerTransition _transition;
27 }
28
29 - (instancetype)initWithTransition:(QRScannerTransition)transition;
30
31 @end
32
33 @implementation QRScannerTransitionAnimator
34
35 - (instancetype)initWithTransition:(QRScannerTransition)transition {
36 self = [super init];
37 if (self) {
38 _transition = transition;
39 }
40 return self;
41 }
42
43 - (void)animateTransition:
44 (id<UIViewControllerContextTransitioning>)transitionContext {
45 UIView* containerView = [transitionContext containerView];
46 UIView* presentedView =
47 [transitionContext viewForKey:UITransitionContextToViewKey];
48 UIView* presentingView =
49 [transitionContext viewForKey:UITransitionContextFromViewKey];
50
51 // Get the final frame for the presented view.
52 UIViewController* presentedViewController = [transitionContext
53 viewControllerForKey:UITransitionContextToViewControllerKey];
54 CGRect finalFrame =
55 [transitionContext finalFrameForViewController:presentedViewController];
56
57 CGRect initialFrame;
58 ProceduralBlock animations;
59
60 switch (_transition) {
61 case PRESENT:
62 [containerView insertSubview:presentedView belowSubview:presentingView];
63 initialFrame = finalFrame;
64 finalFrame.origin.y = -finalFrame.size.height;
65 animations = ^void {
66 [presentingView setFrame:finalFrame];
67 };
68 break;
69 case DISMISS:
70 [containerView insertSubview:presentedView aboveSubview:presentingView];
71 initialFrame = finalFrame;
72 initialFrame.origin.y = -initialFrame.size.height;
73 animations = ^void {
74 [presentedView setFrame:finalFrame];
75 };
76 break;
77 }
78
79 // Set the frame for the presented view.
80 if (!CGRectIsEmpty(initialFrame)) {
81 [presentedView setFrame:initialFrame];
82 }
83 [presentedView layoutIfNeeded];
84
85 void (^completion)(BOOL) = ^void(BOOL finished) {
86 [transitionContext completeTransition:finished];
87 };
88
89 // Animate the transition.
90 [UIView animateWithDuration:kDefaultDuration
91 delay:0
92 options:UIViewAnimationOptionCurveEaseInOut
93 animations:animations
94 completion:completion];
95 }
96
97 - (void)animationEnded:(BOOL)transitionCompleted {
98 return;
99 }
100
101 - (NSTimeInterval)transitionDuration:
102 (id<UIViewControllerContextTransitioning>)transitionContext {
103 return kDefaultDuration;
104 }
105
106 @end
107
108 @implementation QRScannerTransitioningDelegate
109
110 - (id<UIViewControllerAnimatedTransitioning>)
111 animationControllerForPresentedController:(UIViewController*)presented
112 presentingController:(UIViewController*)presenting
113 sourceController:(UIViewController*)source {
114 return [[[QRScannerTransitionAnimator alloc] initWithTransition:PRESENT]
115 autorelease];
116 }
117
118 - (id<UIViewControllerAnimatedTransitioning>)
119 animationControllerForDismissedController:(UIViewController*)dismissed {
120 return [[[QRScannerTransitionAnimator alloc] initWithTransition:DISMISS]
121 autorelease];
122 }
123
124 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698