Index: ios/chrome/share_extension/share_view_controller.mm |
diff --git a/ios/chrome/share_extension/share_view_controller.mm b/ios/chrome/share_extension/share_view_controller.mm |
index cfd96dd90ff60adbffcf114b6b902b6e09a8191b..8ea9e871b2560d788e77bc23c826b08596f3b913 100644 |
--- a/ios/chrome/share_extension/share_view_controller.mm |
+++ b/ios/chrome/share_extension/share_view_controller.mm |
@@ -59,9 +59,6 @@ const CGFloat kMediumAlpha = 0.5; |
// Loads all the shared elements from the extension context and update the UI. |
- (void)loadElementsFromContext; |
-// Performs a fade in animation for the whole widget. |
-- (void)fadeIn; |
- |
// Sets constaints to the widget so that margin are at least |
// kShareExtensionMargin points and widget width is closest up to |
// kShareExtensionMaxWidth points. |
@@ -75,6 +72,8 @@ const CGFloat kMediumAlpha = 0.5; |
@synthesize shareView = _shareView; |
@synthesize itemType = _itemType; |
+#pragma mark - UIViewController |
+ |
- (void)viewDidLoad { |
[super viewDidLoad]; |
@@ -94,9 +93,13 @@ const CGFloat kMediumAlpha = 0.5; |
[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] |
constraintEqualToAnchor:[self.view centerYAnchor]]; |
+ [_centerYConstraint setConstant:(self.view.frame.size.height + |
+ self.shareView.frame.size.height) / |
+ 2]; |
[_centerYConstraint setActive:YES]; |
[[[shareView centerXAnchor] constraintEqualToAnchor:[self.view centerXAnchor]] |
setActive:YES]; |
@@ -105,9 +108,23 @@ const CGFloat kMediumAlpha = 0.5; |
[self.shareView setTranslatesAutoresizingMaskIntoConstraints:NO]; |
[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]; |
Olivier
2016/12/20 16:31:44
Is this needed?
Will this not also fade in ?
gambard
2016/12/20 16:33:49
The dark background view will fade in and the exte
|
+ [self.view layoutIfNeeded]; |
+ }]; |
+} |
+ |
+#pragma mark - Private methods |
+ |
- (void)constrainWidgetWidth { |
// Setting the constraints. |
NSDictionary* views = @{ @"share" : self.shareView }; |
@@ -140,17 +157,6 @@ const CGFloat kMediumAlpha = 0.5; |
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 { |
NSString* typeURL = static_cast<NSString*>(kUTTypeURL); |
for (NSExtensionItem* item in self.extensionContext.inputItems) { |
@@ -195,10 +201,13 @@ const CGFloat kMediumAlpha = 0.5; |
} |
- (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. |
- [_centerYConstraint setConstant:-(self.view.frame.size.height + |
- self.shareView.frame.size.height) / |
+ // The direction (up or down) is relative to the output (cancel or submit). |
+ NSInteger direction = item ? -1 : 1; |
+ [_centerYConstraint setConstant:direction * |
+ (self.view.frame.size.height + |
+ self.shareView.frame.size.height) / |
2]; |
[UIView animateWithDuration:kAnimationDuration |
animations:^{ |