| Index: ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_item.mm
|
| diff --git a/ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_item.mm b/ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_item.mm
|
| index bdad43a9fa824293aed16c58d67db906c9964bb8..b377bd329038ddd77b4ed4f1cdf9a7305d044f7b 100644
|
| --- a/ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_item.mm
|
| +++ b/ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_item.mm
|
| @@ -95,7 +95,7 @@ const CGFloat kSpacingIPad = 24;
|
|
|
| for (UIStackView* row in self.stackViews) {
|
| row.axis = UILayoutConstraintAxisHorizontal;
|
| - row.spacing = [self spacing];
|
| + row.spacing = [ContentSuggestionsMostVisitedCell spacing];
|
| row.translatesAutoresizingMaskIntoConstraints = NO;
|
| [_stackContainer addSubview:row];
|
| row.layoutMarginsRelativeArrangement = YES;
|
| @@ -136,15 +136,28 @@ const CGFloat kSpacingIPad = 24;
|
| - (NSUInteger)numberOfTilesPerLine {
|
| CGFloat availableWidth = self.contentView.bounds.size.width;
|
|
|
| - if (availableWidth > [self widthForNumberOfItem:4])
|
| + NSUInteger numberOfTiles =
|
| + [ContentSuggestionsMostVisitedCell numberOfTilesForWidth:availableWidth];
|
| + DCHECK(numberOfTiles > 1);
|
| + return numberOfTiles;
|
| +}
|
| +
|
| ++ (NSUInteger)numberOfTilesForWidth:(CGFloat)availableWidth {
|
| + if (availableWidth >
|
| + [ContentSuggestionsMostVisitedCell widthForNumberOfItem:4])
|
| return 4;
|
| - if (availableWidth > [self widthForNumberOfItem:3])
|
| + if (availableWidth >
|
| + [ContentSuggestionsMostVisitedCell widthForNumberOfItem:3])
|
| return 3;
|
| - if (availableWidth > [self widthForNumberOfItem:2])
|
| + if (availableWidth >
|
| + [ContentSuggestionsMostVisitedCell widthForNumberOfItem:2])
|
| return 2;
|
|
|
| - NOTREACHED();
|
| - return 2;
|
| + return 1;
|
| +}
|
| +
|
| ++ (CGFloat)spacing {
|
| + return IsIPadIdiom() ? kSpacingIPad : kSpacingIPhone;
|
| }
|
|
|
| #pragma mark - UIView
|
| @@ -192,18 +205,14 @@ const CGFloat kSpacingIPad = 24;
|
| }
|
| }
|
|
|
| - self.containerWidth.constant =
|
| - [self widthForNumberOfItem:numberOfTilesPerLine];
|
| -}
|
| -
|
| -// Returns the spacing between tiles, based on the device.
|
| -- (CGFloat)spacing {
|
| - return IsIPadIdiom() ? kSpacingIPad : kSpacingIPhone;
|
| + self.containerWidth.constant = [ContentSuggestionsMostVisitedCell
|
| + widthForNumberOfItem:numberOfTilesPerLine];
|
| }
|
|
|
| -// Returns the width necessary to fit |numberOfItem| items.
|
| -- (CGFloat)widthForNumberOfItem:(NSUInteger)numberOfItem {
|
| - return (numberOfItem - 1) * [self spacing] +
|
| +// Returns the width necessary to fit |numberOfItem| items, with padding on the
|
| +// side.
|
| ++ (CGFloat)widthForNumberOfItem:(NSUInteger)numberOfItem {
|
| + return (numberOfItem - 1) * [ContentSuggestionsMostVisitedCell spacing] +
|
| numberOfItem * [ContentSuggestionsMostVisitedTile width];
|
| }
|
|
|
|
|