Commit 7c1fa752 authored by Sebastien Lalancette's avatar Sebastien Lalancette Committed by Commit Bot

Implemented Compact Height QRGeneratorViewController Layout

Added configuration in ConfirmationAlertViewController which allows
moving the primary action button to the toolbar, and keep showing the
image, when the layout changes to compact height mode.

Also added a way to overwrite the title text size - made it smaller in
the QRGeneratorVC case, as page titles tend to get fairly long.

Bug: 1064990
Change-Id: I7588088b60b64a4cf2953326d666ccb081d2d8b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2161376Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Reviewed-by: default avatarJavier Ernesto Flores Robles <javierrobles@chromium.org>
Commit-Queue: Sebastien Lalancette <seblalancette@chromium.org>
Cr-Commit-Position: refs/heads/master@{#761897}
parent b4f2fba6
......@@ -28,11 +28,16 @@ const CGFloat kQRCodeImageSize = 200.0;
self.image = [self createQRCodeImage];
self.imageHasFixedSize = YES;
self.titleTextStyle = UIFontTextStyleTitle3;
self.subtitleString = [self.pageURL host];
self.primaryActionAvailable = YES;
self.primaryActionString = l10n_util::GetNSString(IDS_IOS_SHARE_BUTTON_LABEL);
self.alwaysShowImage = YES;
self.primaryActionBarButtonStyle = UIBarButtonSystemItemAction;
self.helpButtonAvailable = YES;
[super loadView];
}
......
......@@ -12,6 +12,8 @@ extern NSString* const kConfirmationAlertMoreInfoAccessibilityIdentifier;
extern NSString* const kConfirmationAlertTitleAccessibilityIdentifier;
extern NSString* const kConfirmationAlertSubtitleAccessibilityIdentifier;
extern NSString* const kConfirmationAlertPrimaryActionAccessibilityIdentifier;
extern NSString* const
kConfirmationAlertBarPrimaryActionAccessibilityIdentifier;
@protocol ConfirmationAlertActionHandler;
......@@ -23,6 +25,9 @@ extern NSString* const kConfirmationAlertPrimaryActionAccessibilityIdentifier;
// The headline below the image. Must be set before the view is loaded.
@property(nonatomic, strong) NSString* titleString;
// Text style for the title. If nil, will default to UIFontTextStyleTitle1.
@property(nonatomic, strong) NSString* titleTextStyle;
// The subtitle below the title. Must be set before the view is loaded.
@property(nonatomic, strong) NSString* subtitleString;
......@@ -39,6 +44,14 @@ extern NSString* const kConfirmationAlertPrimaryActionAccessibilityIdentifier;
// Value to determine whether or not the image's size should be scaled.
@property(nonatomic) BOOL imageHasFixedSize;
// Controls if, when we run out of view space, we should hide the action button
// instead of the image.
@property(nonatomic) BOOL alwaysShowImage;
// The style of the primary action button added to the toolbar. Must be set if
// alwaysShowImage is set to YES.
@property(nonatomic) UIBarButtonSystemItem primaryActionBarButtonStyle;
// Controls if there is a help button in the view. Must be set before the
// view is loaded.
@property(nonatomic) BOOL helpButtonAvailable;
......
......@@ -21,6 +21,8 @@ NSString* const kConfirmationAlertSubtitleAccessibilityIdentifier =
@"kConfirmationAlertSubtitleAccessibilityIdentifier";
NSString* const kConfirmationAlertPrimaryActionAccessibilityIdentifier =
@"kConfirmationAlertPrimaryActionAccessibilityIdentifier";
NSString* const kConfirmationAlertBarPrimaryActionAccessibilityIdentifier =
@"kConfirmationAlertBarPrimaryActionAccessibilityIdentifier";
namespace {
......@@ -38,6 +40,9 @@ constexpr CGFloat kSafeAreaMultiplier = 0.8;
// References to the UI properties that need to be updated when the trait
// collection changes.
@property(nonatomic, strong) UIButton* primaryActionButton;
@property(nonatomic, strong) UIToolbar* topToolbar;
@property(nonatomic, strong) NSArray* regularHeightToolbarItems;
@property(nonatomic, strong) NSArray* compactHeightToolbarItems;
@property(nonatomic, strong) UIImageView* imageView;
// Constraints.
@property(nonatomic, strong)
......@@ -45,7 +50,9 @@ constexpr CGFloat kSafeAreaMultiplier = 0.8;
@property(nonatomic, strong)
NSArray<NSLayoutConstraint*>* regularWidthConstraints;
@property(nonatomic, strong)
NSLayoutConstraint* scrollViewBottomVerticalConstraint;
NSLayoutConstraint* regularHeightScrollViewBottomVerticalConstraint;
@property(nonatomic, strong)
NSLayoutConstraint* compactHeightScrollViewBottomVerticalConstraint;
@property(nonatomic, strong)
NSLayoutConstraint* primaryButtonBottomVerticalConstraint;
@end
......@@ -59,8 +66,8 @@ constexpr CGFloat kSafeAreaMultiplier = 0.8;
self.view.backgroundColor = [UIColor colorNamed:kBackgroundColor];
UIToolbar* topToolbar = [self createTopToolbar];
[self.view addSubview:topToolbar];
self.topToolbar = [self createTopToolbar];
[self.view addSubview:self.topToolbar];
self.imageView = [self createImageView];
UILabel* title = [self createTitleLabel];
......@@ -78,7 +85,7 @@ constexpr CGFloat kSafeAreaMultiplier = 0.8;
// Toolbar constraints to the top.
AddSameConstraintsToSides(
topToolbar, self.view.safeAreaLayoutGuide,
self.topToolbar, self.view.safeAreaLayoutGuide,
LayoutSides::kTrailing | LayoutSides::kTop | LayoutSides::kLeading);
// Scroll View constraints to the height of its content. Can be overridden.
......@@ -146,13 +153,26 @@ constexpr CGFloat kSafeAreaMultiplier = 0.8;
self.primaryActionButton = primaryActionButton;
}
self.scrollViewBottomVerticalConstraint = [scrollView.bottomAnchor
constraintLessThanOrEqualToAnchor:scrollViewBottomAnchor];
self.regularHeightScrollViewBottomVerticalConstraint =
[scrollView.bottomAnchor
constraintLessThanOrEqualToAnchor:scrollViewBottomAnchor];
self.compactHeightScrollViewBottomVerticalConstraint =
[scrollView.bottomAnchor
constraintLessThanOrEqualToAnchor:scrollViewBottomAnchor];
if (self.alwaysShowImage && self.primaryActionAvailable) {
// If we always want to show the image, then it means we must hide the
// button when in compact height mode - meaning we have to constraint the
// scrollview's bottom to the safeArea's bottom.
self.compactHeightScrollViewBottomVerticalConstraint =
[scrollView.bottomAnchor
constraintLessThanOrEqualToAnchor:self.view.safeAreaLayoutGuide
.bottomAnchor];
}
[NSLayoutConstraint activateConstraints:@[
[scrollView.topAnchor
constraintGreaterThanOrEqualToAnchor:topToolbar.bottomAnchor],
self.scrollViewBottomVerticalConstraint,
constraintGreaterThanOrEqualToAnchor:self.topToolbar.bottomAnchor],
]];
if (!self.imageHasFixedSize) {
......@@ -213,7 +233,6 @@ constexpr CGFloat kSafeAreaMultiplier = 0.8;
- (void)updateViewConstraints {
CGFloat marginValue =
self.view.layoutMargins.left - self.view.safeAreaInsets.left;
self.scrollViewBottomVerticalConstraint.constant = -marginValue;
self.primaryButtonBottomVerticalConstraint.constant = -marginValue;
if (self.traitCollection.horizontalSizeClass ==
UIUserInterfaceSizeClassCompact) {
......@@ -223,8 +242,33 @@ constexpr CGFloat kSafeAreaMultiplier = 0.8;
[NSLayoutConstraint deactivateConstraints:self.compactWidthConstraints];
[NSLayoutConstraint activateConstraints:self.regularWidthConstraints];
}
self.imageView.hidden =
BOOL isVerticalCompact =
self.traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact;
NSLayoutConstraint* oldBottomConstraint;
NSLayoutConstraint* newBottomConstraint;
if (isVerticalCompact) {
oldBottomConstraint = self.regularHeightScrollViewBottomVerticalConstraint;
newBottomConstraint = self.compactHeightScrollViewBottomVerticalConstraint;
self.topToolbar.items = self.compactHeightToolbarItems;
} else {
oldBottomConstraint = self.compactHeightScrollViewBottomVerticalConstraint;
newBottomConstraint = self.regularHeightScrollViewBottomVerticalConstraint;
self.topToolbar.items = self.regularHeightToolbarItems;
}
newBottomConstraint.constant = -marginValue;
[NSLayoutConstraint deactivateConstraints:@[ oldBottomConstraint ]];
[NSLayoutConstraint activateConstraints:@[ newBottomConstraint ]];
if (self.alwaysShowImage) {
// Update the primary action button visibility.
[self.primaryActionButton setHidden:isVerticalCompact];
} else {
[self.imageView setHidden:isVerticalCompact];
}
[super updateViewConstraints];
}
......@@ -259,34 +303,65 @@ constexpr CGFloat kSafeAreaMultiplier = 0.8;
forToolbarPosition:UIBarPositionAny];
[topToolbar setBarTintColor:[UIColor colorNamed:kBackgroundColor]];
topToolbar.delegate = self;
NSMutableArray* items = [[NSMutableArray alloc] init];
NSMutableArray* regularHeightItems = [[NSMutableArray alloc] init];
NSMutableArray* compactHeightItems = [[NSMutableArray alloc] init];
if (self.helpButtonAvailable) {
UIBarButtonItem* helpButton = [[UIBarButtonItem alloc]
initWithImage:[UIImage imageNamed:@"confirmation_alert_ic_help"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(didTapHelpButton)];
[items addObject:helpButton];
[regularHeightItems addObject:helpButton];
[compactHeightItems addObject:helpButton];
helpButton.accessibilityIdentifier =
kConfirmationAlertMoreInfoAccessibilityIdentifier;
// Set the help button as the left button item so it can be used as a
// popover anchor.
_helpButton = helpButton;
}
if (self.alwaysShowImage && self.primaryActionAvailable) {
if (self.helpButtonAvailable) {
// Add margin with help button.
UIBarButtonItem* fixedSpacer = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil
action:nil];
fixedSpacer.width = 15.0f;
[compactHeightItems addObject:fixedSpacer];
}
UIBarButtonItem* primaryActionBarButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:self.primaryActionBarButtonStyle
target:self
action:@selector(didTapPrimaryActionButton)];
primaryActionBarButton.accessibilityIdentifier =
kConfirmationAlertBarPrimaryActionAccessibilityIdentifier;
// Only shows up in constraint height mode.
[compactHeightItems addObject:primaryActionBarButton];
}
UIBarButtonItem* spacer = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
[items addObject:spacer];
[regularHeightItems addObject:spacer];
[compactHeightItems addObject:spacer];
UIBarButtonItem* doneButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:@selector(didTapDoneButton)];
[items addObject:doneButton];
[regularHeightItems addObject:doneButton];
[compactHeightItems addObject:doneButton];
topToolbar.items = items;
topToolbar.translatesAutoresizingMaskIntoConstraints = NO;
self.regularHeightToolbarItems = regularHeightItems;
self.compactHeightToolbarItems = compactHeightItems;
return topToolbar;
}
......@@ -300,14 +375,17 @@ constexpr CGFloat kSafeAreaMultiplier = 0.8;
// Helper to create the title label.
- (UILabel*)createTitleLabel {
if (!self.titleTextStyle) {
self.titleTextStyle = UIFontTextStyleTitle1;
}
UILabel* title = [[UILabel alloc] init];
title.numberOfLines = 0;
UIFontDescriptor* descriptor = [UIFontDescriptor
preferredFontDescriptorWithTextStyle:UIFontTextStyleTitle1];
preferredFontDescriptorWithTextStyle:self.titleTextStyle];
UIFont* font = [UIFont systemFontOfSize:descriptor.pointSize
weight:UIFontWeightBold];
UIFontMetrics* fontMetrics =
[UIFontMetrics metricsForTextStyle:UIFontTextStyleTitle1];
[UIFontMetrics metricsForTextStyle:self.titleTextStyle];
title.font = [fontMetrics scaledFontForFont:font];
title.textColor = [UIColor colorNamed:kTextPrimaryColor];
title.text = self.titleString.capitalizedString;
......
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