Commit fce9ec8d authored by Marti Wong's avatar Marti Wong Committed by Commit Bot

Fix the incorrect bottom inset when keyboard appears (iOS bookmarks)

Fix the incorrect bottom inset of bookmarkTableView which is set when
keyboard appears for editing new folder name.  (This causes the new
folder being "pushed" to the top of the screen on iPad.)
Screenshot: https://drive.google.com/file/d/1q_w8bRICkEQmOgApFM1wG79UBLJ_EReS

Bug: 790046
Change-Id: Ic331244b9f49d77ef0b01edf20252ae4cec2e88d
Reviewed-on: https://chromium-review.googlesource.com/805179Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Commit-Queue: Marti Wong <martiw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521518}
parent 505e8e9c
......@@ -559,6 +559,10 @@ std::vector<GURL> GetUrlsToOpen(const std::vector<const BookmarkNode*>& nodes) {
}
}
- (BOOL)isAtTopOfNavigation:(BookmarkTableView*)view {
return (self.navigationController.topViewController == self);
}
#pragma mark - BookmarkFolderViewControllerDelegate
- (void)folderPicker:(BookmarkFolderViewController*)folderPicker
......
......@@ -64,6 +64,9 @@ class ChromeBrowserState;
// Tells the delegate to refresh the context bar.
- (void)bookmarkTableViewRefreshContextBar:(BookmarkTableView*)view;
// Returns true if this table is at the top of the navigation stack.
- (BOOL)isAtTopOfNavigation:(BookmarkTableView*)view;
@end
@interface BookmarkTableView : UIView
......
......@@ -42,6 +42,9 @@ CGFloat kMinFaviconSizePt = 16;
// Cell height, in points.
CGFloat kCellHeightPt = 56.0;
// Minimium spacing between keyboard and the titleText when creating new folder.
CGFloat keyboardSpacing = 16.0;
}
using bookmarks::BookmarkNode;
......@@ -937,21 +940,32 @@ using IntegerPair = std::pair<NSInteger, NSInteger>;
// Called when the UIKeyboardDidShowNotification is sent
- (void)keyboardWasShown:(NSNotification*)aNotification {
if (![self.delegate isAtTopOfNavigation:self]) {
return;
}
NSDictionary* info = [aNotification userInfo];
CGSize kbSize =
[[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
CGFloat keyboardTop =
[[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].origin.y;
CGFloat tableBottom =
CGRectGetMaxY([self convertRect:self.tableView.frame toView:nil]);
CGFloat shiftY = tableBottom - keyboardTop + keyboardSpacing;
if (shiftY >= 0) {
UIEdgeInsets previousContentInsets = self.tableView.contentInset;
// Shift the content inset by the height of the keyboard so we can scoll to
// the bottom of the content that is potentially behind the keyboard.
// Shift the content inset to prevent the editing content from being hidden
// by the keyboard.
UIEdgeInsets contentInsets =
UIEdgeInsetsMake(previousContentInsets.top, 0.0, kbSize.height, 0.0);
UIEdgeInsetsMake(previousContentInsets.top, 0.0, shiftY, 0.0);
self.tableView.contentInset = contentInsets;
self.tableView.scrollIndicatorInsets = contentInsets;
}
}
// Called when the UIKeyboardWillHideNotification is sent
- (void)keyboardWillBeHidden:(NSNotification*)aNotification {
if (![self.delegate isAtTopOfNavigation:self]) {
return;
}
UIEdgeInsets previousContentInsets = self.tableView.contentInset;
// Restore the content inset now that the keyboard has been hidden.
UIEdgeInsets contentInsets =
......
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