| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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/browser/ui/content_suggestions/cells/content_suggestions_art
icle_item.h" | 5 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_art
icle_item.h" |
| 6 | 6 |
| 7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
| 8 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 8 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
| 9 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 9 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 10 #import "ios/chrome/browser/ui/util/i18n_string.h" | 10 #import "ios/chrome/browser/ui/util/i18n_string.h" |
| 11 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" | 11 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
| 12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 13 | 13 |
| 14 #if !defined(__has_feature) || !__has_feature(objc_arc) | 14 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 15 #error "This file requires ARC support." | 15 #error "This file requires ARC support." |
| 16 #endif | 16 #endif |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 const CGFloat kImageSize = 72; | 19 const CGFloat kImageSize = 72; |
| 20 // When updating this, make sure to update |layoutSubviews|. | 20 // When updating this, make sure to update |layoutSubviews|. |
| 21 const CGFloat kStandardSpacing = 8; | 21 const CGFloat kStandardSpacing = 16; |
| 22 } | 22 } |
| 23 | 23 |
| 24 @interface ContentSuggestionsArticleItem () | 24 @interface ContentSuggestionsArticleItem () |
| 25 | 25 |
| 26 @property(nonatomic, copy) NSString* subtitle; | 26 @property(nonatomic, copy) NSString* subtitle; |
| 27 // Used to check if the image has already been fetched. There is no way to | 27 // Used to check if the image has already been fetched. There is no way to |
| 28 // discriminate between failed image download and nonexitent image. The article | 28 // discriminate between failed image download and nonexitent image. The article |
| 29 // tries to download the image only once. | 29 // tries to download the image only once. |
| 30 @property(nonatomic, assign) BOOL imageFetched; | 30 @property(nonatomic, assign) BOOL imageFetched; |
| 31 | 31 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 112 |
| 113 - (instancetype)initWithFrame:(CGRect)frame { | 113 - (instancetype)initWithFrame:(CGRect)frame { |
| 114 self = [super initWithFrame:frame]; | 114 self = [super initWithFrame:frame]; |
| 115 if (self) { | 115 if (self) { |
| 116 _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; | 116 _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
| 117 _subtitleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; | 117 _subtitleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
| 118 _imageView = [[UIImageView alloc] initWithFrame:CGRectZero]; | 118 _imageView = [[UIImageView alloc] initWithFrame:CGRectZero]; |
| 119 _publisherLabel = [[UILabel alloc] initWithFrame:CGRectZero]; | 119 _publisherLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
| 120 | 120 |
| 121 _titleLabel.numberOfLines = 2; | 121 _titleLabel.numberOfLines = 2; |
| 122 _subtitleLabel.numberOfLines = 0; | 122 _subtitleLabel.numberOfLines = 2; |
| 123 [_subtitleLabel setContentHuggingPriority:UILayoutPriorityDefaultHigh | 123 [_subtitleLabel setContentHuggingPriority:UILayoutPriorityDefaultHigh |
| 124 forAxis:UILayoutConstraintAxisVertical]; | 124 forAxis:UILayoutConstraintAxisVertical]; |
| 125 [_titleLabel setContentHuggingPriority:UILayoutPriorityDefaultHigh | 125 [_titleLabel setContentHuggingPriority:UILayoutPriorityDefaultHigh |
| 126 forAxis:UILayoutConstraintAxisVertical]; | 126 forAxis:UILayoutConstraintAxisVertical]; |
| 127 _imageView.contentMode = UIViewContentModeScaleAspectFill; | 127 _imageView.contentMode = UIViewContentModeScaleAspectFill; |
| 128 _imageView.clipsToBounds = YES; | 128 _imageView.clipsToBounds = YES; |
| 129 | 129 |
| 130 _imageView.translatesAutoresizingMaskIntoConstraints = NO; | 130 _imageView.translatesAutoresizingMaskIntoConstraints = NO; |
| 131 _titleLabel.translatesAutoresizingMaskIntoConstraints = NO; | 131 _titleLabel.translatesAutoresizingMaskIntoConstraints = NO; |
| 132 _subtitleLabel.translatesAutoresizingMaskIntoConstraints = NO; | 132 _subtitleLabel.translatesAutoresizingMaskIntoConstraints = NO; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 // height. | 180 // height. |
| 181 [super layoutSubviews]; | 181 [super layoutSubviews]; |
| 182 } | 182 } |
| 183 | 183 |
| 184 #pragma mark - Private | 184 #pragma mark - Private |
| 185 | 185 |
| 186 - (void)applyConstraints { | 186 - (void)applyConstraints { |
| 187 [NSLayoutConstraint activateConstraints:@[ | 187 [NSLayoutConstraint activateConstraints:@[ |
| 188 [_imageView.widthAnchor constraintEqualToConstant:kImageSize], | 188 [_imageView.widthAnchor constraintEqualToConstant:kImageSize], |
| 189 [_imageView.heightAnchor constraintEqualToAnchor:_imageView.widthAnchor], | 189 [_imageView.heightAnchor constraintEqualToAnchor:_imageView.widthAnchor], |
| 190 [_imageView.topAnchor constraintEqualToAnchor:_titleLabel.topAnchor], |
| 190 [_publisherLabel.topAnchor | 191 [_publisherLabel.topAnchor |
| 191 constraintGreaterThanOrEqualToAnchor:_imageView.bottomAnchor | 192 constraintGreaterThanOrEqualToAnchor:_imageView.bottomAnchor |
| 192 constant:kStandardSpacing], | 193 constant:kStandardSpacing], |
| 193 [_publisherLabel.topAnchor | 194 [_publisherLabel.topAnchor |
| 194 constraintGreaterThanOrEqualToAnchor:_subtitleLabel.bottomAnchor | 195 constraintGreaterThanOrEqualToAnchor:_subtitleLabel.bottomAnchor |
| 195 constant:kStandardSpacing], | 196 constant:kStandardSpacing], |
| 196 ]]; | 197 ]]; |
| 197 | 198 |
| 198 ApplyVisualConstraintsWithMetrics( | 199 ApplyVisualConstraintsWithMetrics( |
| 199 @[ | 200 @[ |
| 200 @"H:|-(space)-[title]-(space)-[image]-(space)-|", | 201 @"H:|-(space)-[title]-(space)-[image]-(space)-|", |
| 201 @"H:|-(space)-[text]-(space)-[image]", | 202 @"H:|-(space)-[text]-(space)-[image]", |
| 202 @"V:|-[title]-[text]", | 203 @"V:|-(space)-[title]-[text]", |
| 203 @"V:|-[image]", | 204 @"H:|-(space)-[publish]-(space)-|", |
| 204 @"H:|-[publish]-|", | |
| 205 @"V:[publish]-|", | 205 @"V:[publish]-|", |
| 206 ], | 206 ], |
| 207 @{ | 207 @{ |
| 208 @"image" : _imageView, | 208 @"image" : _imageView, |
| 209 @"title" : _titleLabel, | 209 @"title" : _titleLabel, |
| 210 @"text" : _subtitleLabel, | 210 @"text" : _subtitleLabel, |
| 211 @"publish" : _publisherLabel, | 211 @"publish" : _publisherLabel, |
| 212 }, | 212 }, |
| 213 @{ @"space" : @(kStandardSpacing) }); | 213 @{ @"space" : @(kStandardSpacing) }); |
| 214 } | 214 } |
| 215 | 215 |
| 216 @end | 216 @end |
| OLD | NEW |