Commit c74a83d8 authored by Jérôme Lebel's avatar Jérôme Lebel Committed by Commit Bot

[iOS] Moving SettingsImageDetailTextCell into its own file

This is to prepare the implementation of AccountSignInItem using
UITableViewItem.
See: crrev.com/c/1392962

Change-Id: Ie1d6ae2af7189f7e4e68878efb4bfe50b02604bd
Reviewed-on: https://chromium-review.googlesource.com/c/1392961Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Commit-Queue: Jérôme Lebel <jlebel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#619934}
parent 01d76a4d
...@@ -26,6 +26,8 @@ source_set("cells") { ...@@ -26,6 +26,8 @@ source_set("cells") {
"settings_cells_constants.mm", "settings_cells_constants.mm",
"settings_detail_item.h", "settings_detail_item.h",
"settings_detail_item.mm", "settings_detail_item.mm",
"settings_image_detail_text_cell.h",
"settings_image_detail_text_cell.mm",
"settings_image_detail_text_item.h", "settings_image_detail_text_item.h",
"settings_image_detail_text_item.mm", "settings_image_detail_text_item.mm",
"settings_multiline_detail_item.h", "settings_multiline_detail_item.h",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_SETTINGS_CELLS_SETTINGS_IMAGE_DETAIL_TEXT_CELL_H_
#define IOS_CHROME_BROWSER_UI_SETTINGS_CELLS_SETTINGS_IMAGE_DETAIL_TEXT_CELL_H_
#import <Foundation/Foundation.h>
#import "ios/chrome/browser/ui/table_view/cells/table_view_item.h"
// Cell representation for SettingsImageDetailTextItem.
// +--------------------------------------------------+
// | +-------+ |
// | | image | Multiline title |
// | | | Optional multiline detail text |
// | +-------+ |
// +--------------------------------------------------+
@interface SettingsImageDetailTextCell : UITableViewCell
// Cell image.
@property(nonatomic, strong) UIImage* image;
// Cell title.
@property(nonatomic, readonly, strong) UILabel* textLabel;
// Cell subtitle.
@property(nonatomic, readonly, strong) UILabel* detailTextLabel;
@end
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_CELLS_SETTINGS_IMAGE_DETAIL_TEXT_CELL_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/settings/cells/settings_image_detail_text_cell.h"
#include "base/logging.h"
#include "ios/chrome/browser/ui/table_view/cells/table_view_cells_constants.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface SettingsImageDetailTextCell ()
// Width constraint for the image view.
@property(nonatomic, weak, readonly) NSLayoutConstraint* imageWidthConstraint;
// Height constraint for the image view.
@property(nonatomic, weak, readonly) NSLayoutConstraint* imageHeightConstraint;
// Image view for the cell.
@property(nonatomic, strong) UIImageView* imageView;
@end
@implementation SettingsImageDetailTextCell
@synthesize textLabel = _textLabel;
@synthesize detailTextLabel = _detailTextLabel;
@synthesize imageView = _imageView;
- (instancetype)initWithStyle:(UITableViewCellStyle)style
reuseIdentifier:(NSString*)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.isAccessibilityElement = YES;
[self addSubviews];
[self setViewConstraints];
}
return self;
}
// Creates and adds subviews.
- (void)addSubviews {
UIView* contentView = self.contentView;
_imageView = [[UIImageView alloc] init];
_imageView.translatesAutoresizingMaskIntoConstraints = NO;
[contentView addSubview:_imageView];
_textLabel = [[UILabel alloc] init];
_textLabel.numberOfLines = 0;
_textLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
_textLabel.adjustsFontForContentSizeCategory = YES;
_textLabel.textColor = UIColor.blackColor;
_detailTextLabel = [[UILabel alloc] init];
_detailTextLabel.numberOfLines = 0;
_detailTextLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleFootnote];
_detailTextLabel.adjustsFontForContentSizeCategory = YES;
_detailTextLabel.textColor =
UIColorFromRGB(kTableViewSecondaryLabelLightGrayTextColor);
}
// Sets constraints on subviews.
- (void)setViewConstraints {
UIView* contentView = self.contentView;
UIStackView* textStackView = [[UIStackView alloc]
initWithArrangedSubviews:@[ _textLabel, _detailTextLabel ]];
textStackView.axis = UILayoutConstraintAxisVertical;
textStackView.translatesAutoresizingMaskIntoConstraints = NO;
[contentView addSubview:textStackView];
_imageWidthConstraint = [_imageView.widthAnchor constraintEqualToConstant:0];
_imageHeightConstraint =
[_imageView.heightAnchor constraintEqualToConstant:0];
[NSLayoutConstraint activateConstraints:@[
// Horizontal contraints for |_imageView| and |textStackView|.
_imageWidthConstraint,
[_imageView.leadingAnchor
constraintEqualToAnchor:contentView.leadingAnchor
constant:kTableViewHorizontalSpacing],
[textStackView.leadingAnchor
constraintEqualToAnchor:_imageView.trailingAnchor
constant:kTableViewHorizontalSpacing],
[contentView.trailingAnchor
constraintEqualToAnchor:textStackView.trailingAnchor
constant:kTableViewHorizontalSpacing],
// Vertical contraints for |_imageView| and |textStackView|.
_imageHeightConstraint,
[_imageView.centerYAnchor
constraintEqualToAnchor:contentView.centerYAnchor],
[_imageView.topAnchor
constraintGreaterThanOrEqualToAnchor:contentView.topAnchor
constant:kTableViewLargeVerticalSpacing],
[contentView.bottomAnchor
constraintGreaterThanOrEqualToAnchor:_imageView.bottomAnchor
constant:kTableViewLargeVerticalSpacing],
[textStackView.centerYAnchor
constraintEqualToAnchor:contentView.centerYAnchor],
[textStackView.topAnchor
constraintGreaterThanOrEqualToAnchor:contentView.topAnchor
constant:kTableViewLargeVerticalSpacing],
[contentView.bottomAnchor
constraintGreaterThanOrEqualToAnchor:textStackView.bottomAnchor
constant:kTableViewLargeVerticalSpacing],
]];
}
- (void)setImage:(UIImage*)image {
DCHECK(image);
self.imageView.image = image;
self.imageWidthConstraint.constant = image.size.width;
self.imageHeightConstraint.constant = image.size.height;
}
- (UIImage*)image {
return self.imageView.image;
}
#pragma mark - UIAccessibility
- (NSString*)accessibilityLabel {
if (self.detailTextLabel.text) {
return [NSString stringWithFormat:@"%@, %@", self.textLabel.text,
self.detailTextLabel.text];
}
return self.textLabel.text;
}
@end
...@@ -24,24 +24,4 @@ ...@@ -24,24 +24,4 @@
@end @end
// Cell representation for SettingsImageDetailTextItem.
// +--------------------------------------------------+
// | +-------+ |
// | | image | Multiline title |
// | | | Optional multiline detail text |
// | +-------+ |
// +--------------------------------------------------+
@interface SettingsImageDetailTextCell : UITableViewCell
// Cell image.
@property(nonatomic, readonly, strong) UIImageView* imageView;
// Cell title.
@property(nonatomic, readonly, strong) UILabel* textLabel;
// Cell subtitle.
@property(nonatomic, readonly, strong) UILabel* detailTextLabel;
@end
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_CELLS_SETTINGS_IMAGE_DETAIL_TEXT_ITEM_H_ #endif // IOS_CHROME_BROWSER_UI_SETTINGS_CELLS_SETTINGS_IMAGE_DETAIL_TEXT_ITEM_H_
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import "ios/chrome/browser/ui/settings/cells/settings_image_detail_text_item.h" #import "ios/chrome/browser/ui/settings/cells/settings_image_detail_text_item.h"
#include "base/logging.h" #include "base/logging.h"
#import "ios/chrome/browser/ui/settings/cells/settings_image_detail_text_cell.h"
#include "ios/chrome/browser/ui/table_view/cells/table_view_cells_constants.h" #include "ios/chrome/browser/ui/table_view/cells/table_view_cells_constants.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h" #import "ios/chrome/browser/ui/util/uikit_ui_util.h"
...@@ -12,15 +13,6 @@ ...@@ -12,15 +13,6 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
@interface SettingsImageDetailTextCell ()
@property(nonatomic, weak, readonly) NSLayoutConstraint* imageWidthConstraint;
@property(nonatomic, weak, readonly) NSLayoutConstraint* imageHeightConstraint;
@end
#pragma mark - SettingsImageDetailTextItem
@implementation SettingsImageDetailTextItem @implementation SettingsImageDetailTextItem
- (instancetype)initWithType:(NSInteger)type { - (instancetype)initWithType:(NSInteger)type {
...@@ -37,110 +29,7 @@ ...@@ -37,110 +29,7 @@
cell.textLabel.text = self.text; cell.textLabel.text = self.text;
cell.detailTextLabel.text = self.detailText; cell.detailTextLabel.text = self.detailText;
DCHECK(self.image); DCHECK(self.image);
cell.imageView.image = self.image; cell.image = self.image;
cell.imageWidthConstraint.constant = self.image.size.width;
cell.imageHeightConstraint.constant = self.image.size.height;
}
@end
#pragma mark - SettingsImageDetailTextCell
@implementation SettingsImageDetailTextCell
@synthesize imageView = _imageView;
@synthesize textLabel = _textLabel;
@synthesize detailTextLabel = _detailTextLabel;
- (instancetype)initWithStyle:(UITableViewCellStyle)style
reuseIdentifier:(NSString*)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.isAccessibilityElement = YES;
[self addSubviews];
[self setViewConstraints];
}
return self;
}
// Creates and adds subviews.
- (void)addSubviews {
UIView* contentView = self.contentView;
_imageView = [[UIImageView alloc] init];
_imageView.translatesAutoresizingMaskIntoConstraints = NO;
[contentView addSubview:_imageView];
_textLabel = [[UILabel alloc] init];
_textLabel.numberOfLines = 0;
_textLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
_textLabel.adjustsFontForContentSizeCategory = YES;
_textLabel.textColor = UIColor.blackColor;
_detailTextLabel = [[UILabel alloc] init];
_detailTextLabel.numberOfLines = 0;
_detailTextLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleFootnote];
_detailTextLabel.adjustsFontForContentSizeCategory = YES;
_detailTextLabel.textColor =
UIColorFromRGB(kTableViewSecondaryLabelLightGrayTextColor);
}
// Sets constraints on subviews.
- (void)setViewConstraints {
UIView* contentView = self.contentView;
UIStackView* textStackView = [[UIStackView alloc]
initWithArrangedSubviews:@[ _textLabel, _detailTextLabel ]];
textStackView.axis = UILayoutConstraintAxisVertical;
textStackView.translatesAutoresizingMaskIntoConstraints = NO;
[contentView addSubview:textStackView];
_imageWidthConstraint = [_imageView.widthAnchor constraintEqualToConstant:0];
_imageHeightConstraint =
[_imageView.heightAnchor constraintEqualToConstant:0];
[NSLayoutConstraint activateConstraints:@[
// Horizontal contraints for |_imageView| and |textStackView|.
_imageWidthConstraint,
[_imageView.leadingAnchor
constraintEqualToAnchor:contentView.leadingAnchor
constant:kTableViewHorizontalSpacing],
[textStackView.leadingAnchor
constraintEqualToAnchor:_imageView.trailingAnchor
constant:kTableViewHorizontalSpacing],
[contentView.trailingAnchor
constraintEqualToAnchor:textStackView.trailingAnchor
constant:kTableViewHorizontalSpacing],
// Vertical contraints for |_imageView| and |textStackView|.
_imageHeightConstraint,
[_imageView.centerYAnchor
constraintEqualToAnchor:contentView.centerYAnchor],
[_imageView.topAnchor
constraintGreaterThanOrEqualToAnchor:contentView.topAnchor
constant:kTableViewLargeVerticalSpacing],
[contentView.bottomAnchor
constraintGreaterThanOrEqualToAnchor:_imageView.bottomAnchor
constant:kTableViewLargeVerticalSpacing],
[textStackView.centerYAnchor
constraintEqualToAnchor:contentView.centerYAnchor],
[textStackView.topAnchor
constraintGreaterThanOrEqualToAnchor:contentView.topAnchor
constant:kTableViewLargeVerticalSpacing],
[contentView.bottomAnchor
constraintGreaterThanOrEqualToAnchor:textStackView.bottomAnchor
constant:kTableViewLargeVerticalSpacing],
]];
}
#pragma mark - UIAccessibility
- (NSString*)accessibilityLabel {
if (self.detailTextLabel.text) {
return [NSString stringWithFormat:@"%@, %@", self.textLabel.text,
self.detailTextLabel.text];
}
return self.textLabel.text;
} }
@end @end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment