Commit 30956fc7 authored by Javier Ernesto Flores Robles's avatar Javier Ernesto Flores Robles Committed by Commit Bot

[iOS][MF] Enable pull to reset

Similar to pull to refresh, pulling the suggestions to the right will
reset the keyboard and the manual fallback view.

Video: https://drive.google.com/file/d/1QpoiU3YPXdFhLQ_ubzZcyJ7VxVo86Zpv/view?usp=sharing

Bug: 845472, 911142
Change-Id: Ie13322d168dac81288d95a8e10a0bcb5bab59339
Reviewed-on: https://chromium-review.googlesource.com/c/1355188
Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avatarOlivier Robin <olivierrobin@chromium.org>
Reviewed-by: default avatarBrian White <bcwhite@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613169}
parent fc1ceed4
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "components/autofill/core/common/autofill_features.h" #include "components/autofill/core/common/autofill_features.h"
#import "ios/chrome/browser/autofill/form_input_accessory_view.h" #import "ios/chrome/browser/autofill/form_input_accessory_view.h"
#import "ios/chrome/browser/autofill/form_suggestion_view.h" #import "ios/chrome/browser/autofill/form_suggestion_view.h"
...@@ -23,6 +24,7 @@ CGFloat const kInputAccessoryHeight = 44.0f; ...@@ -23,6 +24,7 @@ CGFloat const kInputAccessoryHeight = 44.0f;
} // namespace autofill } // namespace autofill
@interface FormInputAccessoryViewController () < @interface FormInputAccessoryViewController () <
FormSuggestionViewDelegate,
ManualFillAccessoryViewControllerDelegate> ManualFillAccessoryViewControllerDelegate>
// Grey view used as the background of the keyboard to fix // Grey view used as the background of the keyboard to fix
...@@ -133,7 +135,7 @@ CGFloat const kInputAccessoryHeight = 44.0f; ...@@ -133,7 +135,7 @@ CGFloat const kInputAccessoryHeight = 44.0f;
} }
- (void)unlockManualFallbackView { - (void)unlockManualFallbackView {
[self.formSuggestionView unlockTrailingView]; [self.formSuggestionView resetContentInsetAndDelegate];
} }
- (void)lockManualFallbackView { - (void)lockManualFallbackView {
...@@ -141,7 +143,7 @@ CGFloat const kInputAccessoryHeight = 44.0f; ...@@ -141,7 +143,7 @@ CGFloat const kInputAccessoryHeight = 44.0f;
} }
- (void)resetManualFallbackIcons { - (void)resetManualFallbackIcons {
[self.manualFillAccessoryViewController reset]; [self.manualFillAccessoryViewController resetAnimated:YES];
} }
#pragma mark - FormInputAccessoryConsumer #pragma mark - FormInputAccessoryConsumer
...@@ -178,6 +180,7 @@ CGFloat const kInputAccessoryHeight = 44.0f; ...@@ -178,6 +180,7 @@ CGFloat const kInputAccessoryHeight = 44.0f;
// Create the views if they don't exist already. // Create the views if they don't exist already.
if (!self.formSuggestionView) { if (!self.formSuggestionView) {
self.formSuggestionView = [[FormSuggestionView alloc] init]; self.formSuggestionView = [[FormSuggestionView alloc] init];
self.formSuggestionView.formSuggestionViewDelegate = self;
} }
[self.formSuggestionView updateClient:suggestionClient [self.formSuggestionView updateClient:suggestionClient
...@@ -209,7 +212,7 @@ CGFloat const kInputAccessoryHeight = 44.0f; ...@@ -209,7 +212,7 @@ CGFloat const kInputAccessoryHeight = 44.0f;
} }
- (void)restoreOriginalKeyboardView { - (void)restoreOriginalKeyboardView {
[self.manualFillAccessoryViewController reset]; [self.manualFillAccessoryViewController resetAnimated:NO];
[self removeCustomInputAccessoryView]; [self removeCustomInputAccessoryView];
[self.keyboardReplacementView removeFromSuperview]; [self.keyboardReplacementView removeFromSuperview];
self.keyboardReplacementView = nil; self.keyboardReplacementView = nil;
...@@ -430,4 +433,15 @@ CGFloat const kInputAccessoryHeight = 44.0f; ...@@ -430,4 +433,15 @@ CGFloat const kInputAccessoryHeight = 44.0f;
[self.manualFillAccessoryViewControllerDelegate passwordButtonPressed:sender]; [self.manualFillAccessoryViewControllerDelegate passwordButtonPressed:sender];
} }
#pragma mark - FormSuggestionViewDelegate
- (void)formSuggestionViewShouldResetFromPull:
(FormSuggestionView*)formSuggestionView {
base::RecordAction(base::UserMetricsAction("ManualFallback_ClosePull"));
// The pull gesture has the same effect as when the keyboard button is
// pressed.
[self.manualFillAccessoryViewControllerDelegate keyboardButtonPressed];
[self.manualFillAccessoryViewController resetAnimated:YES];
}
@end @end
...@@ -9,10 +9,24 @@ ...@@ -9,10 +9,24 @@
@class FormSuggestion; @class FormSuggestion;
@protocol FormSuggestionClient; @protocol FormSuggestionClient;
@class FormSuggestionView;
@protocol FormSuggestionViewDelegate <NSObject>
// The view received a long pull in the content direction. The delegate should
// probably unlock the trailing view and reset to a clean state.
- (void)formSuggestionViewShouldResetFromPull:
(FormSuggestionView*)formSuggestionView;
@end
// A scrollable view for displaying user-selectable autofill form suggestions. // A scrollable view for displaying user-selectable autofill form suggestions.
@interface FormSuggestionView : UIScrollView<UIInputViewAudioFeedback> @interface FormSuggestionView : UIScrollView<UIInputViewAudioFeedback>
// The delegate for FormSuggestionView events.
@property(nonatomic, weak) id<FormSuggestionViewDelegate>
formSuggestionViewDelegate;
// The current suggestions this view is showing. // The current suggestions this view is showing.
@property(nonatomic, readonly) NSArray<FormSuggestion*>* suggestions; @property(nonatomic, readonly) NSArray<FormSuggestion*>* suggestions;
...@@ -23,8 +37,9 @@ ...@@ -23,8 +37,9 @@
- (void)updateClient:(id<FormSuggestionClient>)client - (void)updateClient:(id<FormSuggestionClient>)client
suggestions:(NSArray<FormSuggestion*>*)suggestions; suggestions:(NSArray<FormSuggestion*>*)suggestions;
// Animates the content insets back to zero. // Reset content insets back to zero and sets the delegate to nil. Used to stop
- (void)unlockTrailingView; // hearing for the pull gesture to reset and unlock the trailing view.
- (void)resetContentInsetAndDelegate;
// Animates the content insets so the trailing view is showed as the first // Animates the content insets so the trailing view is showed as the first
// thing. // thing.
......
...@@ -29,7 +29,7 @@ const CGFloat kSuggestionHorizontalMargin = 6; ...@@ -29,7 +29,7 @@ const CGFloat kSuggestionHorizontalMargin = 6;
} // namespace } // namespace
@interface FormSuggestionView () @interface FormSuggestionView () <UIScrollViewDelegate>
// The FormSuggestions that are displayed by this view. // The FormSuggestions that are displayed by this view.
@property(nonatomic) NSArray<FormSuggestion*>* suggestions; @property(nonatomic) NSArray<FormSuggestion*>* suggestions;
...@@ -65,10 +65,8 @@ const CGFloat kSuggestionHorizontalMargin = 6; ...@@ -65,10 +65,8 @@ const CGFloat kSuggestionHorizontalMargin = 6;
} }
} }
- (void)unlockTrailingView { - (void)resetContentInsetAndDelegate {
if (!self.superview) { self.delegate = nil;
return;
}
[UIView animateWithDuration:0.2 [UIView animateWithDuration:0.2
animations:^{ animations:^{
self.contentInset = UIEdgeInsetsZero; self.contentInset = UIEdgeInsetsZero;
...@@ -79,16 +77,18 @@ const CGFloat kSuggestionHorizontalMargin = 6; ...@@ -79,16 +77,18 @@ const CGFloat kSuggestionHorizontalMargin = 6;
if (!self.superview || !self.trailingView) { if (!self.superview || !self.trailingView) {
return; return;
} }
LayoutOffset layoutOffset = CGRectGetLeadingLayoutOffsetInBoundingRect( LayoutOffset layoutOffset = CGRectGetLeadingLayoutOffsetInBoundingRect(
self.trailingView.frame, {CGPointZero, self.contentSize}); self.trailingView.frame, {CGPointZero, self.contentSize});
// Because the way the scroll view is transformed for RTL, the insets don't // Because the way the scroll view is transformed for RTL, the insets don't
// need to be directed. // need to be directed.
UIEdgeInsets lockedContentInsets = UIEdgeInsetsMake(0, -layoutOffset, 0, 0); UIEdgeInsets lockedContentInsets = UIEdgeInsetsMake(0, -layoutOffset, 0, 0);
[UIView animateWithDuration:0.2 [UIView animateWithDuration:0.2
animations:^{ animations:^{
self.contentInset = lockedContentInsets; self.contentInset = lockedContentInsets;
}]; }
completion:^(BOOL finished) {
self.delegate = self;
}];
} }
#pragma mark - UIView #pragma mark - UIView
...@@ -183,4 +183,14 @@ const CGFloat kSuggestionHorizontalMargin = 6; ...@@ -183,4 +183,14 @@ const CGFloat kSuggestionHorizontalMargin = 6;
} }
} }
- (void)scrollViewDidScroll:(UIScrollView*)scrollView {
CGFloat offset = self.contentOffset.x;
CGFloat inset = self.contentInset.left; // Inset is negative when locked.
CGFloat diff = offset + inset;
if (diff < -55) {
[self.formSuggestionViewDelegate
formSuggestionViewShouldResetFromPull:self];
}
}
@end @end
...@@ -183,16 +183,18 @@ ...@@ -183,16 +183,18 @@
[self.formInputAccessoryMediator disableSuggestions]; [self.formInputAccessoryMediator disableSuggestions];
} }
#pragma mark - FallbackCoordinatorDelegate
- (void)resetAccessoryView {
[self.formInputAccessoryViewController resetManualFallbackIcons];
}
#pragma mark - PasswordCoordinatorDelegate #pragma mark - PasswordCoordinatorDelegate
- (void)openPasswordSettings { - (void)openPasswordSettings {
[self.delegate openPasswordSettings]; [self.delegate openPasswordSettings];
} }
- (void)resetAccessoryView {
[self.formInputAccessoryViewController resetManualFallbackIcons];
}
#pragma mark - CardCoordinatorDelegate #pragma mark - CardCoordinatorDelegate
- (void)openCardSettings { - (void)openCardSettings {
......
...@@ -69,7 +69,7 @@ extern NSString* const AccessoryCreditCardAccessibilityIdentifier; ...@@ -69,7 +69,7 @@ extern NSString* const AccessoryCreditCardAccessibilityIdentifier;
// Resets to the original state, with the keyboard icon hidden and no icon // Resets to the original state, with the keyboard icon hidden and no icon
// selected. // selected.
- (void)reset; - (void)resetAnimated:(BOOL)animated;
@end @end
......
...@@ -75,10 +75,16 @@ static NSTimeInterval MFAnimationDuration = 0.2; ...@@ -75,10 +75,16 @@ static NSTimeInterval MFAnimationDuration = 0.2;
return self; return self;
} }
- (void)reset { - (void)resetAnimated:(BOOL)animated {
[self resetTintColors]; [UIView animateWithDuration:animated ? MFAnimationDuration : 0
self.keyboardButton.hidden = YES; animations:^{
self.keyboardButton.alpha = 0.0; [self resetTintColors];
// Workaround the |hidden| property in stacked views.
if (!self.keyboardButton.hidden) {
self.keyboardButton.hidden = YES;
self.keyboardButton.alpha = 0.0;
}
}];
} }
#pragma mark - Setters #pragma mark - Setters
...@@ -221,11 +227,15 @@ static NSTimeInterval MFAnimationDuration = 0.2; ...@@ -221,11 +227,15 @@ static NSTimeInterval MFAnimationDuration = 0.2;
- (void)animateKeyboardButtonHidden:(BOOL)hidden { - (void)animateKeyboardButtonHidden:(BOOL)hidden {
[UIView animateWithDuration:MFAnimationDuration [UIView animateWithDuration:MFAnimationDuration
animations:^{ animations:^{
// Workaround setting more than once the |hidden| property
// in stacked views.
if (self.keyboardButton.hidden != hidden) {
self.keyboardButton.hidden = hidden;
}
if (hidden) { if (hidden) {
self.keyboardButton.hidden = YES;
self.keyboardButton.alpha = 0.0; self.keyboardButton.alpha = 0.0;
} else { } else {
self.keyboardButton.hidden = NO;
self.keyboardButton.alpha = 1.0; self.keyboardButton.alpha = 1.0;
} }
}]; }];
......
...@@ -10143,6 +10143,14 @@ should be able to be added at any place in this file. ...@@ -10143,6 +10143,14 @@ should be able to be added at any place in this file.
</description> </description>
</action> </action>
<action name="ManualFallback_ClosePull">
<owner>javierrobles@chromium.org</owner>
<description>
The user closed the Manual Fallback view by pulling. This happens when the
user pulls enough to the right, similar to &quot;pull to refresh&quot;.
</description>
</action>
<action name="ManualFallback_CreditCard_OpenManageCreditCard"> <action name="ManualFallback_CreditCard_OpenManageCreditCard">
<owner>javierrobles@chromium.org</owner> <owner>javierrobles@chromium.org</owner>
<description> <description>
......
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