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 =
// Secondary toolbar.
@property(nonatomic, strong)
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.
@property(nonatomic, strong) id<ToolbarCoordinating> toolbarInterface;
......@@ -937,6 +940,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
@synthesize bubblePresenter = _bubblePresenter;
@synthesize primaryToolbarCoordinator = _primaryToolbarCoordinator;
@synthesize secondaryToolbarCoordinator = _secondaryToolbarCoordinator;
@synthesize secondaryToolbarContainerView = _secondaryToolbarContainerView;
@synthesize primaryToolbarOffsetConstraint = _primaryToolbarOffsetConstraint;
@synthesize primaryToolbarHeightConstraint = _primaryToolbarHeightConstraint;
@synthesize secondaryToolbarHeightConstraint =
......@@ -2367,26 +2371,30 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
if (self.secondaryToolbarCoordinator) {
// Create a constraint for the height of the toolbar to include the unsafe
// area height.
UIView* secondaryView =
self.secondaryToolbarCoordinator.viewController.view;
self.secondaryToolbarHeightConstraint = [secondaryView.heightAnchor
UIView* toolbarView = self.secondaryToolbarCoordinator.viewController.view;
self.secondaryToolbarHeightConstraint = [toolbarView.heightAnchor
constraintEqualToConstant:[self secondaryToolbarHeightWithInset]];
self.secondaryToolbarHeightConstraint.active = YES;
AddSameConstraintsToSides(
self.view, secondaryView,
self.secondaryToolbarContainerView, toolbarView,
LayoutSides::kBottom | LayoutSides::kLeading | LayoutSides::kTrailing);
UILayoutGuide* guide =
[[NamedGuide alloc] initWithName:kSecondaryToolbarNoFullscreenGuide];
[self.view addLayoutGuide:guide];
self.secondaryToolbarNoFullscreenHeightConstraint = [guide.heightAnchor
constraintEqualToConstant:[self secondaryToolbarHeightWithInset]];
// Constrain the container view to the bottom of self.view, and add a
// constant height constraint such that the container's frame is equal to
// that of the secondary toolbar at a fullscreen progress of 1.0.
UIView* containerView = self.secondaryToolbarContainerView;
self.secondaryToolbarNoFullscreenHeightConstraint =
[containerView.heightAnchor
constraintEqualToConstant:[self secondaryToolbarHeightWithInset]];
self.secondaryToolbarNoFullscreenHeightConstraint.active = YES;
AddSameConstraintsToSides(
self.view, guide,
self.view, containerView,
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 {
insertSubview:self.primaryToolbarCoordinator.viewController.view
aboveSubview:bottomView];
if (self.secondaryToolbarCoordinator) {
[[self view]
insertSubview:self.secondaryToolbarCoordinator.viewController.view
// Create the container view for the secondary toolbar and add it to the
// hierarchy
UIView* container = [[UIView alloc] init];
container.translatesAutoresizingMaskIntoConstraints = NO;
[container
addSubview:self.secondaryToolbarCoordinator.viewController.view];
[self.view
insertSubview:container
aboveSubview:self.primaryToolbarCoordinator.viewController.view];
self.secondaryToolbarContainerView = container;
}
NSArray<GuideName*>* guideNames = @[
kContentAreaGuide,
......@@ -4150,10 +4165,12 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
self.footerFullscreenProgress = progress;
if (IsUIRefreshPhase1Enabled()) {
// TODO(crbug.com/880656): Update implementation to make the bottom toolbar
// animatable.
// Update the height constraint and force a layout on the container view so
// that the update is animatable.
self.secondaryToolbarHeightConstraint.constant =
[self secondaryToolbarHeightWithInset] * progress;
[self.secondaryToolbarContainerView setNeedsLayout];
[self.secondaryToolbarContainerView layoutIfNeeded];
// Resize the infobars to take into account the changes in the toolbar.
[self infoBarContainerStateDidChangeAnimated:NO];
......
......@@ -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
- (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