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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/qr_scanner/qr_scanner_transitioning_delegate.mm
diff --git a/ios/chrome/browser/ui/qr_scanner/qr_scanner_transitioning_delegate.mm b/ios/chrome/browser/ui/qr_scanner/qr_scanner_transitioning_delegate.mm
new file mode 100644
index 0000000000000000000000000000000000000000..a484890182f134f2072b94bb1a96cd1148c603f7
--- /dev/null
+++ b/ios/chrome/browser/ui/qr_scanner/qr_scanner_transitioning_delegate.mm
@@ -0,0 +1,124 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/chrome/browser/ui/qr_scanner/qr_scanner_transitioning_delegate.h"
+
+#include "base/ios/block_types.h"
+
+namespace {
+
+// The default animation duration.
+const NSTimeInterval kDefaultDuration = 0.25;
+
+enum QRScannerTransition { PRESENT, DISMISS };
+
+} // namespace
+
+// Animates the QR Scanner transition. If initialized with the |PRESENT|
+// transition, positions the QR Scanner view below its presenting view
+// controller's view in the container view and animates the presenting view to
+// slide up. If initialized with the |DISMISS| transition, positions the
+// presenting view controller's view above the QR Scanner view in the container
+// view and animates the presenting view to slide down.
+@interface QRScannerTransitionAnimator
+ : NSObject<UIViewControllerAnimatedTransitioning> {
+ QRScannerTransition _transition;
+}
+
+- (instancetype)initWithTransition:(QRScannerTransition)transition;
+
+@end
+
+@implementation QRScannerTransitionAnimator
+
+- (instancetype)initWithTransition:(QRScannerTransition)transition {
+ self = [super init];
+ if (self) {
+ _transition = transition;
+ }
+ return self;
+}
+
+- (void)animateTransition:
+ (id<UIViewControllerContextTransitioning>)transitionContext {
+ UIView* containerView = [transitionContext containerView];
+ UIView* presentedView =
+ [transitionContext viewForKey:UITransitionContextToViewKey];
+ UIView* presentingView =
+ [transitionContext viewForKey:UITransitionContextFromViewKey];
+
+ // Get the final frame for the presented view.
+ UIViewController* presentedViewController = [transitionContext
+ viewControllerForKey:UITransitionContextToViewControllerKey];
+ CGRect finalFrame =
+ [transitionContext finalFrameForViewController:presentedViewController];
+
+ CGRect initialFrame;
+ ProceduralBlock animations;
+
+ switch (_transition) {
+ case PRESENT:
+ [containerView insertSubview:presentedView belowSubview:presentingView];
+ initialFrame = finalFrame;
+ finalFrame.origin.y = -finalFrame.size.height;
+ animations = ^void {
+ [presentingView setFrame:finalFrame];
+ };
+ break;
+ case DISMISS:
+ [containerView insertSubview:presentedView aboveSubview:presentingView];
+ initialFrame = finalFrame;
+ initialFrame.origin.y = -initialFrame.size.height;
+ animations = ^void {
+ [presentedView setFrame:finalFrame];
+ };
+ break;
+ }
+
+ // Set the frame for the presented view.
+ if (!CGRectIsEmpty(initialFrame)) {
+ [presentedView setFrame:initialFrame];
+ }
+ [presentedView layoutIfNeeded];
+
+ void (^completion)(BOOL) = ^void(BOOL finished) {
+ [transitionContext completeTransition:finished];
+ };
+
+ // Animate the transition.
+ [UIView animateWithDuration:kDefaultDuration
+ delay:0
+ options:UIViewAnimationOptionCurveEaseInOut
+ animations:animations
+ completion:completion];
+}
+
+- (void)animationEnded:(BOOL)transitionCompleted {
+ return;
+}
+
+- (NSTimeInterval)transitionDuration:
+ (id<UIViewControllerContextTransitioning>)transitionContext {
+ return kDefaultDuration;
+}
+
+@end
+
+@implementation QRScannerTransitioningDelegate
+
+- (id<UIViewControllerAnimatedTransitioning>)
+animationControllerForPresentedController:(UIViewController*)presented
+ presentingController:(UIViewController*)presenting
+ sourceController:(UIViewController*)source {
+ return [[[QRScannerTransitionAnimator alloc] initWithTransition:PRESENT]
+ autorelease];
+}
+
+- (id<UIViewControllerAnimatedTransitioning>)
+animationControllerForDismissedController:(UIViewController*)dismissed {
+ return [[[QRScannerTransitionAnimator alloc] initWithTransition:DISMISS]
+ autorelease];
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698