Commit bfbf0374 authored by Moe Ahmadi's avatar Moe Ahmadi Committed by Commit Bot

[AF][IOS] Fixes the GooglePay logo animation in the FormSuggestionView

After crrev.com/c/1078871 that updated FormSuggestionView and
FormSuggestionLabel to use AutoLayout, the Google Pay logo stopped
animating. This CL fixes that regression and also changes the code
slightly so that the subviews are more lazily created.

Bug: 852890
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I5388a3c4a7df2819e14b5772368e07f16c98564e
Reviewed-on: https://chromium-review.googlesource.com/1101543
Commit-Queue: Moe Ahmadi <mahmadi@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567997}
parent b142a563
...@@ -28,9 +28,19 @@ const CGFloat kSuggestionHorizontalMargin = 6; ...@@ -28,9 +28,19 @@ const CGFloat kSuggestionHorizontalMargin = 6;
} // namespace } // namespace
@interface FormSuggestionView ()
// Creates and adds subviews.
- (void)setupSubviews;
@end
@implementation FormSuggestionView { @implementation FormSuggestionView {
// The FormSuggestions that are displayed by this view. // The FormSuggestions that are displayed by this view.
NSArray* _suggestions; NSArray* _suggestions;
// Handles user interactions.
id<FormSuggestionViewClient> _client;
} }
- (instancetype)initWithFrame:(CGRect)frame - (instancetype)initWithFrame:(CGRect)frame
...@@ -38,8 +48,25 @@ const CGFloat kSuggestionHorizontalMargin = 6; ...@@ -38,8 +48,25 @@ const CGFloat kSuggestionHorizontalMargin = 6;
suggestions:(NSArray*)suggestions { suggestions:(NSArray*)suggestions {
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
if (self) { if (self) {
_client = client;
_suggestions = [suggestions copy]; _suggestions = [suggestions copy];
}
return self;
}
#pragma mark - UIView
- (void)willMoveToSuperview:(UIView*)newSuperview {
// Create and add subviews the first time this moves to a superview.
if (newSuperview && self.subviews.count == 0) {
[self setupSubviews];
}
[super willMoveToSuperview:newSuperview];
}
#pragma mark - Helper methods
- (void)setupSubviews {
self.showsVerticalScrollIndicator = NO; self.showsVerticalScrollIndicator = NO;
self.showsHorizontalScrollIndicator = NO; self.showsHorizontalScrollIndicator = NO;
self.bounces = NO; self.bounces = NO;
...@@ -48,42 +75,36 @@ const CGFloat kSuggestionHorizontalMargin = 6; ...@@ -48,42 +75,36 @@ const CGFloat kSuggestionHorizontalMargin = 6;
UIStackView* stackView = [[UIStackView alloc] initWithArrangedSubviews:@[]]; UIStackView* stackView = [[UIStackView alloc] initWithArrangedSubviews:@[]];
stackView.axis = UILayoutConstraintAxisHorizontal; stackView.axis = UILayoutConstraintAxisHorizontal;
stackView.layoutMarginsRelativeArrangement = YES; stackView.layoutMarginsRelativeArrangement = YES;
stackView.layoutMargins = UIEdgeInsetsMake( stackView.layoutMargins =
kSuggestionVerticalMargin, kSuggestionHorizontalMargin, UIEdgeInsetsMake(kSuggestionVerticalMargin, kSuggestionHorizontalMargin,
kSuggestionVerticalMargin, kSuggestionHorizontalMargin); kSuggestionVerticalMargin, kSuggestionHorizontalMargin);
stackView.spacing = kSuggestionHorizontalMargin; stackView.spacing = kSuggestionHorizontalMargin;
stackView.translatesAutoresizingMaskIntoConstraints = NO; stackView.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:stackView]; [self addSubview:stackView];
AddSameConstraints(stackView, self);
[stackView.heightAnchor constraintEqualToAnchor:self.heightAnchor].active =
true;
void (^setupBlock)(FormSuggestion* suggestion, NSUInteger idx, BOOL* stop) = auto setupBlock = ^(FormSuggestion* suggestion, NSUInteger idx, BOOL* stop) {
^(FormSuggestion* suggestion, NSUInteger idx, BOOL* stop) { // Disable user interaction with suggestion if it is Google Pay logo.
BOOL userInteractionEnabled = BOOL userInteractionEnabled =
suggestion.identifier != suggestion.identifier != autofill::POPUP_ITEM_ID_GOOGLE_PAY_BRANDING;
autofill::POPUP_ITEM_ID_GOOGLE_PAY_BRANDING;
UIView* label = [[FormSuggestionLabel alloc] UIView* label =
initWithSuggestion:suggestion [[FormSuggestionLabel alloc] initWithSuggestion:suggestion
index:idx index:idx
userInteractionEnabled:userInteractionEnabled userInteractionEnabled:userInteractionEnabled
numSuggestions:[_suggestions count] numSuggestions:[_suggestions count]
client:client]; client:_client];
[stackView addArrangedSubview:label]; [stackView addArrangedSubview:label];
};
[_suggestions enumerateObjectsUsingBlock:setupBlock];
AddSameConstraints(stackView, self);
[stackView.heightAnchor constraintEqualToAnchor:self.heightAnchor].active =
true;
}
return self;
}
- (void)willMoveToSuperview:(UIView*)newSuperview { // If first suggestion is Google Pay logo animate it below the fold.
FormSuggestion* firstSuggestion = [_suggestions firstObject]; if (idx == 0U &&
if (firstSuggestion.identifier == suggestion.identifier == autofill::POPUP_ITEM_ID_GOOGLE_PAY_BRANDING) {
autofill::POPUP_ITEM_ID_GOOGLE_PAY_BRANDING) {
UIView* firstLabel = [self.subviews firstObject];
DCHECK(firstLabel);
const CGFloat firstLabelWidth = const CGFloat firstLabelWidth =
CGRectGetWidth([firstLabel frame]) + kSuggestionHorizontalMargin; [label systemLayoutSizeFittingSize:UILayoutFittingCompressedSize]
.width +
kSuggestionHorizontalMargin;
dispatch_time_t popTime = dispatch_time_t popTime =
dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC); dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC);
__weak FormSuggestionView* weakSelf = self; __weak FormSuggestionView* weakSelf = self;
...@@ -93,7 +114,8 @@ const CGFloat kSuggestionHorizontalMargin = 6; ...@@ -93,7 +114,8 @@ const CGFloat kSuggestionHorizontalMargin = 6;
animated:YES]; animated:YES];
}); });
} }
[super willMoveToSuperview:newSuperview]; };
[_suggestions enumerateObjectsUsingBlock:setupBlock];
} }
- (NSArray*)suggestions { - (NSArray*)suggestions {
......
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