Commit b6ee67ef authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Fix secondary toolbar animations.

The old implementation of |updateFootersForFullscreenProgress:|
just updates the height constraint for the toolbar, which isn't
actually applied to the model layer until the end of the runloop. In
order to animate this change, the model layer must be updated from
within the animation block, so |-layoutIfNeeded| is called to commit
the new constraint value to the view hierarchy.

Simply calling |-layoutIfNeeded| on the toolbar view itself will
only animate the height, not the positioning.  Since the positioning
constraint is added to BVC.view, we'd need to force a full BVC layout
to also animate the position correctly.  However, since BVC is a
heavy-weight view, and this is called for every scroll offset, calling
|-layoutIfNeeded| on BVC.view may introduce performance regressions.

This CL adds a container view for the secondary toolbar that has a
constant frame equal to that of the secondary toolbar at a fullscreen
progress of 1.0.  That way, all the constraints that need to be
animated are owned by the container and its subviews, so we can just
call |-layoutIfNeeded| on the container rather than the entire
browser view.


Bug: 880656
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: Ia0520d4cbfb55846efa16282e5aefae6e7f11212
Reviewed-on: https://chromium-review.googlesource.com/1208713
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590182}
parent 8322f15d
...@@ -712,6 +712,9 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -712,6 +712,9 @@ NSString* const kBrowserViewControllerSnackbarCategory =
// Secondary toolbar. // Secondary toolbar.
@property(nonatomic, strong) @property(nonatomic, strong)
AdaptiveToolbarCoordinator* secondaryToolbarCoordinator; AdaptiveToolbarCoordinator* secondaryToolbarCoordinator;
// The container view for the secondary toolbar.
// TODO(crbug.com/880656): Convert to a container coordinator.
@property(nonatomic, strong) UIView* secondaryToolbarContainerView;
// Interface object with the toolbars. // Interface object with the toolbars.
@property(nonatomic, strong) id<ToolbarCoordinating> toolbarInterface; @property(nonatomic, strong) id<ToolbarCoordinating> toolbarInterface;
...@@ -937,6 +940,7 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -937,6 +940,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
@synthesize bubblePresenter = _bubblePresenter; @synthesize bubblePresenter = _bubblePresenter;
@synthesize primaryToolbarCoordinator = _primaryToolbarCoordinator; @synthesize primaryToolbarCoordinator = _primaryToolbarCoordinator;
@synthesize secondaryToolbarCoordinator = _secondaryToolbarCoordinator; @synthesize secondaryToolbarCoordinator = _secondaryToolbarCoordinator;
@synthesize secondaryToolbarContainerView = _secondaryToolbarContainerView;
@synthesize primaryToolbarOffsetConstraint = _primaryToolbarOffsetConstraint; @synthesize primaryToolbarOffsetConstraint = _primaryToolbarOffsetConstraint;
@synthesize primaryToolbarHeightConstraint = _primaryToolbarHeightConstraint; @synthesize primaryToolbarHeightConstraint = _primaryToolbarHeightConstraint;
@synthesize secondaryToolbarHeightConstraint = @synthesize secondaryToolbarHeightConstraint =
...@@ -2367,26 +2371,30 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint { ...@@ -2367,26 +2371,30 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
if (self.secondaryToolbarCoordinator) { if (self.secondaryToolbarCoordinator) {
// Create a constraint for the height of the toolbar to include the unsafe // Create a constraint for the height of the toolbar to include the unsafe
// area height. // area height.
UIView* secondaryView = UIView* toolbarView = self.secondaryToolbarCoordinator.viewController.view;
self.secondaryToolbarCoordinator.viewController.view; self.secondaryToolbarHeightConstraint = [toolbarView.heightAnchor
self.secondaryToolbarHeightConstraint = [secondaryView.heightAnchor
constraintEqualToConstant:[self secondaryToolbarHeightWithInset]]; constraintEqualToConstant:[self secondaryToolbarHeightWithInset]];
self.secondaryToolbarHeightConstraint.active = YES; self.secondaryToolbarHeightConstraint.active = YES;
AddSameConstraintsToSides( AddSameConstraintsToSides(
self.view, secondaryView, self.secondaryToolbarContainerView, toolbarView,
LayoutSides::kBottom | LayoutSides::kLeading | LayoutSides::kTrailing); LayoutSides::kBottom | LayoutSides::kLeading | LayoutSides::kTrailing);
UILayoutGuide* guide = // Constrain the container view to the bottom of self.view, and add a
[[NamedGuide alloc] initWithName:kSecondaryToolbarNoFullscreenGuide]; // constant height constraint such that the container's frame is equal to
[self.view addLayoutGuide:guide]; // that of the secondary toolbar at a fullscreen progress of 1.0.
self.secondaryToolbarNoFullscreenHeightConstraint = [guide.heightAnchor UIView* containerView = self.secondaryToolbarContainerView;
constraintEqualToConstant:[self secondaryToolbarHeightWithInset]]; self.secondaryToolbarNoFullscreenHeightConstraint =
[containerView.heightAnchor
constraintEqualToConstant:[self secondaryToolbarHeightWithInset]];
self.secondaryToolbarNoFullscreenHeightConstraint.active = YES; self.secondaryToolbarNoFullscreenHeightConstraint.active = YES;
AddSameConstraintsToSides( AddSameConstraintsToSides(
self.view, guide, self.view, containerView,
LayoutSides::kBottom | LayoutSides::kLeading | LayoutSides::kTrailing); LayoutSides::kBottom | LayoutSides::kLeading | LayoutSides::kTrailing);
NamedGuide* guide =
[[NamedGuide alloc] initWithName:kSecondaryToolbarNoFullscreenGuide];
[self.view addLayoutGuide:guide];
guide.constrainedView = containerView;
} }
} }
...@@ -2538,9 +2546,16 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint { ...@@ -2538,9 +2546,16 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
insertSubview:self.primaryToolbarCoordinator.viewController.view insertSubview:self.primaryToolbarCoordinator.viewController.view
aboveSubview:bottomView]; aboveSubview:bottomView];
if (self.secondaryToolbarCoordinator) { if (self.secondaryToolbarCoordinator) {
[[self view] // Create the container view for the secondary toolbar and add it to the
insertSubview:self.secondaryToolbarCoordinator.viewController.view // hierarchy
UIView* container = [[UIView alloc] init];
container.translatesAutoresizingMaskIntoConstraints = NO;
[container
addSubview:self.secondaryToolbarCoordinator.viewController.view];
[self.view
insertSubview:container
aboveSubview:self.primaryToolbarCoordinator.viewController.view]; aboveSubview:self.primaryToolbarCoordinator.viewController.view];
self.secondaryToolbarContainerView = container;
} }
NSArray<GuideName*>* guideNames = @[ NSArray<GuideName*>* guideNames = @[
kContentAreaGuide, kContentAreaGuide,
...@@ -4150,10 +4165,12 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint { ...@@ -4150,10 +4165,12 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
self.footerFullscreenProgress = progress; self.footerFullscreenProgress = progress;
if (IsUIRefreshPhase1Enabled()) { if (IsUIRefreshPhase1Enabled()) {
// TODO(crbug.com/880656): Update implementation to make the bottom toolbar // Update the height constraint and force a layout on the container view so
// animatable. // that the update is animatable.
self.secondaryToolbarHeightConstraint.constant = self.secondaryToolbarHeightConstraint.constant =
[self secondaryToolbarHeightWithInset] * progress; [self secondaryToolbarHeightWithInset] * progress;
[self.secondaryToolbarContainerView setNeedsLayout];
[self.secondaryToolbarContainerView layoutIfNeeded];
// Resize the infobars to take into account the changes in the toolbar. // Resize the infobars to take into account the changes in the toolbar.
[self infoBarContainerStateDidChangeAnimated:NO]; [self infoBarContainerStateDidChangeAnimated:NO];
......
...@@ -121,6 +121,13 @@ const CGFloat kTabGridAnimationsTotalDuration = 0.5; ...@@ -121,6 +121,13 @@ const CGFloat kTabGridAnimationsTotalDuration = 0.5;
} }
} }
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
// TODO(crbug.com/882723): Remove this call once iPad trait collection
// override issue is fixed.
[self updateAllButtonsVisibility];
}
#pragma mark - Public #pragma mark - Public
- (ToolbarToolsMenuButton*)toolsMenuButton { - (ToolbarToolsMenuButton*)toolsMenuButton {
......
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