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

Side by Side Diff: ios/chrome/browser/ui/collection_view/cells/collection_view_text_cell.mm

Issue 2764783006: Create CollectionViewTextCell (Closed)
Patch Set: Add comment Created 3 years, 9 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
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_cell.h "
6
7 #if !defined(__has_feature) || !__has_feature(objc_arc)
8 #error "This file requires ARC support."
9 #endif
10
11 namespace {
12 const CGFloat kMargin = 16;
13 const CGFloat kMinimalHeight = 48;
14 }
15
16 @implementation CollectionViewTextCell
17
18 @synthesize textLabel = _textLabel;
19 @synthesize detailTextLabel = _detailTextLabel;
20
21 - (instancetype)initWithFrame:(CGRect)frame {
22 self = [super initWithFrame:frame];
23 if (self) {
24 UIView* containerView = [[UIView alloc] initWithFrame:CGRectZero];
25 containerView.translatesAutoresizingMaskIntoConstraints = NO;
26 [self.contentView addSubview:containerView];
27
28 _textLabel = [[UILabel alloc] initWithFrame:CGRectZero];
29 _textLabel.translatesAutoresizingMaskIntoConstraints = NO;
30 [containerView addSubview:_textLabel];
31
32 _detailTextLabel = [[UILabel alloc] initWithFrame:CGRectZero];
33 _detailTextLabel.translatesAutoresizingMaskIntoConstraints = NO;
34 [containerView addSubview:_detailTextLabel];
35
36 [NSLayoutConstraint activateConstraints:@[
37 // Total height.
38 [self.contentView.heightAnchor
39 constraintGreaterThanOrEqualToConstant:kMinimalHeight],
lpromero 2017/03/22 15:51:47 Why? Material spec?
gambard 2017/03/23 09:41:29 Yes.
40
41 // Container.
42 [containerView.leadingAnchor
lpromero 2017/03/22 15:51:47 Why do you need the container? I'd remove it.
gambard 2017/03/23 09:41:29 The container is needed to center the labels in ca
43 constraintEqualToAnchor:self.contentView.leadingAnchor
44 constant:kMargin],
45 [containerView.trailingAnchor
46 constraintEqualToAnchor:self.contentView.trailingAnchor
47 constant:-kMargin],
48 [containerView.topAnchor
49 constraintGreaterThanOrEqualToAnchor:self.contentView.topAnchor
50 constant:kMargin],
51 [containerView.bottomAnchor
52 constraintLessThanOrEqualToAnchor:self.contentView.bottomAnchor
53 constant:-kMargin],
54 [containerView.centerYAnchor
55 constraintEqualToAnchor:self.contentView.centerYAnchor],
lpromero 2017/03/22 15:51:47 You already set top and bottom, why do you need th
gambard 2017/03/23 09:41:29 Same as above.
lpromero 2017/03/23 12:23:35 I see. And I didn't notice that the top/bottom whe
56
57 // Labels.
58 [_textLabel.leadingAnchor
59 constraintEqualToAnchor:containerView.leadingAnchor],
60 [_textLabel.trailingAnchor
61 constraintLessThanOrEqualToAnchor:containerView.trailingAnchor],
lpromero 2017/03/22 15:51:47 Why not going all the way to the trailing edge?
gambard 2017/03/23 09:41:29 We had some problem with RTL + editing when the la
62 [_textLabel.topAnchor constraintEqualToAnchor:containerView.topAnchor],
63 [_textLabel.bottomAnchor
64 constraintEqualToAnchor:_detailTextLabel.topAnchor],
65 [_detailTextLabel.leadingAnchor
66 constraintEqualToAnchor:_textLabel.leadingAnchor],
67 [_detailTextLabel.trailingAnchor
68 constraintLessThanOrEqualToAnchor:containerView.trailingAnchor],
69 [_detailTextLabel.bottomAnchor
70 constraintLessThanOrEqualToAnchor:containerView.bottomAnchor],
71 ]];
72 }
73 return self;
74 }
75
76 // Implement -layoutSubviews as per instructions in documentation for
77 // +[MDCCollectionViewCell cr_preferredHeightForWidth:forItem:].
78 - (void)layoutSubviews {
79 [super layoutSubviews];
80 // Adjust the text and detailText label preferredMaxLayoutWidth when the
81 // parent's width changes, for instance on screen rotation.
82 CGFloat prefferedMaxLayoutWidth =
lpromero 2017/03/23 12:23:35 preferred
gambard 2017/03/23 15:32:28 Done.
83 CGRectGetWidth(self.contentView.frame) - 2 * kMargin;
84 _textLabel.preferredMaxLayoutWidth = prefferedMaxLayoutWidth;
85 _detailTextLabel.preferredMaxLayoutWidth = prefferedMaxLayoutWidth;
86
87 // Re-layout with the new preferred width to allow the label to adjust its
88 // height.
89 [super layoutSubviews];
90 }
lpromero 2017/03/22 15:51:47 Can you add prepareForReuse?
gambard 2017/03/23 09:41:29 Done. I am not sure about what to reset in prepare
lpromero 2017/03/23 12:23:35 I guess we'll have to do incrementally.
gambard 2017/03/23 15:32:28 Acknowledged.
91
lpromero 2017/03/22 15:51:47 Can you add proper accessibility? I think it's jus
gambard 2017/03/23 09:41:29 The accessibility is done in the item.
lpromero 2017/03/23 12:23:35 Acknowledged.
92 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698