Commit a606972d authored by edchin's avatar edchin Committed by Commit Bot

[ios] Fix rotations in tab grid

The tab grid was not behaving properly in rotations. The page would
change when it is not supposed to. This is due to the page being set
inside |-scrollViewDidScroll:| while the rotation was occurring.
The fix is to separately set the page for non-user-dragging scroll
in |-scrollViewDidEndScrollingAnimation:|.

Bug: 828735
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Ib325eb6ef5d5ebb98274ec565cdbb03a21b8e9e1
Reviewed-on: https://chromium-review.googlesource.com/998055Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Commit-Queue: edchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548541}
parent 81dae6b3
...@@ -29,6 +29,14 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) { ...@@ -29,6 +29,14 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) {
TabGridConfigurationBottomToolbar = 1, TabGridConfigurationBottomToolbar = 1,
TabGridConfigurationFloatingButton, TabGridConfigurationFloatingButton,
}; };
// Computes the page from the offset and width of |scrollView|.
TabGridPage GetPageFromScrollView(UIScrollView* scrollView) {
// TODO(crbug.com/822328) : Fix for RTL.
CGFloat pageWidth = scrollView.frame.size.width;
float fractionalPage = scrollView.contentOffset.x / pageWidth;
return static_cast<TabGridPage>(lround(fractionalPage));
}
} // namespace } // namespace
@interface TabGridViewController ()<GridViewControllerDelegate, @interface TabGridViewController ()<GridViewControllerDelegate,
...@@ -169,19 +177,20 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) { ...@@ -169,19 +177,20 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) {
self.scrollView.contentSize.width - self.scrollView.frame.size.width; self.scrollView.contentSize.width - self.scrollView.frame.size.width;
CGFloat offset = scrollView.contentOffset.x / offsetWidth; CGFloat offset = scrollView.contentOffset.x / offsetWidth;
self.topToolbar.pageControl.sliderPosition = offset; self.topToolbar.pageControl.sliderPosition = offset;
}
// Bookkeeping for the current page. TabGridPage page = GetPageFromScrollView(scrollView);
// TODO(crbug.com/822328) : Fix for RTL. if (page != _currentPage) {
CGFloat pageWidth = scrollView.frame.size.width; _currentPage = page;
float fractionalPage = scrollView.contentOffset.x / pageWidth; [self configureButtonsForOriginalAndCurrentPage];
NSUInteger page = lround(fractionalPage); }
if (page != self.currentPage) {
_currentPage = static_cast<TabGridPage>(page);
[self configureButtonsForOriginalAndCurrentPage];
} }
} }
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView*)scrollView {
_currentPage = GetPageFromScrollView(scrollView);
[self configureButtonsForOriginalAndCurrentPage];
}
#pragma mark - UIScrollViewAccessibilityDelegate #pragma mark - UIScrollViewAccessibilityDelegate
- (NSString*)accessibilityScrollStatusForScrollView:(UIScrollView*)scrollView { - (NSString*)accessibilityScrollStatusForScrollView:(UIScrollView*)scrollView {
...@@ -280,7 +289,7 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) { ...@@ -280,7 +289,7 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) {
_currentPage = currentPage; _currentPage = currentPage;
} else { } else {
[self.scrollView setContentOffset:offset animated:YES]; [self.scrollView setContentOffset:offset animated:YES];
// _currentPage is set in scrollViewDidScroll: // _currentPage is set in scrollViewDidEndScrollingAnimation:
} }
} }
......
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