Commit 05eba098 authored by Javier Ernesto Flores Robles's avatar Javier Ernesto Flores Robles Committed by Commit Bot

[iOS][MF] Creates action table view cell

Creates a new UITableViewCell to show user credentials in a table view.
The design is according to the specs for Manual Fallback, which can be
found in:
https://folio.googleplex.com/ntp/Autofill/Autofill%20Manual%20Fallback

Bug: 845472
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Iaa916c36dfb9ca2a567c904c4ab536b037840077
Reviewed-on: https://chromium-review.googlesource.com/1179756
Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584691}
parent 6cc2805b
// 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_AUTOFILL_MANUAL_FILL_ACTION_CELL_H_
#define IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_ACTION_CELL_H_
#import <UIKit/UIKit.h>
// A table view cell which contains a button and holds an action block, which
// is called when the button is touched.
@interface ManualFillActionCell : UITableViewCell
// Updates the cell with the passed title and action block.
- (void)setUpWithTitle:(NSString*)title action:(void (^)(void))action;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_ACTION_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/autofill/manual_fill/action_cell.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/uicolor_manualfill.h"
#import "ios/chrome/common/ui_util/constraints_ui_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Left and right margins of the cell contents.
static const CGFloat sideMargins = 16;
// The base multiplier for the top and bottom margins. This number multiplied
// by the font size plus the base margins will give similar results to
// |constraintEqualToSystemSpacingBelowAnchor:|.
static const CGFloat iOS10MarginFontMultiplier = 1.18;
// The base top margin, only used in iOS 10. Refer to
// |iOS10MarginFontMultiplier| for how it is used.
static const CGFloat iOS10BaseTopMargin = 24;
// The base bottom margin, only used in iOS 10. Refer to
// |iOS10MarginFontMultiplier| for how it is used.
static const CGFloat iOS10BaseBottomMargin = 6;
// The multiplier for the base system spacing at the top margin.
static const CGFloat TopBaseSystemSpacingMultiplier = 1.78;
// The multiplier for the base system spacing at the bottom margin.
static const CGFloat BottomBaseSystemSpacingMultiplier = 2.26;
} // namespace
@interface ManualFillActionCell ()
// The action block to be called when the user taps the title button.
@property(nonatomic, copy) void (^action)(void);
// The title button of this cell.
@property(nonatomic, strong) UIButton* titleButton;
@end
@implementation ManualFillActionCell
@synthesize action = _action;
@synthesize titleButton = _titleButton;
#pragma mark - Public
- (void)setUpWithTitle:(NSString*)title action:(void (^)(void))action {
if (self.contentView.subviews.count == 0) {
[self createView];
}
[self.titleButton setTitle:title forState:UIControlStateNormal];
self.action = action;
}
- (void)prepareForReuse {
[super prepareForReuse];
self.action = nil;
}
#pragma mark - Private
- (void)createView {
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.titleButton = [[UIButton alloc] init];
[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];
self.titleButton.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
[self.contentView addSubview:self.titleButton];
id<LayoutGuideProvider> safeArea =
SafeAreaLayoutGuideForView(self.contentView);
NSArray* verticalConstraints;
if (@available(iOS 11, *)) {
// 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],
];
} else {
CGFloat pointSize = self.titleButton.titleLabel.font.pointSize;
// These margins are based on the design size and the current point size.
// The multipliers were selected by manually testing the different system
// font sizes.
CGFloat marginTop =
iOS10BaseTopMargin + pointSize * iOS10MarginFontMultiplier;
CGFloat marginBottom =
iOS10BaseBottomMargin + pointSize * iOS10MarginFontMultiplier;
verticalConstraints = @[
[self.titleButton.firstBaselineAnchor
constraintEqualToAnchor:self.contentView.topAnchor
constant:marginTop],
[self.contentView.bottomAnchor
constraintEqualToAnchor:self.titleButton.lastBaselineAnchor
constant:marginBottom],
];
}
[NSLayoutConstraint activateConstraints:verticalConstraints];
// Horizontal constraints.
[NSLayoutConstraint activateConstraints:@[
[self.titleButton.leadingAnchor
constraintEqualToAnchor:safeArea.leadingAnchor
constant:sideMargins],
[safeArea.trailingAnchor
constraintGreaterThanOrEqualToAnchor:self.titleButton.trailingAnchor
constant:sideMargins],
]];
}
- (void)userDidTapTitleButton:(UIButton*)sender {
if (self.action) {
self.action();
}
}
@end
// 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_AUTOFILL_MANUAL_FILL_UICOLOR_MANUALFILL_H_
#define IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_UICOLOR_MANUALFILL_H_
#import <UIKit/UIKit.h>
@interface UIColor (ManualFill)
// Color to set in interactable elements for manual fill (0.1, 0.45, 0.91 RGB).
@property(class, nonatomic, readonly) UIColor* cr_manualFillTintColor;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_UICOLOR_MANUALFILL_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/autofill/manual_fill/uicolor_manualfill.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation UIColor (ManualFill)
+ (UIColor*)cr_manualFillTintColor {
static UIColor* color =
[UIColor colorWithRed:0.10 green:0.45 blue:0.91 alpha:1.0];
return color;
}
@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