Commit 7f80af5b authored by Marti Wong's avatar Marti Wong Committed by Commit Bot

Prevent bookmark scroll position from mistakenly reset to zero.

In bookmark_home_handset_view_controller and
bookmark_home_tablet_ntp_controller, prevent primaryView's content
position from mistakenly reset to zero at viewWillLayoutSubviews().

Bug: 608777
Change-Id: Ifa6a4c075866509171180614cd0d5916a30a9466
Reviewed-on: https://chromium-review.googlesource.com/578693
Commit-Queue: Marti Wong <martiw@chromium.org>
Reviewed-by: default avatarEric Noyau <noyau@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488617}
parent 20b5f338
......@@ -255,7 +255,7 @@ const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0;
return self.collectionView.contentOffset.y;
// In short landscape mode and portrait mode, there are 2 cells per row.
if ([self wideLandscapeMode])
if (![self wideLandscapeMode])
return self.collectionView.contentOffset.y;
// In wide landscape mode, there are 3 cells per row.
......
......@@ -130,15 +130,20 @@ using bookmarks::BookmarkNode;
[super viewWillAppear:animated];
UIInterfaceOrientation orient = GetInterfaceOrientation();
[self updateUIForInterfaceOrientation:orient duration:0];
if (self.cachedContentPosition) {
[self.folderView
applyContentPosition:[self.cachedContentPosition floatValue]];
self.cachedContentPosition = nil;
}
}
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
// Store the content scroll position.
CGFloat contentPosition =
[[self folderView] contentPositionInPortraitOrientation];
// If we have the cached position, use it instead.
if (self.cachedContentPosition) {
contentPosition = [self.cachedContentPosition floatValue];
self.cachedContentPosition = nil;
}
// Invalidate the layout of the collection view, as its frame might have
// changed. Normally, this can be done automatically when the collection view
// layout returns YES to -shouldInvalidateLayoutForBoundsChange:.
......@@ -151,6 +156,14 @@ using bookmarks::BookmarkNode;
self.navigationBar.frame = [self navigationBarFrame];
self.editingBar.frame = [self navigationBarFrame];
[self.panelView setFrame:[self frameForPanelView]];
// Restore the content scroll position if it was reset to zero. This could
// happen when folderView is newly created (restore from cached) or its frame
// height has changed.
if (contentPosition > 0 &&
[[self folderView] contentPositionInPortraitOrientation] == 0) {
[[self folderView] applyContentPosition:contentPosition];
}
}
- (BOOL)prefersStatusBarHidden {
......
......@@ -57,10 +57,9 @@ const CGFloat kNavigationBarTopMargin = 8.0;
@interface BookmarkHomeTabletNTPController ()<BookmarkMenuViewDelegate>
// When the view is first shown on the screen, this property represents the
// cached value of the y of the content offset of the primary view. This
// cached value of the y of the content offset of the folder view. This
// property is set to nil after it is used.
@property(nonatomic, strong)
NSNumber* cachedContentPosition; // FIXME: INACTIVE
@property(nonatomic, strong) NSNumber* cachedContentPosition;
#pragma mark Private methods
......@@ -99,6 +98,16 @@ const CGFloat kNavigationBarTopMargin = 8.0;
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
// Store the content scroll position.
CGFloat contentPosition =
[[self folderView] contentPositionInPortraitOrientation];
// If we have the cached position, use it instead.
if (self.cachedContentPosition) {
contentPosition = [self.cachedContentPosition floatValue];
self.cachedContentPosition = nil;
}
if (!self.folderView && ![self primaryMenuItem] && self.bookmarks->loaded()) {
BookmarkMenuItem* item = nil;
CGFloat position = 0;
......@@ -132,6 +141,14 @@ const CGFloat kNavigationBarTopMargin = 8.0;
[self updateNavigationBarWithDuration:0 orientation:orient];
if (![self shouldPresentMenuInSlideInPanel])
[self updateMenuViewLayout];
// Restore the content scroll position if it was reset to zero. This could
// happen when folderView is newly created (restore from cached); its frame
// height has changed; or it was re-attached to the view hierarchy.
if (contentPosition > 0 &&
[[self folderView] contentPositionInPortraitOrientation] == 0) {
[[self folderView] applyContentPosition:contentPosition];
}
}
- (void)viewDidLoad {
......
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