Commit 6672f6a2 authored by edchin's avatar edchin Committed by Commit Bot

[ios] Make new tab button change appearance during page scroll

Previously, the new tab button would not change until after
the page scroll completed the animation. In that case, the
user is able to tap on the button during the animation, which
potentially resulted in the wrong type of tab being created.

This CL ensures that the new tab button, as well as all other
visual appearances dependent on the current page gets updated
during the scroll, so it is accurate as possible.

Bug: 823842, 804580
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I541a2811929b4e0835649c64e76260f4e11962da
Reviewed-on: https://chromium-review.googlesource.com/972435
Commit-Queue: edchin <edchin@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545058}
parent 55373bc3
...@@ -103,6 +103,7 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) { ...@@ -103,6 +103,7 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) {
// Call the current page setter to sync the scroll view offset to the current // Call the current page setter to sync the scroll view offset to the current
// page value. // page value.
self.currentPage = _currentPage; self.currentPage = _currentPage;
[self.topToolbar.pageControl setSelectedPage:self.currentPage animated:YES];
[self configureViewControllerForCurrentSizeClassesAndPage]; [self configureViewControllerForCurrentSizeClassesAndPage];
if (animated && self.transitionCoordinator) { if (animated && self.transitionCoordinator) {
[self animateToolbarsForAppearance]; [self animateToolbarsForAppearance];
...@@ -155,16 +156,17 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) { ...@@ -155,16 +156,17 @@ 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;
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView*)scrollView { // Bookkeeping for the current page.
// Bookkeeping for the current page. // TODO(crbug.com/822328) : Fix for RTL.
CGFloat pageWidth = scrollView.frame.size.width; CGFloat pageWidth = scrollView.frame.size.width;
float fractionalPage = scrollView.contentOffset.x / pageWidth; float fractionalPage = scrollView.contentOffset.x / pageWidth;
NSUInteger page = lround(fractionalPage); NSUInteger page = lround(fractionalPage);
_currentPage = static_cast<TabGridPage>(page); if (page != self.currentPage) {
[self configureButtonsForCurrentPage]; _currentPage = static_cast<TabGridPage>(page);
[self configureButtonsForCurrentPage];
}
}
} }
#pragma mark - UIScrollViewAccessibilityDelegate #pragma mark - UIScrollViewAccessibilityDelegate
...@@ -553,7 +555,6 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) { ...@@ -553,7 +555,6 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) {
} }
- (void)configureButtonsForCurrentPage { - (void)configureButtonsForCurrentPage {
[self.topToolbar.pageControl setSelectedPage:self.currentPage animated:YES];
self.newTabButton.page = self.currentPage; self.newTabButton.page = self.currentPage;
switch (self.currentPage) { switch (self.currentPage) {
case TabGridPageIncognitoTabs: case TabGridPageIncognitoTabs:
......
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