Commit 273c468d authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Cleanup names for TabGrid animations

This CL updates the names of the object providing animations
information from GridTransitionStateProviding to
GridTransitionAnimationLayoutProviding and its methods.
Hopefully, it should increase the readability of the responsibilities
of the object.

It also removes the context parameter as it wasn't used and I plan to
use this class without a context in a future CL.

Bug: 1038034
Change-Id: I9b125cdd6603c7441dfd0cb9f1c256b3d60e37b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2050317Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Auto-Submit: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#740327}
parent 61d76753
...@@ -7,12 +7,12 @@ ...@@ -7,12 +7,12 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
@protocol GridTransitionStateProviding; @protocol GridTransitionAnimationLayoutProviding;
@interface TabGridTransitionHandler @interface TabGridTransitionHandler
: NSObject<UIViewControllerTransitioningDelegate> : NSObject<UIViewControllerTransitioningDelegate>
@property(nonatomic, weak) id<GridTransitionStateProviding> provider; @property(nonatomic, weak) id<GridTransitionAnimationLayoutProviding> provider;
@end @end
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#import "ios/chrome/browser/ui/tab_grid/tab_grid_transition_handler.h" #import "ios/chrome/browser/ui/tab_grid/tab_grid_transition_handler.h"
#import "ios/chrome/browser/ui/tab_grid/transitions/grid_to_visible_tab_animator.h" #import "ios/chrome/browser/ui/tab_grid/transitions/grid_to_visible_tab_animator.h"
#import "ios/chrome/browser/ui/tab_grid/transitions/grid_transition_state_providing.h" #import "ios/chrome/browser/ui/tab_grid/transitions/grid_transition_animation_layout_providing.h"
#import "ios/chrome/browser/ui/tab_grid/transitions/reduced_motion_animator.h" #import "ios/chrome/browser/ui/tab_grid/transitions/reduced_motion_animator.h"
#import "ios/chrome/browser/ui/tab_grid/transitions/tab_to_grid_animator.h" #import "ios/chrome/browser/ui/tab_grid/transitions/tab_to_grid_animator.h"
...@@ -23,8 +23,8 @@ animationControllerForPresentedController:(UIViewController*)presented ...@@ -23,8 +23,8 @@ animationControllerForPresentedController:(UIViewController*)presented
sourceController:(UIViewController*)source { sourceController:(UIViewController*)source {
if (!UIAccessibilityIsReduceMotionEnabled() && if (!UIAccessibilityIsReduceMotionEnabled() &&
self.provider.selectedCellVisible) { self.provider.selectedCellVisible) {
return return [[GridToVisibleTabAnimator alloc]
[[GridToVisibleTabAnimator alloc] initWithStateProvider:self.provider]; initWithAnimationLayoutProvider:self.provider];
} }
ReducedMotionAnimator* simpleAnimator = [[ReducedMotionAnimator alloc] init]; ReducedMotionAnimator* simpleAnimator = [[ReducedMotionAnimator alloc] init];
simpleAnimator.presenting = YES; simpleAnimator.presenting = YES;
...@@ -34,7 +34,8 @@ animationControllerForPresentedController:(UIViewController*)presented ...@@ -34,7 +34,8 @@ animationControllerForPresentedController:(UIViewController*)presented
- (id<UIViewControllerAnimatedTransitioning>) - (id<UIViewControllerAnimatedTransitioning>)
animationControllerForDismissedController:(UIViewController*)dismissed { animationControllerForDismissedController:(UIViewController*)dismissed {
if (!UIAccessibilityIsReduceMotionEnabled()) { if (!UIAccessibilityIsReduceMotionEnabled()) {
return [[TabToGridAnimator alloc] initWithStateProvider:self.provider]; return [[TabToGridAnimator alloc]
initWithAnimationLayoutProvider:self.provider];
} }
ReducedMotionAnimator* simpleAnimator = [[ReducedMotionAnimator alloc] init]; ReducedMotionAnimator* simpleAnimator = [[ReducedMotionAnimator alloc] init];
simpleAnimator.presenting = NO; simpleAnimator.presenting = NO;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/tab_grid/tab_grid_paging.h" #import "ios/chrome/browser/ui/tab_grid/tab_grid_paging.h"
#import "ios/chrome/browser/ui/tab_grid/transitions/grid_transition_state_providing.h" #import "ios/chrome/browser/ui/tab_grid/transitions/grid_transition_animation_layout_providing.h"
@protocol ApplicationCommands; @protocol ApplicationCommands;
@protocol GridConsumer; @protocol GridConsumer;
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
// View controller representing a tab switcher. The tab switcher has an // View controller representing a tab switcher. The tab switcher has an
// incognito tab grid, regular tab grid, and remote tabs. // incognito tab grid, regular tab grid, and remote tabs.
@interface TabGridViewController @interface TabGridViewController
: UIViewController<TabGridPaging, GridTransitionStateProviding> : UIViewController <TabGridPaging, GridTransitionAnimationLayoutProviding>
@property(nonatomic, weak) id<ApplicationCommands> dispatcher; @property(nonatomic, weak) id<ApplicationCommands> dispatcher;
......
...@@ -312,7 +312,7 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) { ...@@ -312,7 +312,7 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
return l10n_util::GetNSString(stringID); return l10n_util::GetNSString(stringID);
} }
#pragma mark - GridTransitionStateProviding properties #pragma mark - GridTransitionAnimationLayoutProviding properties
- (BOOL)isSelectedCellVisible { - (BOOL)isSelectedCellVisible {
if (self.activePage != self.currentPage) if (self.activePage != self.currentPage)
...@@ -323,8 +323,7 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) { ...@@ -323,8 +323,7 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
: gridViewController.selectedCellVisible; : gridViewController.selectedCellVisible;
} }
- (GridTransitionLayout*)layoutForTransitionContext: - (GridTransitionLayout*)transitionLayout {
(id<UIViewControllerContextTransitioning>)context {
GridViewController* gridViewController = GridViewController* gridViewController =
[self gridViewControllerForPage:self.activePage]; [self gridViewControllerForPage:self.activePage];
if (!gridViewController) if (!gridViewController)
...@@ -335,13 +334,11 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) { ...@@ -335,13 +334,11 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
return layout; return layout;
} }
- (UIView*)proxyContainerForTransitionContext: - (UIView*)animationViewsContainer {
(id<UIViewControllerContextTransitioning>)context {
return self.view; return self.view;
} }
- (UIView*)proxyPositionForTransitionContext: - (UIView*)animationViewsContainerBottomView {
(id<UIViewControllerContextTransitioning>)context {
return self.scrollView; return self.scrollView;
} }
......
...@@ -11,9 +11,9 @@ source_set("transitions") { ...@@ -11,9 +11,9 @@ source_set("transitions") {
"grid_to_visible_tab_animator.mm", "grid_to_visible_tab_animator.mm",
"grid_transition_animation.h", "grid_transition_animation.h",
"grid_transition_animation.mm", "grid_transition_animation.mm",
"grid_transition_animation_layout_providing.h",
"grid_transition_layout.h", "grid_transition_layout.h",
"grid_transition_layout.mm", "grid_transition_layout.mm",
"grid_transition_state_providing.h",
"reduced_motion_animator.h", "reduced_motion_animator.h",
"reduced_motion_animator.mm", "reduced_motion_animator.mm",
"tab_to_grid_animator.h", "tab_to_grid_animator.h",
......
...@@ -7,17 +7,17 @@ ...@@ -7,17 +7,17 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
@protocol GridTransitionStateProviding; @protocol GridTransitionAnimationLayoutProviding;
// Animator object for transitioning from a collection view of square-ish items // Animator object for transitioning from a collection view of square-ish items
// (the "grid") into a fullscreen view controller (the "tab"). // (the "grid") into a fullscreen view controller (the "tab").
@interface GridToVisibleTabAnimator @interface GridToVisibleTabAnimator
: NSObject<UIViewControllerAnimatedTransitioning> : NSObject<UIViewControllerAnimatedTransitioning>
// Initialize an animator object with |stateProvider| to provide state // Initialize an animator object with |animationLayoutProvider| to provide
// information for the transition. // layout information for the transition.
- (instancetype)initWithStateProvider: - (instancetype)initWithAnimationLayoutProvider:
(id<GridTransitionStateProviding>)stateProvider; (id<GridTransitionAnimationLayoutProviding>)animationLayoutProvider;
@end @end
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
#include "ios/chrome/browser/crash_report/breakpad_helper.h" #include "ios/chrome/browser/crash_report/breakpad_helper.h"
#import "ios/chrome/browser/ui/tab_grid/transitions/grid_transition_animation.h" #import "ios/chrome/browser/ui/tab_grid/transitions/grid_transition_animation.h"
#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/tab_grid/transitions/grid_transition_layout.h"
#import "ios/chrome/browser/ui/tab_grid/transitions/grid_transition_state_providing.h"
#import "ios/chrome/browser/ui/util/layout_guide_names.h" #import "ios/chrome/browser/ui/util/layout_guide_names.h"
#import "ios/chrome/browser/ui/util/named_guide.h" #import "ios/chrome/browser/ui/util/named_guide.h"
#import "ios/chrome/browser/ui/util/property_animator_group.h" #import "ios/chrome/browser/ui/util/property_animator_group.h"
...@@ -17,7 +17,8 @@ ...@@ -17,7 +17,8 @@
#endif #endif
@interface GridToVisibleTabAnimator () @interface GridToVisibleTabAnimator ()
@property(nonatomic, weak) id<GridTransitionStateProviding> stateProvider; @property(nonatomic, weak) id<GridTransitionAnimationLayoutProviding>
animationLayoutProvider;
// Animation object for this transition. // Animation object for this transition.
@property(nonatomic, strong) GridTransitionAnimation* animation; @property(nonatomic, strong) GridTransitionAnimation* animation;
// Transition context passed into this object when the animation is started. // Transition context passed into this object when the animation is started.
...@@ -26,14 +27,11 @@ ...@@ -26,14 +27,11 @@
@end @end
@implementation GridToVisibleTabAnimator @implementation GridToVisibleTabAnimator
@synthesize stateProvider = _stateProvider;
@synthesize animation = _animation;
@synthesize transitionContext = _transitionContext;
- (instancetype)initWithStateProvider: - (instancetype)initWithAnimationLayoutProvider:
(id<GridTransitionStateProviding>)stateProvider { (id<GridTransitionAnimationLayoutProviding>)animationLayoutProvider {
if ((self = [super init])) { if ((self = [super init])) {
_stateProvider = stateProvider; _animationLayoutProvider = animationLayoutProvider;
} }
return self; return self;
} }
...@@ -65,11 +63,11 @@ ...@@ -65,11 +63,11 @@
// Get the layout of the grid for the transition. // Get the layout of the grid for the transition.
GridTransitionLayout* layout = GridTransitionLayout* layout =
[self.stateProvider layoutForTransitionContext:transitionContext]; [self.animationLayoutProvider transitionLayout];
// Ask the state provider for the views to use when inserting the animation. // Ask the state provider for the views to use when inserting the animation.
UIView* proxyContainer = UIView* animationContainer =
[self.stateProvider proxyContainerForTransitionContext:transitionContext]; [self.animationLayoutProvider animationViewsContainer];
// Find the rect for the animating tab by getting the content area layout // Find the rect for the animating tab by getting the content area layout
// guide. // guide.
...@@ -89,8 +87,9 @@ ...@@ -89,8 +87,9 @@
[layout.activeItem populateWithSnapshotsFromView:viewWithNamedGuides [layout.activeItem populateWithSnapshotsFromView:viewWithNamedGuides
middleRect:finalRect]; middleRect:finalRect];
layout.expandedRect = [proxyContainer convertRect:viewWithNamedGuides.frame layout.expandedRect =
fromView:presentedView]; [animationContainer convertRect:viewWithNamedGuides.frame
fromView:presentedView];
NSTimeInterval duration = [self transitionDuration:transitionContext]; NSTimeInterval duration = [self transitionDuration:transitionContext];
// Create the animation view and insert it. // Create the animation view and insert it.
...@@ -99,9 +98,10 @@ ...@@ -99,9 +98,10 @@
duration:duration duration:duration
direction:GridAnimationDirectionExpanding]; direction:GridAnimationDirectionExpanding];
UIView* viewBehindProxies = UIView* bottomViewForAnimations =
[self.stateProvider proxyPositionForTransitionContext:transitionContext]; [self.animationLayoutProvider animationViewsContainerBottomView];
[proxyContainer insertSubview:self.animation aboveSubview:viewBehindProxies]; [animationContainer insertSubview:self.animation
aboveSubview:bottomViewForAnimations];
// Reparent the active cell view so that it can animate above the presenting // Reparent the active cell view so that it can animate above the presenting
// view while the rest of the animation is embedded inside it. // view while the rest of the animation is embedded inside it.
......
...@@ -2,38 +2,34 @@ ...@@ -2,38 +2,34 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_TAB_GRID_TRANSITIONS_GRID_TRANSITION_STATE_PROVIDING_H_ #ifndef IOS_CHROME_BROWSER_UI_TAB_GRID_TRANSITIONS_GRID_TRANSITION_ANIMATION_LAYOUT_PROVIDING_H_
#define IOS_CHROME_BROWSER_UI_TAB_GRID_TRANSITIONS_GRID_TRANSITION_STATE_PROVIDING_H_ #define IOS_CHROME_BROWSER_UI_TAB_GRID_TRANSITIONS_GRID_TRANSITION_ANIMATION_LAYOUT_PROVIDING_H_
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@class GridTransitionLayout; @class GridTransitionLayout;
// Objects conforming to this protocol can provide state information to // Objects conforming to this protocol can provide information for the
// transition delegates and animators for a grid. // animation of the transitions from and to a grid.
@protocol GridTransitionStateProviding @protocol GridTransitionAnimationLayoutProviding
// YES if the currently selected cell is visible in the grid. // YES if the currently selected cell is visible in the grid.
@property(nonatomic, readonly, getter=isSelectedCellVisible) @property(nonatomic, readonly, getter=isSelectedCellVisible)
BOOL selectedCellVisible; BOOL selectedCellVisible;
// Asks the provider for an aray of layout items that provide objects for use // Asks the provider for the information on the layout of the grid of cells,
// in building an animated transition. // used in transition animations.
- (GridTransitionLayout*)layoutForTransitionContext: - (GridTransitionLayout*)transitionLayout;
(id<UIViewControllerContextTransitioning>)context;
// Asks the provider for the view to add proxy views to when building an // Asks the provider for the view to which the animation views should be added.
// animated transition. - (UIView*)animationViewsContainer;
- (UIView*)proxyContainerForTransitionContext:
(id<UIViewControllerContextTransitioning>)context;
// Asks the provider for the view (if any) that proxy views should be added // Asks the provider for the view (if any) that animation views should be added
// in front of when building an animated transition. It's an error if this // in front of when building an animated transition. It's an error if this
// view is not nil and isn't an immediate subview of the view returned by // view is not nil and isn't an immediate subview of the view returned by
// |-proxyContainerForTransitionContext:| // |-animationViewsContainer|
- (UIView*)proxyPositionForTransitionContext: - (UIView*)animationViewsContainerBottomView;
(id<UIViewControllerContextTransitioning>)context;
@end @end
#endif // IOS_CHROME_BROWSER_UI_TAB_GRID_TRANSITIONS_TAB_GRID_TRANSITION_STATE_PROVIDING_H_ #endif // IOS_CHROME_BROWSER_UI_TAB_GRID_TRANSITIONS_GRID_TRANSITION_ANIMATION_LAYOUT_PROVIDING_H_
...@@ -7,16 +7,16 @@ ...@@ -7,16 +7,16 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
@protocol GridTransitionStateProviding; @protocol GridTransitionAnimationLayoutProviding;
// Animator object for transitioning from a fullscreen view controller (the // Animator object for transitioning from a fullscreen view controller (the
// "tab") into a collection view of square-ish items (the "grid"). // "tab") into a collection view of square-ish items (the "grid").
@interface TabToGridAnimator : NSObject<UIViewControllerAnimatedTransitioning> @interface TabToGridAnimator : NSObject<UIViewControllerAnimatedTransitioning>
// Initialize an animator object with |stateProvider| to provide state // Initialize an animator object with |animationLayoutProvider| to provide
// information for the transition. // layout information for the transition.
- (instancetype)initWithStateProvider: - (instancetype)initWithAnimationLayoutProvider:
(id<GridTransitionStateProviding>)stateProvider; (id<GridTransitionAnimationLayoutProviding>)animationLayoutProvider;
@end @end
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
#import "ios/chrome/browser/ui/tab_grid/transitions/tab_to_grid_animator.h" #import "ios/chrome/browser/ui/tab_grid/transitions/tab_to_grid_animator.h"
#import "ios/chrome/browser/ui/tab_grid/transitions/grid_transition_animation.h" #import "ios/chrome/browser/ui/tab_grid/transitions/grid_transition_animation.h"
#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/tab_grid/transitions/grid_transition_layout.h"
#import "ios/chrome/browser/ui/tab_grid/transitions/grid_transition_state_providing.h"
#import "ios/chrome/browser/ui/util/layout_guide_names.h" #import "ios/chrome/browser/ui/util/layout_guide_names.h"
#import "ios/chrome/browser/ui/util/named_guide.h" #import "ios/chrome/browser/ui/util/named_guide.h"
#import "ios/chrome/browser/ui/util/property_animator_group.h" #import "ios/chrome/browser/ui/util/property_animator_group.h"
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
#endif #endif
@interface TabToGridAnimator () @interface TabToGridAnimator ()
@property(nonatomic, weak) id<GridTransitionStateProviding> stateProvider; @property(nonatomic, weak) id<GridTransitionAnimationLayoutProviding>
animationLayoutProvider;
// Animation object for this transition. // Animation object for this transition.
@property(nonatomic, strong) GridTransitionAnimation* animation; @property(nonatomic, strong) GridTransitionAnimation* animation;
// Transition context passed into this object when the animation is started. // Transition context passed into this object when the animation is started.
...@@ -25,14 +26,11 @@ ...@@ -25,14 +26,11 @@
@end @end
@implementation TabToGridAnimator @implementation TabToGridAnimator
@synthesize stateProvider = _stateProvider;
@synthesize animation = _animation;
@synthesize transitionContext = _transitionContext;
- (instancetype)initWithStateProvider: - (instancetype)initWithAnimationLayoutProvider:
(id<GridTransitionStateProviding>)stateProvider { (id<GridTransitionAnimationLayoutProviding>)animationLayoutProvider {
if ((self = [super init])) { if ((self = [super init])) {
_stateProvider = stateProvider; _animationLayoutProvider = animationLayoutProvider;
} }
return self; return self;
} }
...@@ -71,12 +69,12 @@ ...@@ -71,12 +69,12 @@
[gridView layoutIfNeeded]; [gridView layoutIfNeeded];
// Ask the state provider for the views to use when inserting the animation. // Ask the state provider for the views to use when inserting the animation.
UIView* proxyContainer = UIView* animationContainer =
[self.stateProvider proxyContainerForTransitionContext:transitionContext]; [self.animationLayoutProvider animationViewsContainer];
// Get the layout of the grid for the transition. // Get the layout of the grid for the transition.
GridTransitionLayout* layout = GridTransitionLayout* layout =
[self.stateProvider layoutForTransitionContext:transitionContext]; [self.animationLayoutProvider transitionLayout];
// Get the initial rect for the snapshotted content of the active tab. // Get the initial rect for the snapshotted content of the active tab.
// Conceptually this transition is dismissing a tab (a BVC). However, // Conceptually this transition is dismissing a tab (a BVC). However,
...@@ -95,8 +93,9 @@ ...@@ -95,8 +93,9 @@
[layout.activeItem populateWithSnapshotsFromView:viewWithNamedGuides [layout.activeItem populateWithSnapshotsFromView:viewWithNamedGuides
middleRect:initialRect]; middleRect:initialRect];
layout.expandedRect = [proxyContainer convertRect:viewWithNamedGuides.frame layout.expandedRect =
fromView:dismissingView]; [animationContainer convertRect:viewWithNamedGuides.frame
fromView:dismissingView];
NSTimeInterval duration = [self transitionDuration:transitionContext]; NSTimeInterval duration = [self transitionDuration:transitionContext];
// Create the animation view and insert it. // Create the animation view and insert it.
...@@ -105,9 +104,10 @@ ...@@ -105,9 +104,10 @@
duration:duration duration:duration
direction:GridAnimationDirectionContracting]; direction:GridAnimationDirectionContracting];
UIView* viewBehindProxies = UIView* bottomViewForAnimations =
[self.stateProvider proxyPositionForTransitionContext:transitionContext]; [self.animationLayoutProvider animationViewsContainerBottomView];
[proxyContainer insertSubview:self.animation aboveSubview:viewBehindProxies]; [animationContainer insertSubview:self.animation
aboveSubview:bottomViewForAnimations];
[self.animation.animator addCompletion:^(UIViewAnimatingPosition position) { [self.animation.animator addCompletion:^(UIViewAnimatingPosition position) {
BOOL finished = (position == UIViewAnimatingPositionEnd); BOOL finished = (position == UIViewAnimatingPositionEnd);
......
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