Commit e6842e2e authored by David Jean's avatar David Jean Committed by Commit Bot

[ios] make manual fallback action cells full width

Also allow them to be disabled to be used as message cells.

Change-Id: I545a0849fa4656e1959c8f01ad456e2b0a52cd78
Reviewed-on: https://chromium-review.googlesource.com/c/1350618
Commit-Queue: David Jean <djean@chromium.org>
Reviewed-by: default avatarJavier Ernesto Flores Robles <javierrobles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611122}
parent 377a0f0f
......@@ -17,6 +17,9 @@
- (instancetype)initWithType:(NSInteger)type NS_UNAVAILABLE;
// Set enable to NO to create a message line cell.
@property(nonatomic, assign) BOOL enabled;
@end
// A table view cell which contains a button and holds an action block, which
......@@ -25,7 +28,8 @@
// Updates the cell with the passed title and action block.
- (void)setUpWithTitle:(NSString*)title
accessibilityID:(NSString*)accessibilityID
action:(void (^)(void))action;
action:(void (^)(void))action
enabled:(BOOL)enabled;
@end
......
......@@ -4,6 +4,7 @@
#import "ios/chrome/browser/ui/autofill/manual_fill/action_cell.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_cell_utils.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/uicolor_manualfill.h"
#import "ios/chrome/browser/ui/list_model/list_model.h"
#import "ios/chrome/common/ui_util/constraints_ui_util.h"
......@@ -13,19 +14,23 @@
#endif
namespace {
// Left and right margins of the cell contents.
static const CGFloat sideMargins = 16;
// The multiplier for the base system spacing at the top margin.
static const CGFloat TopBaseSystemSpacingMultiplier = 1.1;
// The multiplier for the base system spacing at the bottom margin.
static const CGFloat BottomBaseSystemSpacingMultiplier = 1.5;
} // namespace
@interface ManualFillActionItem ()
// The action block to be called when the user taps the title.
@property(nonatomic, copy, readonly) void (^action)(void);
// The title for the action.
@property(nonatomic, copy, readonly) NSString* title;
@end
@implementation ManualFillActionItem
......@@ -35,6 +40,7 @@ static const CGFloat BottomBaseSystemSpacingMultiplier = 1.5;
if (self) {
_title = [title copy];
_action = [action copy];
_enabled = YES;
self.cellClass = [ManualFillActionCell class];
}
return self;
......@@ -46,7 +52,8 @@ static const CGFloat BottomBaseSystemSpacingMultiplier = 1.5;
cell.accessibilityIdentifier = nil;
[cell setUpWithTitle:self.title
accessibilityID:self.accessibilityIdentifier
action:self.action];
action:self.action
enabled:self.enabled];
}
@end
......@@ -59,8 +66,6 @@ static const CGFloat BottomBaseSystemSpacingMultiplier = 1.5;
@end
@implementation ManualFillActionCell
@synthesize action = _action;
@synthesize titleButton = _titleButton;
#pragma mark - Public
......@@ -69,17 +74,26 @@ static const CGFloat BottomBaseSystemSpacingMultiplier = 1.5;
self.action = nil;
[self.titleButton setTitle:nil forState:UIControlStateNormal];
self.titleButton.accessibilityIdentifier = nil;
[self.titleButton setTitleColor:UIColor.cr_manualFillTintColor
forState:UIControlStateNormal];
self.titleButton.enabled = YES;
}
- (void)setUpWithTitle:(NSString*)title
accessibilityID:(NSString*)accessibilityID
action:(void (^)(void))action {
action:(void (^)(void))action
enabled:(BOOL)enabled {
if (self.contentView.subviews.count == 0) {
[self createView];
}
[self.titleButton setTitle:title forState:UIControlStateNormal];
self.titleButton.accessibilityIdentifier = accessibilityID;
self.titleButton.enabled = enabled;
if (!enabled) {
[self.titleButton setTitleColor:UIColor.lightGrayColor
forState:UIControlStateNormal];
}
self.action = action;
}
......@@ -88,45 +102,17 @@ static const CGFloat BottomBaseSystemSpacingMultiplier = 1.5;
- (void)createView {
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.titleButton = [UIButton buttonWithType:UIButtonTypeSystem];
[self.titleButton setTitleColor:UIColor.cr_manualFillTintColor
forState:UIControlStateNormal];
self.titleButton.translatesAutoresizingMaskIntoConstraints = NO;
self.titleButton.titleLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleBody];
self.titleButton.titleLabel.adjustsFontForContentSizeCategory = YES;
[self.titleButton addTarget:self
action:@selector(userDidTapTitleButton:)
forControlEvents:UIControlEventTouchUpInside];
UIView* guide = self.contentView;
self.titleButton = CreateButtonWithSelectorAndTarget(
@selector(userDidTapTitleButton:), self);
self.titleButton.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
[self.contentView addSubview:self.titleButton];
id<LayoutGuideProvider> safeArea = self.contentView.safeAreaLayoutGuide;
NSArray* verticalConstraints;
// Multipliers of these constraints are calculated based on a 24 base
// system spacing.
verticalConstraints = @[
// Vertical constraints.
[self.titleButton.firstBaselineAnchor
constraintEqualToSystemSpacingBelowAnchor:self.contentView.topAnchor
multiplier:
TopBaseSystemSpacingMultiplier],
[self.contentView.bottomAnchor
constraintEqualToSystemSpacingBelowAnchor:self.titleButton
.lastBaselineAnchor
multiplier:
BottomBaseSystemSpacingMultiplier],
];
[NSLayoutConstraint activateConstraints:verticalConstraints];
// Horizontal constraints.
[NSLayoutConstraint activateConstraints:@[
[self.titleButton.leadingAnchor
constraintEqualToAnchor:safeArea.leadingAnchor
constant:sideMargins],
[safeArea.trailingAnchor
constraintGreaterThanOrEqualToAnchor:self.titleButton.trailingAnchor
constant:sideMargins],
]];
HorizontalConstraintsForViewsOnGuideWithShift(@[ self.titleButton ], guide,
0);
VerticalConstraintsSpacingForViewsInContainerWithMultipliers(
@[ self.titleButton ], self.contentView, TopBaseSystemSpacingMultiplier,
0, BottomBaseSystemSpacingMultiplier);
}
- (void)userDidTapTitleButton:(UIButton*)sender {
......
......@@ -113,6 +113,8 @@ static const CGFloat NoMultiplier = 1.0;
self.siteNameLabel.text = @"";
[self.usernameButton setTitle:@"" forState:UIControlStateNormal];
self.usernameButton.enabled = YES;
[self.usernameButton setTitleColor:UIColor.cr_manualFillTintColor
forState:UIControlStateNormal];
[self.passwordButton setTitle:@"" forState:UIControlStateNormal];
self.manualFillCredential = nil;
}
......
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