Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: ios/chrome/share_extension/share_view_controller.mm

Issue 2593563002: Tweak the share screen animation (Closed)
Patch Set: Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import <MobileCoreServices/MobileCoreServices.h> 5 #import <MobileCoreServices/MobileCoreServices.h>
6 6
7 #import "ios/chrome/share_extension/share_view_controller.h" 7 #import "ios/chrome/share_extension/share_view_controller.h"
8 8
9 #import "base/ios/block_types.h" 9 #import "base/ios/block_types.h"
10 #import "base/mac/foundation_util.h" 10 #import "base/mac/foundation_util.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 // If |cancel| is true, |actionType| is ignored. 52 // If |cancel| is true, |actionType| is ignored.
53 - (void)queueActionItemURL:(NSURL*)URL 53 - (void)queueActionItemURL:(NSURL*)URL
54 title:(NSString*)title 54 title:(NSString*)title
55 action:(app_group::ShareExtensionItemType)actionType 55 action:(app_group::ShareExtensionItemType)actionType
56 cancel:(BOOL)cancel 56 cancel:(BOOL)cancel
57 completion:(ProceduralBlock)completion; 57 completion:(ProceduralBlock)completion;
58 58
59 // Loads all the shared elements from the extension context and update the UI. 59 // Loads all the shared elements from the extension context and update the UI.
60 - (void)loadElementsFromContext; 60 - (void)loadElementsFromContext;
61 61
62 // Performs a fade in animation for the whole widget.
63 - (void)fadeIn;
64
65 // Sets constaints to the widget so that margin are at least 62 // Sets constaints to the widget so that margin are at least
66 // kShareExtensionMargin points and widget width is closest up to 63 // kShareExtensionMargin points and widget width is closest up to
67 // kShareExtensionMaxWidth points. 64 // kShareExtensionMaxWidth points.
68 - (void)constrainWidgetWidth; 65 - (void)constrainWidgetWidth;
69 66
70 @end 67 @end
71 68
72 @implementation ShareViewController 69 @implementation ShareViewController
73 70
74 @synthesize maskView = _maskView; 71 @synthesize maskView = _maskView;
75 @synthesize shareView = _shareView; 72 @synthesize shareView = _shareView;
76 @synthesize itemType = _itemType; 73 @synthesize itemType = _itemType;
77 74
75 #pragma mark - UIViewController
76
78 - (void)viewDidLoad { 77 - (void)viewDidLoad {
79 [super viewDidLoad]; 78 [super viewDidLoad];
80 79
81 // This view shadows the screen under the share extension. 80 // This view shadows the screen under the share extension.
82 UIView* maskView = [[UIView alloc] initWithFrame:CGRectZero]; 81 UIView* maskView = [[UIView alloc] initWithFrame:CGRectZero];
83 [self setMaskView:maskView]; 82 [self setMaskView:maskView];
84 [self.maskView 83 [self.maskView
85 setBackgroundColor:[UIColor colorWithWhite:0 alpha:kMediumAlpha]]; 84 setBackgroundColor:[UIColor colorWithWhite:0 alpha:kMediumAlpha]];
86 [self.view addSubview:self.maskView]; 85 [self.view addSubview:self.maskView];
87 ui_util::ConstrainAllSidesOfViewToView(self.view, self.maskView); 86 ui_util::ConstrainAllSidesOfViewToView(self.view, self.maskView);
88 87
89 // This view is the main view of the share extension. 88 // This view is the main view of the share extension.
90 ShareExtensionView* shareView = 89 ShareExtensionView* shareView =
91 [[ShareExtensionView alloc] initWithActionTarget:self]; 90 [[ShareExtensionView alloc] initWithActionTarget:self];
92 [self setShareView:shareView]; 91 [self setShareView:shareView];
93 [self.view addSubview:self.shareView]; 92 [self.view addSubview:self.shareView];
94 93
95 [self constrainWidgetWidth]; 94 [self constrainWidgetWidth];
96 95
97 // Center the widget in the screen. 96 // Position the widget below the screen. It will be slided up with an
97 // animation.
98 _centerYConstraint = [[shareView centerYAnchor] 98 _centerYConstraint = [[shareView centerYAnchor]
99 constraintEqualToAnchor:[self.view centerYAnchor]]; 99 constraintEqualToAnchor:[self.view centerYAnchor]];
100 [_centerYConstraint setConstant:(self.view.frame.size.height +
101 self.shareView.frame.size.height) /
102 2];
100 [_centerYConstraint setActive:YES]; 103 [_centerYConstraint setActive:YES];
101 [[[shareView centerXAnchor] constraintEqualToAnchor:[self.view centerXAnchor]] 104 [[[shareView centerXAnchor] constraintEqualToAnchor:[self.view centerXAnchor]]
102 setActive:YES]; 105 setActive:YES];
103 106
104 [self.maskView setTranslatesAutoresizingMaskIntoConstraints:NO]; 107 [self.maskView setTranslatesAutoresizingMaskIntoConstraints:NO];
105 [self.shareView setTranslatesAutoresizingMaskIntoConstraints:NO]; 108 [self.shareView setTranslatesAutoresizingMaskIntoConstraints:NO];
106 109
107 [self loadElementsFromContext]; 110 [self loadElementsFromContext];
108 [self fadeIn];
109 } 111 }
110 112
113 - (void)viewWillAppear:(BOOL)animated {
114 [super viewWillAppear:animated];
115
116 // Center the widget.
117 [_centerYConstraint setConstant:0];
118 [self.maskView setAlpha:0];
119 [UIView animateWithDuration:kAnimationDuration
120 animations:^{
121 [self.maskView setAlpha:1];
122 [self.view layoutIfNeeded];
123 }];
124 }
125
126 #pragma mark - Private methods
127
111 - (void)constrainWidgetWidth { 128 - (void)constrainWidgetWidth {
112 // Setting the constraints. 129 // Setting the constraints.
113 NSDictionary* views = @{ @"share" : self.shareView }; 130 NSDictionary* views = @{ @"share" : self.shareView };
114 131
115 NSDictionary* metrics = @{ 132 NSDictionary* metrics = @{
116 @"margin" : @(kShareExtensionMargin), 133 @"margin" : @(kShareExtensionMargin),
117 @"maxWidth" : @(kShareExtensionMaxWidth), 134 @"maxWidth" : @(kShareExtensionMaxWidth),
118 }; 135 };
119 136
120 NSArray* constraints = @[ 137 NSArray* constraints = @[
(...skipping 12 matching lines...) Expand all
133 views:views]]; 150 views:views]];
134 } 151 }
135 152
136 // |self.shareView| must be as large as possible and in the center of the 153 // |self.shareView| must be as large as possible and in the center of the
137 // screen. 154 // screen.
138 [self.shareView 155 [self.shareView
139 setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh 156 setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh
140 forAxis:UILayoutConstraintAxisHorizontal]; 157 forAxis:UILayoutConstraintAxisHorizontal];
141 } 158 }
142 159
143 - (void)fadeIn {
144 // Fade in animation.
145 [self.maskView setAlpha:0];
146 [self.shareView setAlpha:0];
147 [UIView animateWithDuration:kAnimationDuration
148 animations:^{
149 [self.maskView setAlpha:kMediumAlpha];
150 [self.shareView setAlpha:1];
151 }];
152 }
153
154 - (void)loadElementsFromContext { 160 - (void)loadElementsFromContext {
155 NSString* typeURL = static_cast<NSString*>(kUTTypeURL); 161 NSString* typeURL = static_cast<NSString*>(kUTTypeURL);
156 for (NSExtensionItem* item in self.extensionContext.inputItems) { 162 for (NSExtensionItem* item in self.extensionContext.inputItems) {
157 for (NSItemProvider* itemProvider in item.attachments) { 163 for (NSItemProvider* itemProvider in item.attachments) {
158 if ([itemProvider hasItemConformingToTypeIdentifier:typeURL]) { 164 if ([itemProvider hasItemConformingToTypeIdentifier:typeURL]) {
159 ItemBlock URLCompletion = ^(id idURL, NSError* error) { 165 ItemBlock URLCompletion = ^(id idURL, NSError* error) {
160 NSURL* URL = static_cast<NSURL*>(idURL); 166 NSURL* URL = static_cast<NSURL*>(idURL);
161 dispatch_async(dispatch_get_main_queue(), ^{ 167 dispatch_async(dispatch_get_main_queue(), ^{
162 _shareItem = [item copy]; 168 _shareItem = [item copy];
163 _shareURL = [URL copy]; 169 _shareURL = [URL copy];
(...skipping 23 matching lines...) Expand all
187 } 193 }
188 194
189 }; 195 };
190 [itemProvider loadPreviewImageWithOptions:imageOptions 196 [itemProvider loadPreviewImageWithOptions:imageOptions
191 completionHandler:ImageCompletion]; 197 completionHandler:ImageCompletion];
192 } 198 }
193 } 199 }
194 } 200 }
195 } 201 }
196 202
197 - (void)dismissAndReturnItem:(NSExtensionItem*)item { 203 - (void)dismissAndReturnItem:(NSExtensionItem*)item {
Olivier 2016/12/20 10:04:16 Animation should still slide up if you select an o
gambard 2016/12/20 10:24:07 Done.
198 // Set the Y center constraints so the whole extension slides up out of the 204 // Set the Y center constraints so the whole extension slides down out of the
199 // screen. Constant is relative to the center of the screen. 205 // screen. Constant is relative to the center of the screen.
200 [_centerYConstraint setConstant:-(self.view.frame.size.height + 206 [_centerYConstraint setConstant:(self.view.frame.size.height +
201 self.shareView.frame.size.height) / 207 self.shareView.frame.size.height) /
202 2]; 208 2];
203 [UIView animateWithDuration:kAnimationDuration 209 [UIView animateWithDuration:kAnimationDuration
204 animations:^{ 210 animations:^{
205 [self.maskView setAlpha:0]; 211 [self.maskView setAlpha:0];
206 [self.view layoutIfNeeded]; 212 [self.view layoutIfNeeded];
207 } 213 }
208 completion:^(BOOL finished) { 214 completion:^(BOOL finished) {
209 NSArray* returnItem = item ? @[ item ] : @[]; 215 NSArray* returnItem = item ? @[ item ] : @[];
210 [self.extensionContext completeRequestReturningItems:returnItem 216 [self.extensionContext completeRequestReturningItems:returnItem
211 completionHandler:nil]; 217 completionHandler:nil];
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 [self dismissAndReturnItem:_shareItem]; 295 [self dismissAndReturnItem:_shareItem];
290 }]; 296 }];
291 } 297 }
292 298
293 - (void)shareExtensionView:(id)sender 299 - (void)shareExtensionView:(id)sender
294 typeChanged:(app_group::ShareExtensionItemType)type { 300 typeChanged:(app_group::ShareExtensionItemType)type {
295 [self setItemType:type]; 301 [self setItemType:type];
296 } 302 }
297 303
298 @end 304 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698