Commit 9a142dc4 authored by sczs's avatar sczs Committed by Commit Bot

[ios] Creates UIViewPropertyAnimator for location bar expansion.

Creates animations for expanding and contracting the location bar/omnibox
using entirely UIViewPropertyAnimators.

The feature is behind a new flag that is disabled by default.

Real time video:
https://drive.google.com/open?id=0Byo6-Nuda2jgVE1yTjBPRU9ybjg

Slow Animations video:
https://drive.google.com/open?id=0Byo6-Nuda2jgR21YM3k0amEwUEE

Bug: 
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Ib3a4f8f7aac9e72b674b881af2f463fabf76393a
Reviewed-on: https://chromium-review.googlesource.com/729839
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#512999}
parent b8c74bd5
...@@ -197,7 +197,10 @@ const flags_ui::FeatureEntry kFeatureEntries[] = { ...@@ -197,7 +197,10 @@ const flags_ui::FeatureEntry kFeatureEntries[] = {
{"ios-share-canonical-url", flag_descriptions::kShareCanonicalURLName, {"ios-share-canonical-url", flag_descriptions::kShareCanonicalURLName,
flag_descriptions::kShareCanonicalURLDescription, flags_ui::kOsIos, flag_descriptions::kShareCanonicalURLDescription, flags_ui::kOsIos,
FEATURE_VALUE_TYPE(activity_services::kShareCanonicalURL)}, FEATURE_VALUE_TYPE(activity_services::kShareCanonicalURL)},
}; {"property-animations-toolbar",
flag_descriptions::kPropertyAnimationsToolbarName,
flag_descriptions::kPropertyAnimationsToolbarDescription, flags_ui::kOsIos,
FEATURE_VALUE_TYPE(kPropertyAnimationsToolbar)}};
// Add all switches from experimental flags to |command_line|. // Add all switches from experimental flags to |command_line|.
void AppendSwitchesFromExperimentalSettings(base::CommandLine* command_line) { void AppendSwitchesFromExperimentalSettings(base::CommandLine* command_line) {
......
...@@ -73,6 +73,12 @@ const char kPhysicalWebDescription[] = ...@@ -73,6 +73,12 @@ const char kPhysicalWebDescription[] =
"When enabled, the omnibox will include suggestions for web pages " "When enabled, the omnibox will include suggestions for web pages "
"broadcast by devices near you."; "broadcast by devices near you.";
const char kPropertyAnimationsToolbarName[] =
"UIViewPropertyAnimator Animated Toolbar";
const char kPropertyAnimationsToolbarDescription[] =
"When enabled, Toolbar animations will be done using "
"UIViewPropertyAnimator";
extern const char kSafeAreaCompatibleToolbarName[] = extern const char kSafeAreaCompatibleToolbarName[] =
"Safe Area Compatible Toolbar"; "Safe Area Compatible Toolbar";
extern const char kSafeAreaCompatibleToolbarDescription[] = extern const char kSafeAreaCompatibleToolbarDescription[] =
......
...@@ -66,6 +66,11 @@ extern const char kOmniboxUIHideSuggestionUrlTrivialSubdomainsDescription[]; ...@@ -66,6 +66,11 @@ extern const char kOmniboxUIHideSuggestionUrlTrivialSubdomainsDescription[];
extern const char kPhysicalWeb[]; extern const char kPhysicalWeb[];
extern const char kPhysicalWebDescription[]; extern const char kPhysicalWebDescription[];
// Title and description for the flag to have the toolbar use
// UIViewPropertyAnimators.
extern const char kPropertyAnimationsToolbarName[];
extern const char kPropertyAnimationsToolbarDescription[];
// Title and description for the flag to have the toolbar respect the safe area. // Title and description for the flag to have the toolbar respect the safe area.
extern const char kSafeAreaCompatibleToolbarName[]; extern const char kSafeAreaCompatibleToolbarName[];
extern const char kSafeAreaCompatibleToolbarDescription[]; extern const char kSafeAreaCompatibleToolbarDescription[];
......
...@@ -92,6 +92,7 @@ source_set("omnibox_internal") { ...@@ -92,6 +92,7 @@ source_set("omnibox_internal") {
"//ios/chrome/browser/sessions", "//ios/chrome/browser/sessions",
"//ios/chrome/browser/ui", "//ios/chrome/browser/ui",
"//ios/chrome/browser/ui/commands", "//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/toolbar/public",
"//ios/chrome/common", "//ios/chrome/common",
"//ios/public/provider/chrome/browser", "//ios/public/provider/chrome/browser",
"//ios/third_party/material_components_ios", "//ios/third_party/material_components_ios",
......
...@@ -121,6 +121,12 @@ typedef enum { ...@@ -121,6 +121,12 @@ typedef enum {
@property(nonatomic, strong) UIColor* selectedTextBackgroundColor; @property(nonatomic, strong) UIColor* selectedTextBackgroundColor;
@property(nonatomic, strong) UIColor* placeholderTextColor; @property(nonatomic, strong) UIColor* placeholderTextColor;
@property(nonatomic, assign) BOOL incognito; @property(nonatomic, assign) BOOL incognito;
// UIViewPropertyAnimator for expanding the location bar.
@property(nonatomic, strong)
UIViewPropertyAnimator* omniboxExpanderAnimator API_AVAILABLE(ios(10.0));
// UIViewPropertyAnimator for contracting the location bar.
@property(nonatomic, strong)
UIViewPropertyAnimator* omniboxContractorAnimator API_AVAILABLE(ios(10.0));
@end @end
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "ios/chrome/browser/ui/omnibox/omnibox_util.h" #include "ios/chrome/browser/ui/omnibox/omnibox_util.h"
#import "ios/chrome/browser/ui/reversed_animation.h" #import "ios/chrome/browser/ui/reversed_animation.h"
#include "ios/chrome/browser/ui/rtl_geometry.h" #include "ios/chrome/browser/ui/rtl_geometry.h"
#import "ios/chrome/browser/ui/toolbar/public/web_toolbar_controller_constants.h"
#include "ios/chrome/browser/ui/ui_util.h" #include "ios/chrome/browser/ui/ui_util.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h" #import "ios/chrome/browser/ui/uikit_ui_util.h"
#import "ios/chrome/common/material_timing.h" #import "ios/chrome/common/material_timing.h"
...@@ -109,6 +110,8 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation"; ...@@ -109,6 +110,8 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation";
@synthesize selectedTextBackgroundColor = _selectedTextBackgroundColor; @synthesize selectedTextBackgroundColor = _selectedTextBackgroundColor;
@synthesize placeholderTextColor = _placeholderTextColor; @synthesize placeholderTextColor = _placeholderTextColor;
@synthesize incognito = _incognito; @synthesize incognito = _incognito;
@synthesize omniboxExpanderAnimator = _omniboxExpanderAnimator;
@synthesize omniboxContractorAnimator = _omniboxContractorAnimator;
// Overload to allow for code-based initialization. // Overload to allow for code-based initialization.
- (instancetype)initWithFrame:(CGRect)frame { - (instancetype)initWithFrame:(CGRect)frame {
...@@ -165,6 +168,69 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation"; ...@@ -165,6 +168,69 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation";
return nil; return nil;
} }
- (void)setOmniboxExpanderAnimator:(UIViewPropertyAnimator*)animator
API_AVAILABLE(ios(10.0)) {
_omniboxExpanderAnimator = animator;
[self addExpandOmniboxAnimations];
}
- (void)setOmniboxContractorAnimator:(UIViewPropertyAnimator*)animator
API_AVAILABLE(ios(10.0)) {
_omniboxContractorAnimator = animator;
[self addContractOmniboxAnimations];
}
- (void)addExpandOmniboxAnimations API_AVAILABLE(ios(10.0)) {
UIView* leadingView = [self leftView];
[_omniboxExpanderAnimator addAnimations:^{
leadingView.alpha = 0;
leadingView.frame =
CGRectMake(leadingView.frame.origin.x - kPositionAnimationLeadingOffset,
leadingView.frame.origin.y, leadingView.frame.size.width,
leadingView.frame.size.height);
}];
__weak OmniboxTextFieldIOS* weakSelf = self;
[self rightView].alpha = 0;
[_omniboxExpanderAnimator addCompletion:^(
UIViewAnimatingPosition finalPosition) {
UIView* trailingView = [weakSelf rightView];
CGRect finalTrailingViewFrame = trailingView.frame;
trailingView.frame =
CGRectLayoutOffset(trailingView.frame, kPositionAnimationLeadingOffset);
[UIViewPropertyAnimator
runningPropertyAnimatorWithDuration:0.2
delay:0.1
options:UIViewAnimationOptionCurveEaseOut
animations:^{
trailingView.alpha = 1.0;
trailingView.frame = finalTrailingViewFrame;
}
completion:nil];
}];
}
- (void)addContractOmniboxAnimations API_AVAILABLE(ios(10.0)) {
UIView* leadingView = [self leftView];
leadingView.alpha = 0;
CGRect finalLeadingViewFrame = leadingView.frame;
leadingView.frame =
CGRectLayoutOffset(leadingView.frame, kPositionAnimationLeadingOffset);
[_omniboxContractorAnimator addAnimations:^{
leadingView.alpha = 1.0;
leadingView.frame = finalLeadingViewFrame;
}
delayFactor:ios::material::kDuration2];
UIView* trailingView = [self rightView];
[_omniboxContractorAnimator addAnimations:^{
trailingView.alpha = 0;
trailingView.frame.origin = CGPointMake(
trailingView.frame.origin.x + kPositionAnimationLeadingOffset,
trailingView.frame.origin.y);
}];
}
// Enforces that the delegate is an OmniboxTextFieldDelegate. // Enforces that the delegate is an OmniboxTextFieldDelegate.
- (id<OmniboxTextFieldDelegate>)delegate { - (id<OmniboxTextFieldDelegate>)delegate {
id delegate = [super delegate]; id delegate = [super delegate];
......
...@@ -10,4 +10,7 @@ ...@@ -10,4 +10,7 @@
// Feature to choose whether the toolbar respects the safe area. // Feature to choose whether the toolbar respects the safe area.
extern const base::Feature kSafeAreaCompatibleToolbar; extern const base::Feature kSafeAreaCompatibleToolbar;
// Feature to choose whether the toolbar uses UIViewPropertyAnimators.
extern const base::Feature kPropertyAnimationsToolbar;
#endif // IOS_CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_CONTROLLER_BASE_FEATURE_H_ #endif // IOS_CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_CONTROLLER_BASE_FEATURE_H_
...@@ -6,3 +6,6 @@ ...@@ -6,3 +6,6 @@
const base::Feature kSafeAreaCompatibleToolbar{ const base::Feature kSafeAreaCompatibleToolbar{
"SafeAreaCompatibleToolbar", base::FEATURE_DISABLED_BY_DEFAULT}; "SafeAreaCompatibleToolbar", base::FEATURE_DISABLED_BY_DEFAULT};
extern const base::Feature kPropertyAnimationsToolbar{
"PropertyAnimationsToolbar", base::FEATURE_DISABLED_BY_DEFAULT};
...@@ -17,6 +17,14 @@ extern NSString* const kToolbarTransitionAnimationKey; ...@@ -17,6 +17,14 @@ extern NSString* const kToolbarTransitionAnimationKey;
// kToolbarTransitionAnimationKey. // kToolbarTransitionAnimationKey.
@property(nonatomic, readonly) NSMutableArray* transitionLayers; @property(nonatomic, readonly) NSMutableArray* transitionLayers;
// UIViewPropertyAnimator for expanding the location bar.
@property(nonatomic, strong)
UIViewPropertyAnimator* omniboxExpanderAnimator API_AVAILABLE(ios(10.0));
// UIViewPropertyAnimator for contracting the location bar.
@property(nonatomic, strong)
UIViewPropertyAnimator* omniboxContractorAnimator API_AVAILABLE(ios(10.0));
// Update share button visibility and |standardButtons_| array. // Update share button visibility and |standardButtons_| array.
- (void)updateStandardButtons; - (void)updateStandardButtons;
...@@ -87,6 +95,13 @@ extern NSString* const kToolbarTransitionAnimationKey; ...@@ -87,6 +95,13 @@ extern NSString* const kToolbarTransitionAnimationKey;
// animation used for Material. // animation used for Material.
- (void)animateStandardControlsForOmniboxExpansion:(BOOL)growOmnibox; - (void)animateStandardControlsForOmniboxExpansion:(BOOL)growOmnibox;
// Animates in the standard Toolbar buttons when the Location bar is
// contracting.
- (void)configureFadeInAnimation API_AVAILABLE(ios(10.0));
// Animates out the standard Toolbar buttons when the Location bar is expanding.
- (void)configureFadeOutAnimation API_AVAILABLE(ios(10.0));
@end @end
#endif // IOS_CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_CONTROLLER_PROTECTED_H_ #endif // IOS_CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_CONTROLLER_PROTECTED_H_
...@@ -85,6 +85,12 @@ using ios::material::TimingFunction; ...@@ -85,6 +85,12 @@ using ios::material::TimingFunction;
// The following is nil if not visible. // The following is nil if not visible.
ToolsPopupController* toolsPopupController_; ToolsPopupController* toolsPopupController_;
// Backing object for |self.omniboxExpanderAnimator|.
API_AVAILABLE(ios(10.0)) UIViewPropertyAnimator* _omniboxExpanderAnimator;
// Backing object for |self.omniboxContractorAnimator|.
API_AVAILABLE(ios(10.0)) UIViewPropertyAnimator* _omniboxContractorAnimator;
} }
// Returns the background image that should be used for |style|. // Returns the background image that should be used for |style|.
...@@ -733,6 +739,24 @@ using ios::material::TimingFunction; ...@@ -733,6 +739,24 @@ using ios::material::TimingFunction;
[self fadeInStandardControls]; [self fadeInStandardControls];
} }
- (UIViewPropertyAnimator*)omniboxExpanderAnimator {
return _omniboxExpanderAnimator;
}
- (void)setOmniboxExpanderAnimator:
(UIViewPropertyAnimator*)omniboxExpanderAnimator {
_omniboxExpanderAnimator = omniboxExpanderAnimator;
}
- (UIViewPropertyAnimator*)omniboxContractorAnimator {
return _omniboxContractorAnimator;
}
- (void)setOmniboxContractorAnimator:
(UIViewPropertyAnimator*)omniboxContractorAnimator {
_omniboxContractorAnimator = omniboxContractorAnimator;
}
#pragma mark - Private Methods #pragma mark - Private Methods
#pragma mark Animations #pragma mark Animations
- (void)fadeOutStandardControls { - (void)fadeOutStandardControls {
...@@ -784,6 +808,34 @@ using ios::material::TimingFunction; ...@@ -784,6 +808,34 @@ using ios::material::TimingFunction;
}]; }];
} }
- (void)configureFadeOutAnimation API_AVAILABLE(ios(10.0)) {
__weak NSArray* weakStandardButtons = standardButtons_;
__weak UIView* weakShadowView = shadowView_;
__weak UIView* weakFullBleedShadowView = fullBleedShadowView_;
[self.omniboxExpanderAnimator addAnimations:^{
// Animate the opacity of the buttons to 0 and 10 pixels in the
// leading-to-trailing direction.
for (UIButton* button in weakStandardButtons) {
if (![button isHidden])
button.alpha = 0;
button.frame = CGRectOffset(button.frame, kButtonFadeOutXOffset, 0);
}
// Fade to the full bleed shadow.
weakShadowView.alpha = 0;
weakFullBleedShadowView.alpha = 1;
}];
// After the animation is done and the buttons are hidden, move the buttons
// back to the position they originally were.
[self.omniboxExpanderAnimator
addCompletion:^(UIViewAnimatingPosition finalPosition) {
for (UIButton* button in weakStandardButtons) {
button.frame = CGRectOffset(button.frame, -kButtonFadeOutXOffset, 0);
}
}];
}
- (void)fadeInStandardControls { - (void)fadeInStandardControls {
for (UIButton* button in standardButtons_) { for (UIButton* button in standardButtons_) {
[self fadeInView:button [self fadeInView:button
...@@ -800,6 +852,22 @@ using ios::material::TimingFunction; ...@@ -800,6 +852,22 @@ using ios::material::TimingFunction;
}]; }];
} }
- (void)configureFadeInAnimation API_AVAILABLE(ios(10.0)) {
// First shift the Buttons by |kButtonFadeOutXOffset| so then the
// PropertyAnimator can move them in into their final position.
for (UIButton* button in standardButtons_) {
button.alpha = 0;
button.frame = CGRectOffset(button.frame, kButtonFadeOutXOffset, 0);
}
__weak NSArray* weakStandardButtons = standardButtons_;
[self.omniboxContractorAnimator addAnimations:^{
for (UIButton* button in weakStandardButtons) {
button.alpha = 1.0;
button.frame = CGRectOffset(button.frame, -kButtonFadeOutXOffset, 0);
}
}];
}
- (CAAnimation*)transitionAnimationForButton:(UIButton*)button - (CAAnimation*)transitionAnimationForButton:(UIButton*)button
containerBeginBounds:(CGRect)containerBeginBounds containerBeginBounds:(CGRect)containerBeginBounds
containerEndBounds:(CGRect)containerEndBounds containerEndBounds:(CGRect)containerEndBounds
......
...@@ -1078,7 +1078,15 @@ using ios::material::TimingFunction; ...@@ -1078,7 +1078,15 @@ using ios::material::TimingFunction;
- (void)locationBarHasBecomeFirstResponder { - (void)locationBarHasBecomeFirstResponder {
[self.delegate locationBarDidBecomeFirstResponder:self]; [self.delegate locationBarDidBecomeFirstResponder:self];
if (@available(iOS 10, *)) {
if (base::FeatureList::IsEnabled(kPropertyAnimationsToolbar)) {
[self expandOmnibox];
} else {
[self animateMaterialOmnibox];
}
} else {
[self animateMaterialOmnibox]; [self animateMaterialOmnibox];
}
// Record the appropriate user action for focusing the omnibox. // Record the appropriate user action for focusing the omnibox.
web::WebState* webState = [self.delegate currentWebState]; web::WebState* webState = [self.delegate currentWebState];
...@@ -1101,7 +1109,15 @@ using ios::material::TimingFunction; ...@@ -1101,7 +1109,15 @@ using ios::material::TimingFunction;
- (void)locationBarHasResignedFirstResponder { - (void)locationBarHasResignedFirstResponder {
[self.delegate locationBarDidResignFirstResponder:self]; [self.delegate locationBarDidResignFirstResponder:self];
if (@available(iOS 10, *)) {
if (base::FeatureList::IsEnabled(kPropertyAnimationsToolbar)) {
[self contractOmnibox];
} else {
[self animateMaterialOmnibox]; [self animateMaterialOmnibox];
}
} else {
[self animateMaterialOmnibox];
}
} }
- (void)locationBarBeganEdit { - (void)locationBarBeganEdit {
...@@ -1761,6 +1777,183 @@ using ios::material::TimingFunction; ...@@ -1761,6 +1777,183 @@ using ios::material::TimingFunction;
#pragma mark Omnibox Animation. #pragma mark Omnibox Animation.
- (void)expandOmnibox API_AVAILABLE(ios(10.0)) {
if (IsIPadIdiom())
return [self layoutOmnibox];
// Return if PropertyAnimator is already running.
if (self.omniboxExpanderAnimator.isRunning)
return;
CGRect newOmniboxFrame = [self newOmniboxFrame];
// Determine the starting and ending bounds and position for |_omniBox|.
// Increasing the height of _omniBox results in the text inside it jumping
// vertically during the animation, so the height change will not be animated.
LayoutRect toLayout =
LayoutRectForRectInBoundingRect(newOmniboxFrame, [_webToolbar bounds]);
CGRect omniboxRect = LayoutRectGetRect(kOmniboxFrame[IPHONE_IDIOM]);
toLayout.size = CGSizeMake([_webToolbar bounds].size.width -
self.cancelButton.frame.size.width -
kCancelButtonLeadingMargin,
omniboxRect.size.height);
toLayout.position.leading = 0;
if (_incognito) {
// Adjust the width and leading of the omnibox to account for the
// incognito icon.
// TODO(crbug.com/525943): Refactor so this value isn't calculated here, and
// instead is calculated in -newOmniboxFrame?
// (include in (crbug/525943) refactor).
LayoutRect incognitioIconLayout = LayoutRectForRectInBoundingRect(
[_incognitoIcon frame], [_webToolbar frame]);
CGFloat trailingEdge = LayoutRectGetTrailingEdge(incognitioIconLayout);
toLayout.size.width -= trailingEdge;
toLayout.position.leading = trailingEdge;
}
CGRect toBounds = LayoutRectGetBoundsRect(toLayout);
// Grow the background to cover the whole toolbar.
CGRect backgroundToBounds = [_clippingView bounds];
// Increase the bounds of the background so that the border extends past the
// toolbar and is clipped.
backgroundToBounds = CGRectInset(backgroundToBounds, -2, -2);
if (_incognito)
_incognitoIcon.frame = CGRectMake(
_incognitoIcon.frame.origin.x + kPositionAnimationLeadingOffset,
_incognitoIcon.frame.origin.y, _incognitoIcon.frame.size.width,
_incognitoIcon.frame.size.height);
// Create animator and add animations.
self.omniboxExpanderAnimator = [[UIViewPropertyAnimator alloc]
initWithDuration:ios::material::kDuration1
curve:UIViewAnimationCurveEaseInOut
animations:^{
CGFloat omniboxLeadingPadding = 10;
// Incognito.
if (_incognito) {
_incognitoIcon.alpha = 1;
_incognitoIcon.frame =
CGRectMake(_incognitoIcon.frame.origin.x -
kPositionAnimationLeadingOffset,
_incognitoIcon.frame.origin.y,
_incognitoIcon.frame.size.width,
_incognitoIcon.frame.size.height);
omniboxLeadingPadding =
omniboxLeadingPadding + _incognitoIcon.frame.size.width;
}
// Omnibox and OmniboxBackground.
_omniBox.frame =
CGRectMake(newOmniboxFrame.origin.x + omniboxLeadingPadding,
_omniBox.frame.origin.y, toBounds.size.width - 10,
toBounds.size.height);
_omniboxBackground.frame = CGRectMake(
self.view.bounds.origin.x, self.view.bounds.origin.y,
backgroundToBounds.size.width,
backgroundToBounds.size.height);
}];
// Perfom cancel button animation on completion.
[_cancelButton setHidden:NO];
__weak UIButton* weakCancelButton = _cancelButton;
_cancelButton.alpha = 0;
[self.omniboxExpanderAnimator addCompletion:^(
UIViewAnimatingPosition finalPosition) {
CGRect finalCancelButtonFrame = weakCancelButton.frame;
weakCancelButton.frame = CGRectLayoutOffset(
weakCancelButton.frame, kPositionAnimationLeadingOffset);
// Create and start the cancel button animation.
[UIViewPropertyAnimator
runningPropertyAnimatorWithDuration:0.2
delay:0.1
options:UIViewAnimationOptionCurveEaseOut
animations:^{
weakCancelButton.alpha = 1.0;
weakCancelButton.frame =
finalCancelButtonFrame;
}
completion:nil];
}];
// Add standard Toolbar buttons animations.
[self configureFadeOutAnimation];
// Add navigation buttons animations.
[self configureFadeOutNavigationControlsAnimation];
// Set the _omnibox animator.
_omniBox.omniboxExpanderAnimator = self.omniboxExpanderAnimator;
[self.omniboxExpanderAnimator startAnimation];
}
- (void)contractOmnibox API_AVAILABLE(ios(10.0)) {
if (IsIPadIdiom())
return [self layoutOmnibox];
// Return if PropertyAnimator is already running.
if (self.omniboxContractorAnimator.isRunning)
return;
CGRect newOmniboxFrame = [self newOmniboxFrame];
__weak UIButton* weakCancelButton = _cancelButton;
self.omniboxContractorAnimator = [[UIViewPropertyAnimator alloc]
initWithDuration:ios::material::kDuration1
curve:UIViewAnimationCurveEaseInOut
animations:^{
if (_incognito) {
_incognitoIcon.alpha = 0;
_incognitoIcon.frame =
CGRectMake(_incognitoIcon.frame.origin.x +
kPositionAnimationLeadingOffset,
_incognitoIcon.frame.origin.y,
_incognitoIcon.frame.size.width,
_incognitoIcon.frame.size.height);
}
// Cancel Button.
weakCancelButton.alpha = 0;
weakCancelButton.frame =
CGRectMake(weakCancelButton.frame.origin.x +
kPositionAnimationLeadingOffset,
weakCancelButton.frame.origin.y,
weakCancelButton.frame.size.width,
weakCancelButton.frame.size.height);
// Omnibox and OmniboxBackground bounds.
_omniBox.frame = CGRectMake(
newOmniboxFrame.origin.x, _omniBox.frame.origin.y,
newOmniboxFrame.size.width - 10, newOmniboxFrame.size.height);
_omniboxBackground.frame = CGRectMake(
newOmniboxFrame.origin.x,
newOmniboxFrame.origin.y + StatusBarHeight(),
newOmniboxFrame.size.width - 10, newOmniboxFrame.size.height);
}];
// Hide cancel button on completion.
[self.omniboxContractorAnimator
addCompletion:^(UIViewAnimatingPosition finalPosition) {
weakCancelButton.hidden = YES;
}];
// Add standard Toolbar buttons animations.
[self configureFadeInAnimation];
// Add navigation buttons animations.
[self configureFadeInNavigationControlsAnimation];
// Set the _omnibox animator.
_omniBox.omniboxContractorAnimator = self.omniboxContractorAnimator;
[self.omniboxContractorAnimator startAnimation];
}
- (void)animateMaterialOmnibox { - (void)animateMaterialOmnibox {
// The iPad omnibox does not animate. // The iPad omnibox does not animate.
if (IsIPadIdiom()) if (IsIPadIdiom())
...@@ -2093,6 +2286,31 @@ using ios::material::TimingFunction; ...@@ -2093,6 +2286,31 @@ using ios::material::TimingFunction;
} }
} }
- (void)configureFadeInNavigationControlsAnimation API_AVAILABLE(ios(10.0)) {
CGRect finalBackButtonFrame = _backButton.frame;
CGRect shifted =
CGRectLayoutOffset(_backButton.frame, kPositionAnimationLeadingOffset);
_backButton.frame = shifted;
__weak UIButton* weakBackButton = _backButton;
[self.omniboxContractorAnimator addAnimations:^{
weakBackButton.alpha = 1.0;
weakBackButton.frame = finalBackButtonFrame;
}
delayFactor:ios::material::kDuration1];
if ([_forwardButton isEnabled]) {
CGRect finalForwardButtonFrame = _forwardButton.frame;
_forwardButton.frame = CGRectLayoutOffset(_forwardButton.frame,
kPositionAnimationLeadingOffset);
__weak UIButton* weakForwardButton = _forwardButton;
[self.omniboxContractorAnimator addAnimations:^{
weakForwardButton.alpha = 1.0;
weakForwardButton.frame = finalForwardButtonFrame;
}
delayFactor:ios::material::kDuration3];
}
}
- (void)fadeOutNavigationControls { - (void)fadeOutNavigationControls {
[CATransaction begin]; [CATransaction begin];
[CATransaction setAnimationDuration:ios::material::kDuration2]; [CATransaction setAnimationDuration:ios::material::kDuration2];
...@@ -2135,6 +2353,35 @@ using ios::material::TimingFunction; ...@@ -2135,6 +2353,35 @@ using ios::material::TimingFunction;
[CATransaction commit]; [CATransaction commit];
} }
- (void)configureFadeOutNavigationControlsAnimation API_AVAILABLE(ios(10.0)) {
// Animate the navigation buttons 10 pixels to the left and opacity to 0;
CGRect originalBackFrame = _backButton.frame;
__weak UIButton* weakBackButton = _backButton;
[self.omniboxExpanderAnimator addAnimations:^{
weakBackButton.alpha = 0.0;
weakBackButton.frame = CGRectLayoutOffset(weakBackButton.frame,
kPositionAnimationLeadingOffset);
}];
[self.omniboxExpanderAnimator
addCompletion:^(UIViewAnimatingPosition finalPosition) {
weakBackButton.frame = originalBackFrame;
}];
if ([_forwardButton isEnabled]) {
CGRect originalForwardFrame = _forwardButton.frame;
__weak UIButton* weakForwardButton = _forwardButton;
[self.omniboxExpanderAnimator addAnimations:^{
weakForwardButton.alpha = 0.0;
weakForwardButton.frame = CGRectLayoutOffset(
weakForwardButton.frame, kPositionAnimationLeadingOffset);
}];
[self.omniboxExpanderAnimator
addCompletion:^(UIViewAnimatingPosition finalPosition) {
weakForwardButton.frame = originalForwardFrame;
}];
}
}
#pragma mark Omnibox Cancel Button. #pragma mark Omnibox Cancel Button.
- (UIButton*)cancelButton { - (UIButton*)cancelButton {
......
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