Commit a9dab387 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Add reduced animations for contained Browser

This CL adds the animations for entering/leaving the TabGrid when the
motion is reduced. It also adds a parameter to be able to present it
with no animations.

Bug: 1038034
Change-Id: Idf7d4f48049137007ed9f76bae2828eb90322c22
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2061156
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742136}
parent 8922f8c9
......@@ -284,15 +284,18 @@
// It's also expected that |tabSwitcher| will be |self.tabSwitcher|, but that
// may not be worth a DCHECK?
BOOL animated = !self.animationsDisabledForTesting;
// If a BVC is currently being presented, dismiss it. This will trigger any
// necessary animations.
if (self.bvcContainer) {
if (base::FeatureList::IsEnabled(kContainedBVC)) {
[self.baseViewController contentWillAppearAnimated:NO];
[self.baseViewController contentWillAppearAnimated:animated];
self.baseViewController.childViewControllerForStatusBarStyle = nil;
self.transitionHandler = [[TabGridTransitionHandler alloc]
initWithLayoutProvider:self.baseViewController];
self.transitionHandler.animationDisabled = !animated;
[self.transitionHandler
transitionFromBrowser:self.bvcContainer
toTabGrid:self.baseViewController
......@@ -304,7 +307,6 @@
} else {
self.bvcContainer.transitioningDelegate = self.legacyTransitionHandler;
self.bvcContainer = nil;
BOOL animated = !self.animationsDisabledForTesting;
[self.baseViewController dismissViewControllerAnimated:animated
completion:nil];
}
......@@ -361,6 +363,7 @@
self.transitionHandler = [[TabGridTransitionHandler alloc]
initWithLayoutProvider:self.baseViewController];
self.transitionHandler.animationDisabled = !animated;
[self.transitionHandler transitionFromTabGrid:self.baseViewController
toBrowser:self.bvcContainer
withCompletion:^{
......
......@@ -18,6 +18,9 @@
- (instancetype)init NS_UNAVAILABLE;
// Whether the animations should be disabled.
@property(nonatomic, assign) BOOL animationDisabled;
// Starts the transition from the |browser| to the |tabGrid|. Assumes that the
// |browser| is currently a child ViewController of the |tabGrid|. Calls
// |completion| when the transition finishes.
......
......@@ -8,6 +8,7 @@
#import "ios/chrome/browser/ui/tab_grid/transitions/grid_transition_animation_layout_providing.h"
#import "ios/chrome/browser/ui/tab_grid/transitions/grid_transition_layout.h"
#import "ios/chrome/browser/ui/util/named_guide.h"
#include "ios/chrome/browser/ui/util/ui_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -16,6 +17,7 @@
namespace {
const CGFloat kBrowserToGridDuration = 0.3;
const CGFloat kGridToBrowserDuration = 0.5;
const CGFloat kReducedMotionDuration = 0.25;
} // namespace
@interface TabGridTransitionHandler ()
......@@ -41,13 +43,25 @@ const CGFloat kGridToBrowserDuration = 0.5;
- (void)transitionFromBrowser:(UIViewController*)browser
toTabGrid:(UIViewController*)tabGrid
withCompletion:(void (^)(void))completion {
// TODO(crbug.com/1038034): Add support for ReducedMotionAnimator.
[browser willMoveToParentViewController:nil];
if (UIAccessibilityIsReduceMotionEnabled()) {
[self transitionWithReducedAnimationsForTab:browser.view
beingPresented:NO
withCompletion:^{
[browser.view removeFromSuperview];
[browser removeFromParentViewController];
if (completion)
completion();
}];
return;
}
CGFloat duration = self.animationDisabled ? 0 : kBrowserToGridDuration;
self.animation = [[GridTransitionAnimation alloc]
initWithLayout:[self transitionLayoutForTabInViewController:browser]
duration:kBrowserToGridDuration
duration:duration
direction:GridAnimationDirectionContracting];
UIView* animationContainer = [self.layoutProvider animationViewsContainer];
......@@ -81,8 +95,6 @@ const CGFloat kGridToBrowserDuration = 0.5;
- (void)transitionFromTabGrid:(UIViewController*)tabGrid
toBrowser:(UIViewController*)browser
withCompletion:(void (^)(void))completion {
// TODO(crbug.com/1038034): Add support for ReducedMotionAnimator.
[tabGrid addChildViewController:browser];
browser.view.frame = tabGrid.view.bounds;
......@@ -90,9 +102,23 @@ const CGFloat kGridToBrowserDuration = 0.5;
browser.view.alpha = 0;
if (UIAccessibilityIsReduceMotionEnabled() ||
!self.layoutProvider.selectedCellVisible) {
[self transitionWithReducedAnimationsForTab:browser.view
beingPresented:YES
withCompletion:^{
[browser
didMoveToParentViewController:tabGrid];
if (completion)
completion();
}];
return;
}
CGFloat duration = self.animationDisabled ? 0 : kGridToBrowserDuration;
self.animation = [[GridTransitionAnimation alloc]
initWithLayout:[self transitionLayoutForTabInViewController:browser]
duration:kGridToBrowserDuration
duration:duration
direction:GridAnimationDirectionExpanding];
UIView* animationContainer = [self.layoutProvider animationViewsContainer];
......@@ -153,4 +179,58 @@ const CGFloat kGridToBrowserDuration = 0.5;
return layout;
}
// Animates the transition for the |tab|, whether it is |beingPresented| or not,
// with reduced animations.
- (void)transitionWithReducedAnimationsForTab:(UIView*)tab
beingPresented:(BOOL)beingPresented
withCompletion:(void (^)(void))completion {
// The animation here creates a simple quick zoom effect -- the tab view
// fades in/out as it expands/contracts. The zoom is not large (75% to 100%)
// and is centered on the view's final center position, so it's not directly
// connected to any tab grid positions.
CGFloat tabFinalAlpha;
CGAffineTransform tabFinalTransform;
CGFloat tabFinalCornerRadius;
if (beingPresented) {
// If presenting, the tab view animates in from 0% opacity, 75% scale
// transform, and a 26pt corner radius
tabFinalAlpha = 1;
tabFinalTransform = tab.transform;
tab.transform = CGAffineTransformScale(tabFinalTransform, 0.75, 0.75);
tabFinalCornerRadius = DeviceCornerRadius();
tab.layer.cornerRadius = 26.0;
} else {
// If dismissing, the the tab view animates out to 0% opacity, 75% scale,
// and 26px corner radius.
tabFinalAlpha = 0;
tabFinalTransform = CGAffineTransformScale(tab.transform, 0.75, 0.75);
tab.layer.cornerRadius = DeviceCornerRadius();
tabFinalCornerRadius = 26.0;
}
// Set clipsToBounds on the animating view so its corner radius will look
// right.
BOOL oldClipsToBounds = tab.clipsToBounds;
tab.clipsToBounds = YES;
CGFloat duration = self.animationDisabled ? 0 : kReducedMotionDuration;
[UIView animateWithDuration:duration
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
tab.alpha = tabFinalAlpha;
tab.transform = tabFinalTransform;
tab.layer.cornerRadius = tabFinalCornerRadius;
}
completion:^(BOOL finished) {
tab.clipsToBounds = oldClipsToBounds;
if (!finished && beingPresented) {
[tab removeFromSuperview];
}
if (completion)
completion();
}];
}
@end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment