Commit fcae9f69 authored by sczs's avatar sczs Committed by Commit Bot

[ios] Creates Infobar Banner Open Modal button.

This CL creates an Open Modal button which will be tapped to display the Modal,
it also stops adding the Infobar icon of there's not one, and makes some
small UI tweaks overall.

Adds showcase testing.

Screenshot:
https://drive.google.com/open?id=1uEkE3O1spb0YrETXGu1Gdkk1TEJIN6yw

Bug: 961343
Change-Id: I4fbfbca8427a70d4cdf659397303a0c384da1f3e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1818610Reviewed-by: default avatarPeter Lee <pkl@chromium.org>
Reviewed-by: default avatarChris Lu <thegreenfrog@chromium.org>
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699799}
parent f19ff775
......@@ -11,5 +11,7 @@
extern NSString* const kInfobarBannerViewIdentifier;
// Accessibility identifier of the Banner Accept Button.
extern NSString* const kInfobarBannerAcceptButtonIdentifier;
// Accessibility identifier of the Banner Open Modal Button.
extern NSString* const kInfobarBannerOpenModalButtonIdentifier;
#endif // IOS_CHROME_BROWSER_UI_INFOBARS_BANNERS_INFOBAR_BANNER_CONSTANTS_H_
......@@ -11,3 +11,5 @@
NSString* const kInfobarBannerViewIdentifier = @"kInfobarBannerViewIdentifier";
NSString* const kInfobarBannerAcceptButtonIdentifier =
@"kInfobarBannerAcceptButtonIdentifier";
NSString* const kInfobarBannerOpenModalButtonIdentifier =
@"kInfobarBannerOpenModalButtonIdentifier";
......@@ -38,8 +38,9 @@ const CGFloat kButtonSeparatorWidth = 1.0;
const CGFloat kButtonMaxFontSize = 45;
// Container Stack constants.
const CGFloat kContainerStackSpacing = 18.0;
const CGFloat kContainerStackSpacing = 10.0;
const CGFloat kContainerStackVerticalPadding = 18.0;
const CGFloat kContainerStackHorizontalPadding = 18.0;
// Icon constants.
const CGFloat kIconWidth = 25.0;
......@@ -124,11 +125,13 @@ const CGFloat kLongPressTimeDurationInSeconds = 0.4;
self.view.accessibilityCustomActions = [self accessibilityActions];
// Icon setup.
self.iconImage = [self.iconImage
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UIImageView* iconImageView =
[[UIImageView alloc] initWithImage:self.iconImage];
iconImageView.contentMode = UIViewContentModeScaleAspectFit;
UIImageView* iconImageView = nil;
if (self.iconImage) {
self.iconImage = [self.iconImage
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
iconImageView = [[UIImageView alloc] initWithImage:self.iconImage];
iconImageView.contentMode = UIViewContentModeScaleAspectFit;
}
// Labels setup.
self.titleLabel = [[UILabel alloc] init];
......@@ -161,6 +164,8 @@ const CGFloat kLongPressTimeDurationInSeconds = 0.4;
scaledFontForFont:[UIFont
preferredFontForTextStyle:UIFontTextStyleHeadline]
maximumPointSize:kButtonMaxFontSize];
self.infobarButton.titleLabel.numberOfLines = 0;
self.infobarButton.titleLabel.textAlignment = NSTextAlignmentCenter;
[self.infobarButton addTarget:self
action:@selector(bannerInfobarButtonWasPressed:)
forControlEvents:UIControlEventTouchUpInside];
......@@ -173,9 +178,36 @@ const CGFloat kLongPressTimeDurationInSeconds = 0.4;
[self.infobarButton addSubview:buttonSeparator];
// Container Stack setup.
UIStackView* containerStack = [[UIStackView alloc] initWithArrangedSubviews:@[
iconImageView, labelsStackView, self.infobarButton
]];
UIStackView* containerStack = [[UIStackView alloc] init];
// Check if it should have an icon.
if (iconImageView) {
[containerStack addArrangedSubview:iconImageView];
[iconImageView.widthAnchor constraintEqualToConstant:kIconWidth].active =
YES;
}
// Add labels.
[containerStack addArrangedSubview:labelsStackView];
// Check if it should have an Open Modal button.
if (self.presentsModal) {
// Open Modal Button setup.
UIButton* openModalButton = [UIButton buttonWithType:UIButtonTypeSystem];
UIImage* gearImage = [[UIImage imageNamed:@"infobar_settings_icon"]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[openModalButton setImage:gearImage forState:UIControlStateNormal];
openModalButton.tintColor = [UIColor colorNamed:kTextSecondaryColor];
[openModalButton addTarget:self
action:@selector(animateBannerTappedAndPresentModal)
forControlEvents:UIControlEventTouchUpInside];
[openModalButton
setContentHuggingPriority:UILayoutPriorityDefaultHigh
forAxis:UILayoutConstraintAxisHorizontal];
openModalButton.accessibilityIdentifier =
kInfobarBannerOpenModalButtonIdentifier;
[containerStack addArrangedSubview:openModalButton];
}
// Add accept button.
[containerStack addArrangedSubview:self.infobarButton];
// Configure it.
containerStack.axis = UILayoutConstraintAxisHorizontal;
containerStack.spacing = kContainerStackSpacing;
containerStack.distribution = UIStackViewDistributionFill;
......@@ -192,14 +224,12 @@ const CGFloat kLongPressTimeDurationInSeconds = 0.4;
// Container Stack.
[containerStack.leadingAnchor
constraintEqualToAnchor:self.view.leadingAnchor
constant:kContainerStackSpacing],
constant:kContainerStackHorizontalPadding],
[containerStack.trailingAnchor
constraintEqualToAnchor:self.view.trailingAnchor],
[containerStack.topAnchor constraintEqualToAnchor:self.view.topAnchor],
[containerStack.bottomAnchor
constraintEqualToAnchor:self.view.bottomAnchor],
// Icon.
[iconImageView.widthAnchor constraintEqualToConstant:kIconWidth],
// Button.
[self.infobarButton.widthAnchor constraintEqualToConstant:kButtonWidth],
[buttonSeparator.widthAnchor
......@@ -224,14 +254,6 @@ const CGFloat kLongPressTimeDurationInSeconds = 0.4;
longPressGestureRecognizer.minimumPressDuration =
kLongPressTimeDurationInSeconds;
[self.view addGestureRecognizer:longPressGestureRecognizer];
if (self.presentsModal) {
UITapGestureRecognizer* tapGestureRecognizer =
[[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(animateBannerTappedAndPresentModal)];
[self.view addGestureRecognizer:tapGestureRecognizer];
}
}
- (void)viewDidAppear:(BOOL)animated {
......
......@@ -73,7 +73,7 @@ using ::showcase_utils::Close;
assertWithMatcher:grey_nil()];
}
// Tests that the InfobarBanner is dismissed correctly when its swiped up.
// Tests that the InfobarBanner is dismissed correctly when is swiped up.
- (void)testInfobarBannerDismissSwipe {
// Check Banner was presented.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
......@@ -89,7 +89,7 @@ using ::showcase_utils::Close;
assertWithMatcher:grey_nil()];
}
// Tests that the InfobarModal is not presented when the Banner its swiped down.
// Tests that the InfobarModal is not presented when the Banner is swiped down.
- (void)testInfobarBannerCantSwipeDown {
// Check Banner was presented.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
......@@ -113,7 +113,7 @@ using ::showcase_utils::Close;
assertWithMatcher:grey_nil()];
}
// Tests that the InfobarModal is presented when the Banner its tapped.
// Tests that the InfobarModal is not presented when the Banner is tapped.
- (void)testInfobarBannerTapped {
// Check Banner was presented.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
......@@ -123,6 +123,32 @@ using ::showcase_utils::Close;
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kInfobarBannerViewIdentifier)]
performAction:grey_tap()];
// Check the Modal is not presented.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kInfobarBannerPresentedModalLabel)]
assertWithMatcher:grey_nil()];
// Check the banner is still interactable by swiping it up.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kInfobarBannerViewIdentifier)]
performAction:grey_swipeFastInDirection(kGREYDirectionUp)];
// Check Banner was dismissed.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kInfobarBannerViewIdentifier)]
assertWithMatcher:grey_nil()];
}
// Tests that the InfobarModal is presented when the Open Modal button is
// tapped.
- (void)testInfobarBannerGearTapped {
// Check Banner was presented.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kInfobarBannerViewIdentifier)]
assertWithMatcher:grey_notNil()];
// Tap Gear Button.
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kInfobarBannerOpenModalButtonIdentifier)]
performAction:grey_tap()];
// Check Modal was presented.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kInfobarBannerPresentedModalLabel)]
......
......@@ -73,7 +73,7 @@ using ::showcase_utils::Close;
assertWithMatcher:grey_nil()];
}
// Tests that the InfobarBanner is dismissed correctly when its swiped up.
// Tests that the InfobarBanner is dismissed correctly when is swiped up.
- (void)testInfobarBannerDismissSwipe {
// Check Banner was presented.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
......@@ -89,7 +89,7 @@ using ::showcase_utils::Close;
assertWithMatcher:grey_nil()];
}
// Tests that the InfobarModal is not presented when the Banner its swiped down.
// Tests that the InfobarModal is not presented when the Banner is swiped down.
- (void)testInfobarBannerCantSwipeDown {
// Check Banner was presented.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
......@@ -113,7 +113,7 @@ using ::showcase_utils::Close;
assertWithMatcher:grey_nil()];
}
// Tests that the InfobarModal is not presented when the Banner its tapped.
// Tests that the InfobarModal is not presented when the Banner is tapped.
- (void)testInfobarBannerTapped {
// Check Banner was presented.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
......@@ -137,4 +137,22 @@ using ::showcase_utils::Close;
assertWithMatcher:grey_nil()];
}
// Tests that there's no Infobar Open Modal button. Banners that don't present a
// Modal shouldn't have one.
- (void)testInfobarBannerNoGear {
// Check Banner was presented.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kInfobarBannerViewIdentifier)]
assertWithMatcher:grey_notNil()];
// Check Gear Button is not present.
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kInfobarBannerOpenModalButtonIdentifier)]
assertWithMatcher:grey_nil()];
// Dismiss banner.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kInfobarBannerViewIdentifier)]
performAction:grey_swipeFastInDirection(kGREYDirectionUp)];
}
@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