Commit b6ab1448 authored by Robbie Gibson's avatar Robbie Gibson Committed by Commit Bot

[iOS] Update Thumb Strip plus button state when adding/removing tabs

Before, |fractionVisibleOfLastItem| was only updated on scroll, so the
plus button only appeared/was hidden on scroll. It should also be
updated when tabs are added or removed.

Bug: 1094335
Change-Id: I2e187c8b41ba69b3cb1e3a1d0b4158a82e43809c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2529112
Commit-Queue: Robbie Gibson <rkgibson@google.com>
Reviewed-by: default avataredchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826770}
parent b2e17027
...@@ -584,9 +584,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) { ...@@ -584,9 +584,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
- (void)scrollViewDidScroll:(UIScrollView*)scrollView { - (void)scrollViewDidScroll:(UIScrollView*)scrollView {
if (!IsThumbStripEnabled()) if (!IsThumbStripEnabled())
return; return;
CGFloat offset = self.offsetPastEndOfScrollView; [self updateFractionVisibleOfLastItem];
self.fractionVisibleOfLastItem = base::ClampToRange<CGFloat>(
1 - offset / kScrollThresholdForPlusSignButtonHide, 0, 1);
} }
#pragma mark - GridCellDelegate #pragma mark - GridCellDelegate
...@@ -635,6 +633,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) { ...@@ -635,6 +633,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
} }
// Whether the view is visible or not, the delegate must be updated. // Whether the view is visible or not, the delegate must be updated.
[self.delegate gridViewController:self didChangeItemCount:self.items.count]; [self.delegate gridViewController:self didChangeItemCount:self.items.count];
[self updateFractionVisibleOfLastItem];
} }
- (void)insertItem:(GridItem*)item - (void)insertItem:(GridItem*)item
...@@ -664,6 +663,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) { ...@@ -664,6 +663,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
animated:YES animated:YES
scrollPosition:UICollectionViewScrollPositionNone]; scrollPosition:UICollectionViewScrollPositionNone];
[self.delegate gridViewController:self didChangeItemCount:self.items.count]; [self.delegate gridViewController:self didChangeItemCount:self.items.count];
[self updateFractionVisibleOfLastItem];
}; };
[self performModelUpdates:modelUpdates [self performModelUpdates:modelUpdates
collectionViewUpdates:collectionViewUpdates collectionViewUpdates:collectionViewUpdates
...@@ -703,6 +703,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) { ...@@ -703,6 +703,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
scrollPosition:UICollectionViewScrollPositionNone]; scrollPosition:UICollectionViewScrollPositionNone];
} }
[self.delegate gridViewController:self didChangeItemCount:self.items.count]; [self.delegate gridViewController:self didChangeItemCount:self.items.count];
[self updateFractionVisibleOfLastItem];
}; };
[self performModelUpdates:modelUpdates [self performModelUpdates:modelUpdates
collectionViewUpdates:collectionViewUpdates collectionViewUpdates:collectionViewUpdates
...@@ -955,6 +956,13 @@ NSIndexPath* CreateIndexPath(NSInteger index) { ...@@ -955,6 +956,13 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
} }
} }
// Updates the value stored in |fractionVisibleOfLastItem|.
- (void)updateFractionVisibleOfLastItem {
CGFloat offset = self.offsetPastEndOfScrollView;
self.fractionVisibleOfLastItem = base::ClampToRange<CGFloat>(
1 - offset / kScrollThresholdForPlusSignButtonHide, 0, 1);
}
#pragma mark - Custom Gesture-based Reordering #pragma mark - Custom Gesture-based Reordering
// Handle the long-press gesture used to reorder cells in the collection view. // Handle the long-press gesture used to reorder cells in the collection view.
......
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