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[] = {
{"ios-share-canonical-url", flag_descriptions::kShareCanonicalURLName,
flag_descriptions::kShareCanonicalURLDescription, flags_ui::kOsIos,
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|.
void AppendSwitchesFromExperimentalSettings(base::CommandLine* command_line) {
......
......@@ -73,6 +73,12 @@ const char kPhysicalWebDescription[] =
"When enabled, the omnibox will include suggestions for web pages "
"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[] =
"Safe Area Compatible Toolbar";
extern const char kSafeAreaCompatibleToolbarDescription[] =
......
......@@ -66,6 +66,11 @@ extern const char kOmniboxUIHideSuggestionUrlTrivialSubdomainsDescription[];
extern const char kPhysicalWeb[];
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.
extern const char kSafeAreaCompatibleToolbarName[];
extern const char kSafeAreaCompatibleToolbarDescription[];
......
......@@ -92,6 +92,7 @@ source_set("omnibox_internal") {
"//ios/chrome/browser/sessions",
"//ios/chrome/browser/ui",
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/toolbar/public",
"//ios/chrome/common",
"//ios/public/provider/chrome/browser",
"//ios/third_party/material_components_ios",
......
......@@ -121,6 +121,12 @@ typedef enum {
@property(nonatomic, strong) UIColor* selectedTextBackgroundColor;
@property(nonatomic, strong) UIColor* placeholderTextColor;
@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
......
......@@ -21,6 +21,7 @@
#include "ios/chrome/browser/ui/omnibox/omnibox_util.h"
#import "ios/chrome/browser/ui/reversed_animation.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"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#import "ios/chrome/common/material_timing.h"
......@@ -109,6 +110,8 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation";
@synthesize selectedTextBackgroundColor = _selectedTextBackgroundColor;
@synthesize placeholderTextColor = _placeholderTextColor;
@synthesize incognito = _incognito;
@synthesize omniboxExpanderAnimator = _omniboxExpanderAnimator;
@synthesize omniboxContractorAnimator = _omniboxContractorAnimator;
// Overload to allow for code-based initialization.
- (instancetype)initWithFrame:(CGRect)frame {
......@@ -165,6 +168,69 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation";
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.
- (id<OmniboxTextFieldDelegate>)delegate {
id delegate = [super delegate];
......
......@@ -10,4 +10,7 @@
// Feature to choose whether the toolbar respects the safe area.
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_
......@@ -6,3 +6,6 @@
const base::Feature kSafeAreaCompatibleToolbar{
"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;
// kToolbarTransitionAnimationKey.
@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.
- (void)updateStandardButtons;
......@@ -87,6 +95,13 @@ extern NSString* const kToolbarTransitionAnimationKey;
// animation used for Material.
- (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
#endif // IOS_CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_CONTROLLER_PROTECTED_H_
......@@ -85,6 +85,12 @@ using ios::material::TimingFunction;
// The following is nil if not visible.
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|.
......@@ -733,6 +739,24 @@ using ios::material::TimingFunction;
[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 Animations
- (void)fadeOutStandardControls {
......@@ -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 {
for (UIButton* button in standardButtons_) {
[self fadeInView:button
......@@ -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
containerBeginBounds:(CGRect)containerBeginBounds
containerEndBounds:(CGRect)containerEndBounds
......
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