Commit c418d652 authored by Nazerke's avatar Nazerke Committed by Chromium LUCI CQ

[ios] Adds the zPosition for the selected cells.

This CL adds the zPosition for the selected cells in the tabstrip to
make them fully visible.

Bug: 1154122,1128249
Change-Id: If11dd52e456bc5b3c625ef3aaf226a39326e72d2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2575025Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Commit-Queue: Nazerke Kalidolda <nazerke@google.com>
Cr-Commit-Position: refs/heads/master@{#837551}
parent 4f5e14ee
...@@ -60,6 +60,7 @@ const CGFloat kNewTabButtonBottomImageInset = -2.0; ...@@ -60,6 +60,7 @@ const CGFloat kNewTabButtonBottomImageInset = -2.0;
self.collectionView.alwaysBounceHorizontal = YES; self.collectionView.alwaysBounceHorizontal = YES;
[self.collectionView registerClass:[TabStripCell class] [self.collectionView registerClass:[TabStripCell class]
forCellWithReuseIdentifier:kReuseIdentifier]; forCellWithReuseIdentifier:kReuseIdentifier];
[self orderBySelectedTab];
self.buttonNewTab = [[UIButton alloc] init]; self.buttonNewTab = [[UIButton alloc] init];
self.buttonNewTab.translatesAutoresizingMaskIntoConstraints = NO; self.buttonNewTab.translatesAutoresizingMaskIntoConstraints = NO;
...@@ -189,6 +190,7 @@ const CGFloat kNewTabButtonBottomImageInset = -2.0; ...@@ -189,6 +190,7 @@ const CGFloat kNewTabButtonBottomImageInset = -2.0;
selectItemAtIndexPath:CreateIndexPath(self.selectedIndex) selectItemAtIndexPath:CreateIndexPath(self.selectedIndex)
animated:YES animated:YES
scrollPosition:UICollectionViewScrollPositionNone]; scrollPosition:UICollectionViewScrollPositionNone];
[self orderBySelectedTab];
} }
#pragma mark - Private #pragma mark - Private
...@@ -227,6 +229,20 @@ const CGFloat kNewTabButtonBottomImageInset = -2.0; ...@@ -227,6 +229,20 @@ const CGFloat kNewTabButtonBottomImageInset = -2.0;
[self.delegate addNewItem]; [self.delegate addNewItem];
} }
// Puts the tabs into the right positioning, i.e. the selected tab is in the
// foreground, and the farther tabs are from the selected tab, the lower
// zPositioning is.
- (void)orderBySelectedTab {
for (TabSwitcherItem* item in self.items) {
NSUInteger index = [self indexOfItemWithID:item.identifier];
UICollectionViewCell* cell =
[self.collectionView cellForItemAtIndexPath:CreateIndexPath(index)];
// Calculating how "far" is the current tab from the selected one.
cell.layer.zPosition =
(int)(self.selectedIndex - abs(int(self.selectedIndex - index)));
}
}
#pragma mark - Private properties #pragma mark - Private properties
- (NSUInteger)selectedIndex { - (NSUInteger)selectedIndex {
...@@ -239,6 +255,7 @@ const CGFloat kNewTabButtonBottomImageInset = -2.0; ...@@ -239,6 +255,7 @@ const CGFloat kNewTabButtonBottomImageInset = -2.0;
didSelectItemAtIndexPath:(NSIndexPath*)indexPath { didSelectItemAtIndexPath:(NSIndexPath*)indexPath {
int index = indexPath.item; int index = indexPath.item;
[self.delegate selectTab:index]; [self.delegate selectTab:index];
[self orderBySelectedTab];
} }
#pragma mark - TabStripCellDelegate #pragma mark - TabStripCellDelegate
......
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