Commit b1309cfb authored by gambard's avatar gambard Committed by Commit bot

Tweak the share screen animation

Change the share view animation from fade in/slide up to slide up/slide down.

BUG=672773

Review-Url: https://codereview.chromium.org/2593563002
Cr-Commit-Position: refs/heads/master@{#439826}
parent 29cd6645
...@@ -59,9 +59,6 @@ const CGFloat kMediumAlpha = 0.5; ...@@ -59,9 +59,6 @@ const CGFloat kMediumAlpha = 0.5;
// Loads all the shared elements from the extension context and update the UI. // Loads all the shared elements from the extension context and update the UI.
- (void)loadElementsFromContext; - (void)loadElementsFromContext;
// Performs a fade in animation for the whole widget.
- (void)fadeIn;
// Sets constaints to the widget so that margin are at least // Sets constaints to the widget so that margin are at least
// kShareExtensionMargin points and widget width is closest up to // kShareExtensionMargin points and widget width is closest up to
// kShareExtensionMaxWidth points. // kShareExtensionMaxWidth points.
...@@ -75,6 +72,8 @@ const CGFloat kMediumAlpha = 0.5; ...@@ -75,6 +72,8 @@ const CGFloat kMediumAlpha = 0.5;
@synthesize shareView = _shareView; @synthesize shareView = _shareView;
@synthesize itemType = _itemType; @synthesize itemType = _itemType;
#pragma mark - UIViewController
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
...@@ -94,9 +93,13 @@ const CGFloat kMediumAlpha = 0.5; ...@@ -94,9 +93,13 @@ const CGFloat kMediumAlpha = 0.5;
[self constrainWidgetWidth]; [self constrainWidgetWidth];
// Center the widget in the screen. // Position the widget below the screen. It will be slided up with an
// animation.
_centerYConstraint = [[shareView centerYAnchor] _centerYConstraint = [[shareView centerYAnchor]
constraintEqualToAnchor:[self.view centerYAnchor]]; constraintEqualToAnchor:[self.view centerYAnchor]];
[_centerYConstraint setConstant:(self.view.frame.size.height +
self.shareView.frame.size.height) /
2];
[_centerYConstraint setActive:YES]; [_centerYConstraint setActive:YES];
[[[shareView centerXAnchor] constraintEqualToAnchor:[self.view centerXAnchor]] [[[shareView centerXAnchor] constraintEqualToAnchor:[self.view centerXAnchor]]
setActive:YES]; setActive:YES];
...@@ -105,9 +108,23 @@ const CGFloat kMediumAlpha = 0.5; ...@@ -105,9 +108,23 @@ const CGFloat kMediumAlpha = 0.5;
[self.shareView setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.shareView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self loadElementsFromContext]; [self loadElementsFromContext];
[self fadeIn];
} }
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// Center the widget.
[_centerYConstraint setConstant:0];
[self.maskView setAlpha:0];
[UIView animateWithDuration:kAnimationDuration
animations:^{
[self.maskView setAlpha:1];
[self.view layoutIfNeeded];
}];
}
#pragma mark - Private methods
- (void)constrainWidgetWidth { - (void)constrainWidgetWidth {
// Setting the constraints. // Setting the constraints.
NSDictionary* views = @{ @"share" : self.shareView }; NSDictionary* views = @{ @"share" : self.shareView };
...@@ -140,17 +157,6 @@ const CGFloat kMediumAlpha = 0.5; ...@@ -140,17 +157,6 @@ const CGFloat kMediumAlpha = 0.5;
forAxis:UILayoutConstraintAxisHorizontal]; forAxis:UILayoutConstraintAxisHorizontal];
} }
- (void)fadeIn {
// Fade in animation.
[self.maskView setAlpha:0];
[self.shareView setAlpha:0];
[UIView animateWithDuration:kAnimationDuration
animations:^{
[self.maskView setAlpha:kMediumAlpha];
[self.shareView setAlpha:1];
}];
}
- (void)loadElementsFromContext { - (void)loadElementsFromContext {
NSString* typeURL = static_cast<NSString*>(kUTTypeURL); NSString* typeURL = static_cast<NSString*>(kUTTypeURL);
for (NSExtensionItem* item in self.extensionContext.inputItems) { for (NSExtensionItem* item in self.extensionContext.inputItems) {
...@@ -195,10 +201,13 @@ const CGFloat kMediumAlpha = 0.5; ...@@ -195,10 +201,13 @@ const CGFloat kMediumAlpha = 0.5;
} }
- (void)dismissAndReturnItem:(NSExtensionItem*)item { - (void)dismissAndReturnItem:(NSExtensionItem*)item {
// Set the Y center constraints so the whole extension slides up out of the // Set the Y center constraints so the whole extension slides out of the
// screen. Constant is relative to the center of the screen. // screen. Constant is relative to the center of the screen.
[_centerYConstraint setConstant:-(self.view.frame.size.height + // The direction (up or down) is relative to the output (cancel or submit).
self.shareView.frame.size.height) / NSInteger direction = item ? -1 : 1;
[_centerYConstraint setConstant:direction *
(self.view.frame.size.height +
self.shareView.frame.size.height) /
2]; 2];
[UIView animateWithDuration:kAnimationDuration [UIView animateWithDuration:kAnimationDuration
animations:^{ animations:^{
......
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