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

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

Issue 2629853003: Update the Share Extension View (Closed)
Patch Set: Cleanup Created 3 years, 11 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 "ios/chrome/share_extension/share_extension_view.h" 5 #import "ios/chrome/share_extension/share_extension_view.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #import "ios/chrome/share_extension/ui_util.h" 8 #import "ios/chrome/share_extension/ui_util.h"
9 9
10 #if !defined(__has_feature) || !__has_feature(objc_arc) 10 #if !defined(__has_feature) || !__has_feature(objc_arc)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 __weak id<ShareExtensionViewActionTarget> _target; 53 __weak id<ShareExtensionViewActionTarget> _target;
54 54
55 // Track if a button has been pressed. All button pressing will have no effect 55 // Track if a button has been pressed. All button pressing will have no effect
56 // if |_dismissed| is YES. 56 // if |_dismissed| is YES.
57 BOOL _dismissed; 57 BOOL _dismissed;
58 } 58 }
59 59
60 // Keep strong references of the views that need to be updated. 60 // Keep strong references of the views that need to be updated.
61 @property(nonatomic, strong) UILabel* titleLabel; 61 @property(nonatomic, strong) UILabel* titleLabel;
62 @property(nonatomic, strong) UILabel* URLLabel; 62 @property(nonatomic, strong) UILabel* URLLabel;
63 @property(nonatomic, strong) UIView* titleURLContainer;
63 @property(nonatomic, strong) UIButton* readingListButton; 64 @property(nonatomic, strong) UIButton* readingListButton;
64 @property(nonatomic, strong) UIImageView* screenshotView; 65 @property(nonatomic, strong) UIImageView* screenshotView;
65 @property(nonatomic, strong) UIStackView* itemStack; 66 @property(nonatomic, strong) UIView* itemView;
66 67
67 // View creation helpers. 68 // View creation helpers.
68 // Returns a view containing the shared items (title, URL, screenshot). This 69 // Returns a view containing the shared items (title, URL, screenshot). This
69 // method will set the ivars. 70 // method will set the ivars.
70 - (UIView*)sharedItemView; 71 - (UIView*)sharedItemView;
71 72
72 // Returns a button containing the with title |title| and action |selector| on 73 // Returns a button containing the with title |title| and action |selector| on
73 // |_target|. 74 // |_target|.
74 - (UIButton*)buttonWithTitle:(NSString*)title selector:(SEL)selector; 75 - (UIButton*)buttonWithTitle:(NSString*)title selector:(SEL)selector;
75 76
(...skipping 16 matching lines...) Expand all
92 // completion. 93 // completion.
93 - (void)animateButtonPressed:(UIButton*)sender 94 - (void)animateButtonPressed:(UIButton*)sender
94 withCompletion:(void (^)(void))completion; 95 withCompletion:(void (^)(void))completion;
95 96
96 @end 97 @end
97 98
98 @implementation ShareExtensionView 99 @implementation ShareExtensionView
99 100
100 @synthesize titleLabel = _titleLabel; 101 @synthesize titleLabel = _titleLabel;
101 @synthesize URLLabel = _URLLabel; 102 @synthesize URLLabel = _URLLabel;
103 @synthesize titleURLContainer = _titleURLContainer;
102 @synthesize readingListButton = _readingListButton; 104 @synthesize readingListButton = _readingListButton;
103 @synthesize screenshotView = _screenshotView; 105 @synthesize screenshotView = _screenshotView;
104 @synthesize itemStack = _itemStack; 106 @synthesize itemView = _itemView;
105 107
106 #pragma mark - Lifecycle 108 #pragma mark - Lifecycle
107 109
108 - (instancetype)initWithActionTarget: 110 - (instancetype)initWithActionTarget:
109 (id<ShareExtensionViewActionTarget>)target { 111 (id<ShareExtensionViewActionTarget>)target {
110 self = [super initWithFrame:CGRectZero]; 112 self = [super initWithFrame:CGRectZero];
111 if (self) { 113 if (self) {
112 DCHECK(target); 114 DCHECK(target);
113 _target = target; 115 _target = target;
114 _dismissed = NO; 116 _dismissed = NO;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 174
173 // URL label. Text will be filled by |setURL:| when available. 175 // URL label. Text will be filled by |setURL:| when available.
174 _URLLabel = [[UILabel alloc] initWithFrame:CGRectZero]; 176 _URLLabel = [[UILabel alloc] initWithFrame:CGRectZero];
175 [_URLLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; 177 [_URLLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
176 [_URLLabel setNumberOfLines:3]; 178 [_URLLabel setNumberOfLines:3];
177 [_URLLabel setLineBreakMode:NSLineBreakByWordWrapping]; 179 [_URLLabel setLineBreakMode:NSLineBreakByWordWrapping];
178 [_URLLabel setFont:[UIFont systemFontOfSize:12]]; 180 [_URLLabel setFont:[UIFont systemFontOfSize:12]];
179 181
180 // Screenshot view. Image will be filled by |setScreenshot:| when available. 182 // Screenshot view. Image will be filled by |setScreenshot:| when available.
181 _screenshotView = [[UIImageView alloc] initWithFrame:CGRectZero]; 183 _screenshotView = [[UIImageView alloc] initWithFrame:CGRectZero];
182 [_screenshotView.widthAnchor 184 [_screenshotView setTranslatesAutoresizingMaskIntoConstraints:NO];
183 constraintLessThanOrEqualToConstant:kScreenshotSize] 185 NSLayoutConstraint* imageWidthConstraint =
184 .active = YES; 186 [_screenshotView.widthAnchor constraintEqualToConstant:0];
187 imageWidthConstraint.priority = UILayoutPriorityDefaultHigh;
188 imageWidthConstraint.active = YES;
189
185 [_screenshotView.heightAnchor 190 [_screenshotView.heightAnchor
186 constraintEqualToAnchor:_screenshotView.widthAnchor] 191 constraintEqualToAnchor:_screenshotView.widthAnchor]
187 .active = YES; 192 .active = YES;
188 [_screenshotView setContentMode:UIViewContentModeScaleAspectFill]; 193 [_screenshotView setContentMode:UIViewContentModeScaleAspectFill];
189 [_screenshotView setClipsToBounds:YES]; 194 [_screenshotView setClipsToBounds:YES];
190 [_screenshotView setHidden:YES];
191 195
192 // |_screenshotView| should take as much space as needed. Lower compression 196 // |_screenshotView| should take as much space as needed. Lower compression
193 // resistance of the other elements. 197 // resistance of the other elements.
194 [_titleLabel 198 [_titleLabel
195 setContentCompressionResistancePriority:UILayoutPriorityDefaultLow 199 setContentCompressionResistancePriority:UILayoutPriorityDefaultLow
196 forAxis:UILayoutConstraintAxisHorizontal]; 200 forAxis:UILayoutConstraintAxisHorizontal];
197 [_titleLabel setContentHuggingPriority:UILayoutPriorityDefaultHigh 201 [_titleLabel setContentHuggingPriority:UILayoutPriorityDefaultHigh
198 forAxis:UILayoutConstraintAxisVertical]; 202 forAxis:UILayoutConstraintAxisVertical];
199 [_URLLabel setContentHuggingPriority:UILayoutPriorityDefaultHigh 203 [_URLLabel setContentHuggingPriority:UILayoutPriorityDefaultHigh
200 forAxis:UILayoutConstraintAxisVertical]; 204 forAxis:UILayoutConstraintAxisVertical];
201 205
202 [_URLLabel 206 [_URLLabel
203 setContentCompressionResistancePriority:UILayoutPriorityDefaultLow 207 setContentCompressionResistancePriority:UILayoutPriorityDefaultLow
204 forAxis:UILayoutConstraintAxisHorizontal]; 208 forAxis:UILayoutConstraintAxisHorizontal];
205 209
206 UIStackView* titleURLStack = [[UIStackView alloc] 210 _titleURLContainer = [[UIView alloc] initWithFrame:CGRectZero];
207 initWithArrangedSubviews:@[ _titleLabel, _URLLabel ]]; 211 [_titleURLContainer setTranslatesAutoresizingMaskIntoConstraints:NO];
208 [titleURLStack setAxis:UILayoutConstraintAxisVertical];
209 212
210 UIView* titleURLContainer = [[UIView alloc] initWithFrame:CGRectZero]; 213 [_titleURLContainer addSubview:_titleLabel];
211 [titleURLContainer setTranslatesAutoresizingMaskIntoConstraints:NO]; 214 [_titleURLContainer addSubview:_URLLabel];
212 [titleURLContainer addSubview:titleURLStack];
213 [[titleURLStack topAnchor]
214 constraintEqualToAnchor:[titleURLContainer topAnchor]
215 constant:kShareExtensionPadding]
216 .active = YES;
217 [[titleURLStack bottomAnchor]
218 constraintEqualToAnchor:[titleURLContainer bottomAnchor]
219 constant:-kShareExtensionPadding]
220 .active = YES;
221 215
222 [titleURLStack.centerYAnchor 216 _itemView = [[UIView alloc] init];
223 constraintEqualToAnchor:titleURLContainer.centerYAnchor] 217 [_itemView setTranslatesAutoresizingMaskIntoConstraints:NO];
224 .active = YES; 218 [_itemView addSubview:_titleURLContainer];
225 [titleURLStack.centerXAnchor 219 [_itemView addSubview:_screenshotView];
226 constraintEqualToAnchor:titleURLContainer.centerXAnchor]
227 .active = YES;
228 [titleURLStack.widthAnchor
229 constraintEqualToAnchor:titleURLContainer.widthAnchor]
230 .active = YES;
231 [titleURLStack
232 setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh
233 forAxis:UILayoutConstraintAxisVertical];
234 220
235 _itemStack = 221 [NSLayoutConstraint activateConstraints:@[
236 [[UIStackView alloc] initWithArrangedSubviews:@[ titleURLContainer ]]; 222 [_titleLabel.topAnchor
237 [_itemStack setAxis:UILayoutConstraintAxisHorizontal]; 223 constraintEqualToAnchor:_titleURLContainer.topAnchor],
238 [_itemStack setLayoutMargins:UIEdgeInsetsMake(kShareExtensionPadding, 224 [_URLLabel.topAnchor constraintEqualToAnchor:_titleLabel.bottomAnchor],
239 kShareExtensionPadding, 225 [_URLLabel.bottomAnchor
240 kShareExtensionPadding, 226 constraintEqualToAnchor:_titleURLContainer.bottomAnchor],
241 kShareExtensionPadding)]; 227 [_titleLabel.trailingAnchor
242 [_itemStack setLayoutMarginsRelativeArrangement:YES]; 228 constraintEqualToAnchor:_titleURLContainer.trailingAnchor],
243 [_itemStack setSpacing:kShareExtensionPadding]; 229 [_URLLabel.trailingAnchor
230 constraintEqualToAnchor:_titleURLContainer.trailingAnchor],
231 [_titleLabel.leadingAnchor
232 constraintEqualToAnchor:_titleURLContainer.leadingAnchor],
233 [_URLLabel.leadingAnchor
234 constraintEqualToAnchor:_titleURLContainer.leadingAnchor],
235 [_titleURLContainer.centerYAnchor
236 constraintEqualToAnchor:_itemView.centerYAnchor],
237 [_itemView.heightAnchor
238 constraintGreaterThanOrEqualToAnchor:_titleURLContainer.heightAnchor
239 multiplier:1
240 constant:2 * kShareExtensionPadding],
241 [_titleURLContainer.leadingAnchor
242 constraintEqualToAnchor:_itemView.leadingAnchor
243 constant:kShareExtensionPadding],
244 [_screenshotView.trailingAnchor
245 constraintEqualToAnchor:_itemView.trailingAnchor
246 constant:-kShareExtensionPadding],
247 [_itemView.heightAnchor
248 constraintGreaterThanOrEqualToAnchor:_screenshotView.heightAnchor
249 multiplier:1
250 constant:2 * kShareExtensionPadding],
251 [_screenshotView.centerYAnchor
252 constraintEqualToAnchor:_itemView.centerYAnchor],
253 ]];
244 254
245 [_titleLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; 255 NSLayoutConstraint* titleURLScreenshotConstraint =
246 [_URLLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; 256 [_titleURLContainer.trailingAnchor
247 [_screenshotView setTranslatesAutoresizingMaskIntoConstraints:NO]; 257 constraintEqualToAnchor:_screenshotView.leadingAnchor];
248 [titleURLStack setTranslatesAutoresizingMaskIntoConstraints:NO]; 258 titleURLScreenshotConstraint.priority = UILayoutPriorityDefaultHigh;
249 [_itemStack setTranslatesAutoresizingMaskIntoConstraints:NO]; 259 titleURLScreenshotConstraint.active = YES;
250 260
251 return _itemStack; 261 return _itemView;
252 } 262 }
253 263
254 - (UIView*)dividerViewWithVibrancy:(UIVisualEffect*)vibrancyEffect { 264 - (UIView*)dividerViewWithVibrancy:(UIVisualEffect*)vibrancyEffect {
255 UIVisualEffectView* dividerVibrancy = 265 UIVisualEffectView* dividerVibrancy =
256 [[UIVisualEffectView alloc] initWithEffect:vibrancyEffect]; 266 [[UIVisualEffectView alloc] initWithEffect:vibrancyEffect];
257 UIView* divider = [[UIView alloc] initWithFrame:CGRectZero]; 267 UIView* divider = [[UIView alloc] initWithFrame:CGRectZero];
258 [divider setBackgroundColor:[UIColor colorWithWhite:0 alpha:kLowAlpha]]; 268 [divider setBackgroundColor:[UIColor colorWithWhite:0 alpha:kLowAlpha]];
259 [[dividerVibrancy contentView] addSubview:divider]; 269 [[dividerVibrancy contentView] addSubview:divider];
260 [dividerVibrancy setTranslatesAutoresizingMaskIntoConstraints:NO]; 270 [dividerVibrancy setTranslatesAutoresizingMaskIntoConstraints:NO];
261 [divider setTranslatesAutoresizingMaskIntoConstraints:NO]; 271 [divider setTranslatesAutoresizingMaskIntoConstraints:NO];
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 417
408 - (void)setURL:(NSURL*)URL { 418 - (void)setURL:(NSURL*)URL {
409 [[self URLLabel] setText:[URL absoluteString]]; 419 [[self URLLabel] setText:[URL absoluteString]];
410 } 420 }
411 421
412 - (void)setTitle:(NSString*)title { 422 - (void)setTitle:(NSString*)title {
413 [[self titleLabel] setText:title]; 423 [[self titleLabel] setText:title];
414 } 424 }
415 425
416 - (void)setScreenshot:(UIImage*)screenshot { 426 - (void)setScreenshot:(UIImage*)screenshot {
417 [[self screenshotView] setHidden:NO]; 427 [self.screenshotView.widthAnchor constraintEqualToConstant:kScreenshotSize]
428 .active = YES;
429 [self.titleURLContainer.trailingAnchor
430 constraintEqualToAnchor:self.screenshotView.leadingAnchor
431 constant:-kShareExtensionPadding]
432 .active = YES;
418 [[self screenshotView] setImage:screenshot]; 433 [[self screenshotView] setImage:screenshot];
419 [[self itemStack] addArrangedSubview:[self screenshotView]];
420 } 434 }
421 435
422 @end 436 @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