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 @@
#include "base/mac/foundation_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.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_suggestion_view.h"
......@@ -23,6 +24,7 @@ CGFloat const kInputAccessoryHeight = 44.0f;
} // namespace autofill
@interface FormInputAccessoryViewController () <
FormSuggestionViewDelegate,
ManualFillAccessoryViewControllerDelegate>
// Grey view used as the background of the keyboard to fix
......@@ -133,7 +135,7 @@ CGFloat const kInputAccessoryHeight = 44.0f;
}
- (void)unlockManualFallbackView {
[self.formSuggestionView unlockTrailingView];
[self.formSuggestionView resetContentInsetAndDelegate];
}
- (void)lockManualFallbackView {
......@@ -141,7 +143,7 @@ CGFloat const kInputAccessoryHeight = 44.0f;
}
- (void)resetManualFallbackIcons {
[self.manualFillAccessoryViewController reset];
[self.manualFillAccessoryViewController resetAnimated:YES];
}
#pragma mark - FormInputAccessoryConsumer
......@@ -178,6 +180,7 @@ CGFloat const kInputAccessoryHeight = 44.0f;
// Create the views if they don't exist already.
if (!self.formSuggestionView) {
self.formSuggestionView = [[FormSuggestionView alloc] init];
self.formSuggestionView.formSuggestionViewDelegate = self;
}
[self.formSuggestionView updateClient:suggestionClient
......@@ -209,7 +212,7 @@ CGFloat const kInputAccessoryHeight = 44.0f;
}
- (void)restoreOriginalKeyboardView {
[self.manualFillAccessoryViewController reset];
[self.manualFillAccessoryViewController resetAnimated:NO];
[self removeCustomInputAccessoryView];
[self.keyboardReplacementView removeFromSuperview];
self.keyboardReplacementView = nil;
......@@ -430,4 +433,15 @@ CGFloat const kInputAccessoryHeight = 44.0f;
[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
......@@ -9,10 +9,24 @@
@class FormSuggestion;
@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.
@interface FormSuggestionView : UIScrollView<UIInputViewAudioFeedback>
// The delegate for FormSuggestionView events.
@property(nonatomic, weak) id<FormSuggestionViewDelegate>
formSuggestionViewDelegate;
// The current suggestions this view is showing.
@property(nonatomic, readonly) NSArray<FormSuggestion*>* suggestions;
......@@ -23,8 +37,9 @@
- (void)updateClient:(id<FormSuggestionClient>)client
suggestions:(NSArray<FormSuggestion*>*)suggestions;
// Animates the content insets back to zero.
- (void)unlockTrailingView;
// Reset content insets back to zero and sets the delegate to nil. Used to stop
// 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
// thing.
......
......@@ -29,7 +29,7 @@ const CGFloat kSuggestionHorizontalMargin = 6;
} // namespace
@interface FormSuggestionView ()
@interface FormSuggestionView () <UIScrollViewDelegate>
// The FormSuggestions that are displayed by this view.
@property(nonatomic) NSArray<FormSuggestion*>* suggestions;
......@@ -65,10 +65,8 @@ const CGFloat kSuggestionHorizontalMargin = 6;
}
}
- (void)unlockTrailingView {
if (!self.superview) {
return;
}
- (void)resetContentInsetAndDelegate {
self.delegate = nil;
[UIView animateWithDuration:0.2
animations:^{
self.contentInset = UIEdgeInsetsZero;
......@@ -79,7 +77,6 @@ const CGFloat kSuggestionHorizontalMargin = 6;
if (!self.superview || !self.trailingView) {
return;
}
LayoutOffset layoutOffset = CGRectGetLeadingLayoutOffsetInBoundingRect(
self.trailingView.frame, {CGPointZero, self.contentSize});
// Because the way the scroll view is transformed for RTL, the insets don't
......@@ -88,6 +85,9 @@ const CGFloat kSuggestionHorizontalMargin = 6;
[UIView animateWithDuration:0.2
animations:^{
self.contentInset = lockedContentInsets;
}
completion:^(BOOL finished) {
self.delegate = self;
}];
}
......@@ -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
......@@ -183,16 +183,18 @@
[self.formInputAccessoryMediator disableSuggestions];
}
#pragma mark - FallbackCoordinatorDelegate
- (void)resetAccessoryView {
[self.formInputAccessoryViewController resetManualFallbackIcons];
}
#pragma mark - PasswordCoordinatorDelegate
- (void)openPasswordSettings {
[self.delegate openPasswordSettings];
}
- (void)resetAccessoryView {
[self.formInputAccessoryViewController resetManualFallbackIcons];
}
#pragma mark - CardCoordinatorDelegate
- (void)openCardSettings {
......
......@@ -69,7 +69,7 @@ extern NSString* const AccessoryCreditCardAccessibilityIdentifier;
// Resets to the original state, with the keyboard icon hidden and no icon
// selected.
- (void)reset;
- (void)resetAnimated:(BOOL)animated;
@end
......
......@@ -75,10 +75,16 @@ static NSTimeInterval MFAnimationDuration = 0.2;
return self;
}
- (void)reset {
- (void)resetAnimated:(BOOL)animated {
[UIView animateWithDuration:animated ? MFAnimationDuration : 0
animations:^{
[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
......@@ -221,11 +227,15 @@ static NSTimeInterval MFAnimationDuration = 0.2;
- (void)animateKeyboardButtonHidden:(BOOL)hidden {
[UIView animateWithDuration:MFAnimationDuration
animations:^{
// Workaround setting more than once the |hidden| property
// in stacked views.
if (self.keyboardButton.hidden != hidden) {
self.keyboardButton.hidden = hidden;
}
if (hidden) {
self.keyboardButton.hidden = YES;
self.keyboardButton.alpha = 0.0;
} else {
self.keyboardButton.hidden = NO;
self.keyboardButton.alpha = 1.0;
}
}];
......
......@@ -10143,6 +10143,14 @@ should be able to be added at any place in this file.
</description>
</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">
<owner>javierrobles@chromium.org</owner>
<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