Commit bb392971 authored by Ramya Sharma's avatar Ramya Sharma Committed by Commit Bot

Fixes content position so that its more accurate when restoring from

cache.

TBR=martiw

Bug: 695749
Change-Id: I9f7eb9b56cd608174c658ceffd1079eca7c10c04
Reviewed-on: https://chromium-review.googlesource.com/670963Reviewed-by: default avatarRamya Sharma <ramyasharma@chromium.org>
Reviewed-by: default avatarMarti Wong <martiw@chromium.org>
Commit-Queue: Ramya Sharma <ramyasharma@chromium.org>
Cr-Commit-Position: refs/heads/master@{#502569}
parent 7a6fd9b2
...@@ -129,8 +129,6 @@ using bookmarks::BookmarkNode; ...@@ -129,8 +129,6 @@ using bookmarks::BookmarkNode;
- (void)viewWillLayoutSubviews { - (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews]; [super viewWillLayoutSubviews];
if (base::FeatureList::IsEnabled(kBookmarkNewGeneration)) { if (base::FeatureList::IsEnabled(kBookmarkNewGeneration)) {
// TODO(crbug.com/695749): See if we need to store/restore the content
// scroll position for BookmarkTableView here.
return; return;
} }
......
...@@ -182,11 +182,23 @@ std::vector<GURL> GetUrlsToOpen(const std::vector<const BookmarkNode*>& nodes) { ...@@ -182,11 +182,23 @@ std::vector<GURL> GetUrlsToOpen(const std::vector<const BookmarkNode*>& nodes) {
} }
- (void)viewWillAppear:(BOOL)animated { - (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (self.isReconstructingFromCache) { if (self.isReconstructingFromCache) {
[self setupUIStackCacheIfApplicable]; [self setupUIStackCacheIfApplicable];
} }
} }
- (void)viewDidLayoutSubviews {
// Set the content position after views are laid out,
// to ensure the right window of rows is shown. Once
// used, reset self.cachedContentPosition.
if (self.cachedContentPosition) {
[self.bookmarksTableView
setContentPosition:self.cachedContentPosition.floatValue];
self.cachedContentPosition = nil;
}
}
#pragma mark - Public #pragma mark - Public
- (void)dismissModals { - (void)dismissModals {
...@@ -975,10 +987,6 @@ std::vector<GURL> GetUrlsToOpen(const std::vector<const BookmarkNode*>& nodes) { ...@@ -975,10 +987,6 @@ std::vector<GURL> GetUrlsToOpen(const std::vector<const BookmarkNode*>& nodes) {
setAutoresizingMask:UIViewAutoresizingFlexibleWidth | setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight]; UIViewAutoresizingFlexibleHeight];
[self.bookmarksTableView setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.bookmarksTableView setTranslatesAutoresizingMaskIntoConstraints:NO];
if (self.cachedContentPosition) {
[self.bookmarksTableView
setContentPosition:self.cachedContentPosition.floatValue];
}
[self.view addSubview:self.bookmarksTableView]; [self.view addSubview:self.bookmarksTableView];
if (_rootNode != self.bookmarks->root_node()) { if (_rootNode != self.bookmarks->root_node()) {
......
...@@ -292,9 +292,13 @@ using IntegerPair = std::pair<NSInteger, NSInteger>; ...@@ -292,9 +292,13 @@ using IntegerPair = std::pair<NSInteger, NSInteger>;
- (void)setContentPosition:(CGFloat)position { - (void)setContentPosition:(CGFloat)position {
NSIndexPath* path = NSIndexPath* path =
[NSIndexPath indexPathForRow:position inSection:self.bookmarksSection]; [NSIndexPath indexPathForRow:position inSection:self.bookmarksSection];
[self.tableView scrollToRowAtIndexPath:path // Anchoring |position| as the starting point calculate the visible rect area,
atScrollPosition:UITableViewScrollPositionTop // based on screen size.
animated:NO]; CGRect visibleRect = [self.tableView rectForRowAtIndexPath:path];
visibleRect =
CGRectMake(visibleRect.origin.x, visibleRect.origin.y,
visibleRect.size.width, self.tableView.frame.size.height);
[self.tableView scrollRectToVisible:visibleRect animated:NO];
} }
#pragma mark - UITableViewDataSource #pragma mark - UITableViewDataSource
......
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