Commit 9ff46f9b authored by Javier Ernesto Flores Robles's avatar Javier Ernesto Flores Robles Committed by Commit Bot

[iOS][MF] Fix insets when changing fields.

This fixes a bug that was causing the system to add insets to the table
view when jumping between fields. This inset was the same as the one
other scroll views get when the keyboard appears. Setting
|contentInsetAdjustmentBehavior| to never is not enough, and the
inset gets added anyway.

Bug: 878388
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: I305395fc691301a467523755d006277687a35c1d
Reviewed-on: https://chromium-review.googlesource.com/c/1273041Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600976}
parent 859b0299
......@@ -71,7 +71,7 @@ initWithBaseViewController:(UIViewController*)viewController
if (self) {
_passwordViewController =
[[PasswordViewController alloc] initWithSearchController:nil];
_passwordViewController.contentInsetsAlwaysEqualToSafeArea = YES;
_manualFillInjectionHandler = injectionHandler;
auto passwordStore = IOSChromePasswordStoreFactory::GetForBrowserState(
......
......@@ -29,6 +29,11 @@ extern NSString* const PasswordDoneButtonAccessibilityIdentifier;
appBarStyle:
(ChromeTableViewControllerStyle)appBarStyle
NS_UNAVAILABLE;
// If set to YES, the controller will add negative content insets inverse to the
// ones added by UITableViewController to accommodate for the keyboard.
@property(nonatomic, assign) BOOL contentInsetsAlwaysEqualToSafeArea;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_PASSWORD_VIEW_CONTROLLER_H_
......@@ -9,6 +9,7 @@
#import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_password_cell.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_styler.h"
#include "ios/chrome/browser/ui/ui_util.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util_mac.h"
......@@ -54,6 +55,17 @@ constexpr float PopoverMaxHeight = 250;
appBarStyle:ChromeTableViewControllerStyleNoAppBar];
if (self) {
_searchController = searchController;
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(handleKeyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(handleKeyboardDidHide:)
name:UIKeyboardDidHideNotification
object:nil];
}
return self;
}
......@@ -111,6 +123,29 @@ constexpr float PopoverMaxHeight = 250;
#pragma mark - Private
- (void)handleKeyboardDidHide:(NSNotification*)notification {
if (self.contentInsetsAlwaysEqualToSafeArea && !IsIPadIdiom()) {
// Resets the table view content inssets to be equal to the safe area
// insets.
self.tableView.contentInset = SafeAreaInsetsForView(self.view);
}
}
- (void)handleKeyboardWillShow:(NSNotification*)notification {
if (self.contentInsetsAlwaysEqualToSafeArea && !IsIPadIdiom()) {
// Sets the bottom inset to be equal to the height of the keyboard to
// override the behaviour in UITableViewController. Which adjust the scroll
// view insets to accommodate for the keyboard.
CGRect keyboardFrame =
[notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat keyboardHeight = keyboardFrame.size.height;
UIEdgeInsets safeInsets = SafeAreaInsetsForView(self.view);
self.tableView.contentInset =
UIEdgeInsetsMake(safeInsets.top, safeInsets.left,
safeInsets.bottom - keyboardHeight, safeInsets.right);
}
}
// Presents |items| in the respective section. Handles creating or deleting the
// section accordingly.
- (void)presentItems:(NSArray<TableViewItem*>*)items
......
......@@ -37,6 +37,7 @@
namespace {
const char kFormElementUsername[] = "username";
const char kFormElementPassword[] = "password";
const char kExampleUsername[] = "concrete username";
const char kExamplePassword[] = "concrete password";
......@@ -472,4 +473,32 @@ void ClearPasswordStore() {
assertWithMatcher:grey_notVisible()];
}
// Test that after switching fields the content size of the table view didn't
// grow.
- (void)testPasswordControllerKeepsRightSize {
// Bring up the keyboard.
[[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()]
performAction:chrome_test_util::TapWebElement(kFormElementUsername)];
// Tap on the passwords icon.
[[EarlGrey selectElementWithMatcher:PasswordIconMatcher()]
performAction:grey_tap()];
// Verify the "Manage Passwords..." is on screen.
[[EarlGrey selectElementWithMatcher:OtherPasswordsMatcher()]
assertWithMatcher:grey_sufficientlyVisible()];
// Tap the second element.
[[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()]
performAction:chrome_test_util::TapWebElement(kFormElementPassword)];
// Try to scroll.
[[EarlGrey selectElementWithMatcher:PasswordTableViewMatcher()]
performAction:grey_scrollToContentEdge(kGREYContentEdgeBottom)];
// Verify the "Manage Passwords..." is on screen.
[[EarlGrey selectElementWithMatcher:OtherPasswordsMatcher()]
assertWithMatcher:grey_sufficientlyVisible()];
}
@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