Commit ae91b77f authored by sczs's avatar sczs Committed by Commit Bot

[ios] Adds expandOmniboxAnimation for clean toolbar.

Toolbar Coordinator creates a property animator animation for expanding the location bar.
ToolbarViewController expands the locationBarContainerView by changing its constraints.

Bug: 784592
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I36414e22a887cd0752cbece06058bf1d67eaec18
Reviewed-on: https://chromium-review.googlesource.com/798752
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520812}
parent 21b079d1
...@@ -43,6 +43,7 @@ source_set("toolbar") { ...@@ -43,6 +43,7 @@ source_set("toolbar") {
"//ios/chrome/browser/ui/tools_menu/public", "//ios/chrome/browser/ui/tools_menu/public",
"//ios/chrome/browser/ui/voice", "//ios/chrome/browser/ui/voice",
"//ios/chrome/browser/web_state_list", "//ios/chrome/browser/web_state_list",
"//ios/chrome/common",
"//ios/public/provider/chrome/browser", "//ios/public/provider/chrome/browser",
"//ios/public/provider/chrome/browser/voice", "//ios/public/provider/chrome/browser/voice",
"//ios/third_party/material_components_ios", "//ios/third_party/material_components_ios",
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#import "ios/chrome/browser/ui/voice/text_to_speech_player.h" #import "ios/chrome/browser/ui/voice/text_to_speech_player.h"
#import "ios/chrome/browser/ui/voice/voice_search_notification_names.h" #import "ios/chrome/browser/ui/voice/voice_search_notification_names.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h" #import "ios/chrome/browser/web_state_list/web_state_list.h"
#import "ios/chrome/common/material_timing.h"
#import "ios/public/provider/chrome/browser/chrome_browser_provider.h" #import "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h" #import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h"
#import "ios/web/public/navigation_item.h" #import "ios/web/public/navigation_item.h"
...@@ -330,16 +331,12 @@ ...@@ -330,16 +331,12 @@
- (void)locationBarHasBecomeFirstResponder { - (void)locationBarHasBecomeFirstResponder {
[self.delegate locationBarDidBecomeFirstResponder]; [self.delegate locationBarDidBecomeFirstResponder];
if (@available(iOS 10, *)) { [self expandOmniboxAnimated:YES];
[self.toolbarViewController expandOmniboxAnimated:YES];
}
} }
- (void)locationBarHasResignedFirstResponder { - (void)locationBarHasResignedFirstResponder {
[self.delegate locationBarDidResignFirstResponder]; [self.delegate locationBarDidResignFirstResponder];
if (@available(iOS 10, *)) { [self contractOmnibox];
[self.toolbarViewController contractOmnibox];
}
} }
- (void)locationBarBeganEdit { - (void)locationBarBeganEdit {
...@@ -379,7 +376,7 @@ ...@@ -379,7 +376,7 @@
model->OnSetFocus(false); model->OnSetFocus(false);
model->SetCaretVisibility(false); model->SetCaretVisibility(false);
} else { } else {
[self.toolbarViewController expandOmniboxAnimated:NO]; [self expandOmniboxAnimated:NO];
} }
[self focusOmnibox]; [self focusOmnibox];
...@@ -521,4 +518,37 @@ ...@@ -521,4 +518,37 @@
} }
} }
// Animates |_toolbar| and |_locationBarView| for omnibox expansion. If
// |animated| is NO the animation will happen instantly.
- (void)expandOmniboxAnimated:(BOOL)animated {
// There's no Toolbar expanding on iPad.
if (IsIPadIdiom())
return;
NSTimeInterval duration = animated ? ios::material::kDuration1 : 0;
UIViewPropertyAnimator* animator = [[UIViewPropertyAnimator alloc]
initWithDuration:duration
curve:UIViewAnimationCurveEaseInOut
animations:^{
}];
[self.locationBarView addExpandOmniboxAnimations:animator];
[self.toolbarViewController addToolbarExpansionAnimations:animator];
[animator startAnimation];
}
// Animates |_toolbar| and |_locationBarView| for omnibox contraction.
- (void)contractOmnibox {
// There's no Toolbar expanding on iPad, thus no need to contract.
if (IsIPadIdiom())
return;
UIViewPropertyAnimator* animator = [[UIViewPropertyAnimator alloc]
initWithDuration:ios::material::kDuration1
curve:UIViewAnimationCurveEaseInOut
animations:^{
}];
[self.locationBarView addContractOmniboxAnimations:animator];
[self.toolbarViewController addToolbarContractionAnimations:animator];
[animator startAnimation];
}
@end @end
...@@ -42,10 +42,12 @@ ...@@ -42,10 +42,12 @@
// The ToolsMenu button. // The ToolsMenu button.
@property(nonatomic, strong, readonly) ToolbarToolsMenuButton* toolsMenuButton; @property(nonatomic, strong, readonly) ToolbarToolsMenuButton* toolsMenuButton;
// Animates the toolbar so the omnibox is shrinking to its standard state. // Adds the toolbar expanded state animations to |animator|, and changes the
- (void)contractOmnibox; // toolbar constraints in preparation for the animation.
// Expands the omnibox to its expanded state, |animated| or not. - (void)addToolbarExpansionAnimations:(UIViewPropertyAnimator*)animator;
- (void)expandOmniboxAnimated:(BOOL)animated; // Adds the toolbar contracted state animations to |animator|, and changes the
// toolbar constraints in preparation for the animation.
- (void)addToolbarContractionAnimations:(UIViewPropertyAnimator*)animator;
// Updates the view so a snapshot can be taken. It needs to be adapted, // Updates the view so a snapshot can be taken. It needs to be adapted,
// depending on if it is a snapshot displayed |onNTP| or not. // depending on if it is a snapshot displayed |onNTP| or not.
- (void)updateForSideSwipeSnapshotOnNTP:(BOOL)onNTP; - (void)updateForSideSwipeSnapshotOnNTP:(BOOL)onNTP;
......
...@@ -49,6 +49,15 @@ ...@@ -49,6 +49,15 @@
@property(nonatomic, strong) UIView* backgroundView; @property(nonatomic, strong) UIView* backgroundView;
// Whether a page is loading. // Whether a page is loading.
@property(nonatomic, assign, getter=isLoading) BOOL loading; @property(nonatomic, assign, getter=isLoading) BOOL loading;
// Constraints used for the regular/contracted Toolbar state.
@property(nonatomic, strong) NSMutableArray* regularToolbarConstraints;
// Constraints used to layout the Toolbar to its expanded state. If these are
// active the locationBarContainer will expand to the size of this VC's view.
// The locationBarView will only expand up to the VC's view safeAreaLayoutGuide.
@property(nonatomic, strong) NSArray* expandedToolbarConstraints;
// Top anchor at the bottom of the safeAreaLayoutGuide. Used so views don't
// overlap with the Status Bar.
@property(nonatomic, strong) NSLayoutYAxisAnchor* topSafeAnchor;
@end @end
@implementation ToolbarViewController @implementation ToolbarViewController
...@@ -71,6 +80,9 @@ ...@@ -71,6 +80,9 @@
@synthesize bookmarkButton = _bookmarkButton; @synthesize bookmarkButton = _bookmarkButton;
@synthesize voiceSearchEnabled = _voiceSearchEnabled; @synthesize voiceSearchEnabled = _voiceSearchEnabled;
@synthesize progressBar = _progressBar; @synthesize progressBar = _progressBar;
@synthesize expandedToolbarConstraints = _expandedToolbarConstraints;
@synthesize topSafeAnchor = _topSafeAnchor;
@synthesize regularToolbarConstraints = _regularToolbarConstraints;
#pragma mark - Properties accessor #pragma mark - Properties accessor
...@@ -105,12 +117,20 @@ ...@@ -105,12 +117,20 @@
return self; return self;
} }
- (void)contractOmnibox { - (void)addToolbarExpansionAnimations:(UIViewPropertyAnimator*)animator {
// TODO(crbug.com/785210): Implement this. [NSLayoutConstraint deactivateConstraints:self.regularToolbarConstraints];
[NSLayoutConstraint activateConstraints:self.expandedToolbarConstraints];
[animator addAnimations:^{
[self.view layoutIfNeeded];
}];
} }
- (void)expandOmniboxAnimated:(BOOL)animated { - (void)addToolbarContractionAnimations:(UIViewPropertyAnimator*)animator {
// TODO(crbug.com/785210): Implement this. [NSLayoutConstraint deactivateConstraints:self.expandedToolbarConstraints];
[NSLayoutConstraint activateConstraints:self.regularToolbarConstraints];
[animator addAnimations:^{
[self.view layoutIfNeeded];
}];
} }
- (void)updateForSideSwipeSnapshotOnNTP:(BOOL)onNTP { - (void)updateForSideSwipeSnapshotOnNTP:(BOOL)onNTP {
...@@ -153,8 +173,22 @@ ...@@ -153,8 +173,22 @@
[self setUpToolbarStackView]; [self setUpToolbarStackView];
if (self.locationBarView) { if (self.locationBarView) {
NSLayoutConstraint* locationBarTopAnchorConstraint =
[self.locationBarView.topAnchor
constraintEqualToAnchor:self.locationBarContainer.topAnchor];
[self.locationBarContainer addSubview:self.locationBarView]; [self.locationBarContainer addSubview:self.locationBarView];
AddSameConstraints(self.locationBarContainer, self.locationBarView); NSArray* locationBarViewConstraints = @[
[self.locationBarView.leadingAnchor
constraintEqualToAnchor:self.locationBarContainer.leadingAnchor],
[self.locationBarView.trailingAnchor
constraintEqualToAnchor:self.locationBarContainer.trailingAnchor],
[self.locationBarView.bottomAnchor
constraintEqualToAnchor:self.locationBarContainer.bottomAnchor],
locationBarTopAnchorConstraint,
];
// Adds
[self.regularToolbarConstraints addObject:locationBarTopAnchorConstraint];
[NSLayoutConstraint activateConstraints:locationBarViewConstraints];
} }
[self.locationBarContainer addSubview:self.bookmarkButton]; [self.locationBarContainer addSubview:self.bookmarkButton];
[self.locationBarContainer addSubview:self.voiceSearchButton]; [self.locationBarContainer addSubview:self.voiceSearchButton];
...@@ -183,15 +217,23 @@ ...@@ -183,15 +217,23 @@
} }
- (void)setConstraints { - (void)setConstraints {
// Top anchor so Toolbar content never overlaps with the Status Bar.
NSLayoutYAxisAnchor* topAnchor;
if (@available(iOS 11, *)) {
topAnchor = self.view.safeAreaLayoutGuide.topAnchor;
} else {
topAnchor = self.topLayoutGuide.bottomAnchor;
}
self.view.translatesAutoresizingMaskIntoConstraints = NO; self.view.translatesAutoresizingMaskIntoConstraints = NO;
[self.view.bottomAnchor constraintEqualToAnchor:self.topSafeAnchor
constant:kToolbarHeight]
.active = YES;
NSArray* progressBarConstraints = @[
[self.progressBar.leadingAnchor
constraintEqualToAnchor:self.view.leadingAnchor],
[self.progressBar.trailingAnchor
constraintEqualToAnchor:self.view.trailingAnchor],
[self.progressBar.bottomAnchor
constraintEqualToAnchor:self.view.bottomAnchor],
[self.progressBar.heightAnchor
constraintEqualToConstant:kProgressBarHeight],
];
[NSLayoutConstraint activateConstraints:progressBarConstraints];
NSArray* constraints = @[ NSArray* constraints = @[
[self.stackView.heightAnchor [self.stackView.heightAnchor
constraintEqualToConstant:kToolbarHeight - 2 * kVerticalMargin], constraintEqualToConstant:kToolbarHeight - 2 * kVerticalMargin],
...@@ -203,14 +245,6 @@ ...@@ -203,14 +245,6 @@
[self.stackView.trailingAnchor [self.stackView.trailingAnchor
constraintEqualToAnchor:self.view.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor
constant:-kHorizontalMargin], constant:-kHorizontalMargin],
[self.progressBar.leadingAnchor
constraintEqualToAnchor:self.view.leadingAnchor],
[self.progressBar.trailingAnchor
constraintEqualToAnchor:self.view.trailingAnchor],
[self.progressBar.bottomAnchor
constraintEqualToAnchor:self.view.bottomAnchor],
[self.progressBar.heightAnchor
constraintEqualToConstant:kProgressBarHeight],
[self.bookmarkButton.centerYAnchor [self.bookmarkButton.centerYAnchor
constraintEqualToAnchor:self.locationBarContainer.centerYAnchor], constraintEqualToAnchor:self.locationBarContainer.centerYAnchor],
[self.voiceSearchButton.centerYAnchor [self.voiceSearchButton.centerYAnchor
...@@ -219,10 +253,8 @@ ...@@ -219,10 +253,8 @@
constraintEqualToAnchor:self.locationBarContainer.trailingAnchor], constraintEqualToAnchor:self.locationBarContainer.trailingAnchor],
[self.bookmarkButton.trailingAnchor [self.bookmarkButton.trailingAnchor
constraintEqualToAnchor:self.voiceSearchButton.leadingAnchor], constraintEqualToAnchor:self.voiceSearchButton.leadingAnchor],
[self.view.bottomAnchor constraintEqualToAnchor:topAnchor
constant:kToolbarHeight],
]; ];
[self.regularToolbarConstraints addObjectsFromArray:constraints];
[NSLayoutConstraint activateConstraints:constraints]; [NSLayoutConstraint activateConstraints:constraints];
} }
...@@ -343,6 +375,7 @@ ...@@ -343,6 +375,7 @@
self.buttonUpdater.forwardButton = self.forwardButton; self.buttonUpdater.forwardButton = self.forwardButton;
self.buttonUpdater.voiceSearchButton = self.voiceSearchButton; self.buttonUpdater.voiceSearchButton = self.voiceSearchButton;
[self.regularToolbarConstraints addObjectsFromArray:buttonConstraints];
[NSLayoutConstraint activateConstraints:buttonConstraints]; [NSLayoutConstraint activateConstraints:buttonConstraints];
} }
...@@ -546,6 +579,44 @@ ...@@ -546,6 +579,44 @@
[self.voiceSearchButton updateHiddenInCurrentSizeClass]; [self.voiceSearchButton updateHiddenInCurrentSizeClass];
} }
#pragma mark - Setters & Getters.
- (NSLayoutYAxisAnchor*)topSafeAnchor {
if (!_topSafeAnchor) {
if (@available(iOS 11, *)) {
_topSafeAnchor = self.view.safeAreaLayoutGuide.topAnchor;
} else {
_topSafeAnchor = self.topLayoutGuide.bottomAnchor;
}
}
return _topSafeAnchor;
}
- (NSMutableArray*)regularToolbarConstraints {
if (!_regularToolbarConstraints) {
_regularToolbarConstraints = [[NSMutableArray alloc] init];
}
return _regularToolbarConstraints;
}
- (NSArray*)expandedToolbarConstraints {
if (!_expandedToolbarConstraints) {
_expandedToolbarConstraints = @[
[self.locationBarContainer.topAnchor
constraintEqualToAnchor:self.view.topAnchor],
[self.locationBarContainer.bottomAnchor
constraintEqualToAnchor:self.view.bottomAnchor],
[self.locationBarContainer.leadingAnchor
constraintEqualToAnchor:self.view.leadingAnchor],
[self.locationBarContainer.trailingAnchor
constraintEqualToAnchor:self.view.trailingAnchor],
[self.locationBarView.topAnchor constraintEqualToAnchor:self.topSafeAnchor
constant:kVerticalMargin],
];
}
return _expandedToolbarConstraints;
}
#pragma mark - Private #pragma mark - Private
// Sets the progress of the progressBar to 1 then hides it. // Sets the progress of the progressBar to 1 then hides it.
......
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