-
Notifications
You must be signed in to change notification settings - Fork 946
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Tabs] Adjust sizeThatFits: behavior for TabBarView. (#7846)
The `sizeThatFits:` beahvior of `MDCTabBarView` previously would return a size
large enough for Fixed tabs in a justified layout. If the provided `size` was
wider than necessary, that value would be returned.
A solution that works better for inclusion in MDCHeaderStackView, which uses
`sizeThatFits:` to determine the view's frame size.
Closes #7845
- Loading branch information
Robert Moore
committed
Jul 10, 2019
1 parent
29e37b8
commit 7c7208f
Showing
21 changed files
with
198 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
components/Tabs/tests/snapshot/TabBarView/MDCTabBarViewIntegrationSnapshotTests.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
// Copyright 2019-present the Material Components for iOS authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#import "MaterialSnapshot.h" | ||
|
||
#import "MDCTabBarView.h" | ||
#import "MaterialAppBar.h" | ||
#import "MaterialHeaderStackView.h" | ||
|
||
/** Snapshot tests for MDCTabBarView when integrating with other components. */ | ||
@interface MDCTabBarViewIntegrationSnapshotTests : MDCSnapshotTestCase | ||
|
||
/** The tab bar being tested and integrated. */ | ||
@property(nonatomic, strong) MDCTabBarView *tabBarView; | ||
|
||
@end | ||
|
||
@implementation MDCTabBarViewIntegrationSnapshotTests | ||
|
||
- (void)setUp { | ||
[super setUp]; | ||
|
||
// Uncomment below to recreate all the goldens (or add the following line to the specific | ||
// test you wish to recreate the golden for). | ||
// self.recordMode = YES; | ||
|
||
self.tabBarView = [[MDCTabBarView alloc] init]; | ||
|
||
UIImage *typicalIcon = [[UIImage mdc_testImageOfSize:CGSizeMake(24, 24) | ||
withStyle:MDCSnapshotTestImageStyleFramedX] | ||
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; | ||
|
||
UITabBarItem *item1 = [[UITabBarItem alloc] initWithTitle:@"One" image:typicalIcon tag:0]; | ||
UITabBarItem *item2 = [[UITabBarItem alloc] initWithTitle:@"Two" image:typicalIcon tag:1]; | ||
UITabBarItem *item3 = [[UITabBarItem alloc] initWithTitle:@"Three" image:typicalIcon tag:2]; | ||
self.tabBarView.items = @[ item1, item2, item3 ]; | ||
[self.tabBarView setSelectedItem:item3 animated:NO]; | ||
} | ||
|
||
- (void)tearDown { | ||
self.tabBarView = nil; | ||
|
||
[super tearDown]; | ||
} | ||
|
||
- (void)generateSnapshotAndVerifyForView:(UIView *)view { | ||
UIView *snapshotView = [view mdc_addToBackgroundView]; | ||
[self snapshotVerifyView:snapshotView]; | ||
} | ||
|
||
#pragma mark - MDCHeaderStackView Integration | ||
|
||
- (void)testTabBarViewInHeaderStackViewBottomBarWithWidthLessThanIntrinsicContentSize { | ||
// Given | ||
MDCHeaderStackView *headerStackView = [[MDCHeaderStackView alloc] init]; | ||
headerStackView.backgroundColor = UIColor.orangeColor; | ||
CGSize tabBarViewIntrinsicContentSize = self.tabBarView.intrinsicContentSize; | ||
|
||
// When | ||
headerStackView.bottomBar = self.tabBarView; | ||
headerStackView.bounds = CGRectMake(0, 0, tabBarViewIntrinsicContentSize.width - 50, | ||
tabBarViewIntrinsicContentSize.height + 50); | ||
[headerStackView layoutIfNeeded]; | ||
|
||
// Then | ||
[self generateSnapshotAndVerifyForView:headerStackView]; | ||
} | ||
|
||
- (void)testTabBarViewInHeaderStackViewBottomBarWithWidthEqualToIntrinsicContentSize { | ||
// Given | ||
MDCHeaderStackView *headerStackView = [[MDCHeaderStackView alloc] init]; | ||
headerStackView.backgroundColor = UIColor.orangeColor; | ||
CGSize tabBarViewIntrinsicContentSize = self.tabBarView.intrinsicContentSize; | ||
|
||
// When | ||
headerStackView.bottomBar = self.tabBarView; | ||
headerStackView.bounds = CGRectMake(0, 0, tabBarViewIntrinsicContentSize.width, | ||
tabBarViewIntrinsicContentSize.height + 50); | ||
[headerStackView layoutIfNeeded]; | ||
|
||
// Then | ||
[self generateSnapshotAndVerifyForView:headerStackView]; | ||
} | ||
|
||
- (void)testTabBarViewInHeaderStackViewBottomBarWithWidthGreaterThanIntrinsicContentSize { | ||
// Given | ||
MDCHeaderStackView *headerStackView = [[MDCHeaderStackView alloc] init]; | ||
headerStackView.backgroundColor = UIColor.orangeColor; | ||
CGSize tabBarViewIntrinsicContentSize = self.tabBarView.intrinsicContentSize; | ||
|
||
// When | ||
headerStackView.bottomBar = self.tabBarView; | ||
headerStackView.bounds = CGRectMake(0, 0, tabBarViewIntrinsicContentSize.width + 50, | ||
tabBarViewIntrinsicContentSize.height + 50); | ||
[headerStackView layoutIfNeeded]; | ||
|
||
// Then | ||
[self generateSnapshotAndVerifyForView:headerStackView]; | ||
} | ||
|
||
#pragma mark - MDCAppBarViewController Integration | ||
|
||
- (void)testTabBarViewInAppBarViewBottomBarWithWidthLessThanIntrinsicContentSize { | ||
// Given | ||
MDCAppBarViewController *appBarController = [[MDCAppBarViewController alloc] init]; | ||
appBarController.navigationBar.title = @"TabBarView"; | ||
appBarController.headerView.minimumHeight = 120; | ||
appBarController.headerView.backgroundColor = UIColor.orangeColor; | ||
CGSize tabBarViewIntrinsicContentSize = self.tabBarView.intrinsicContentSize; | ||
|
||
// When | ||
appBarController.headerStackView.bottomBar = self.tabBarView; | ||
appBarController.view.bounds = CGRectMake(0, 0, tabBarViewIntrinsicContentSize.width - 50, | ||
tabBarViewIntrinsicContentSize.height + 50); | ||
[appBarController.view layoutIfNeeded]; | ||
|
||
// Then | ||
[self generateSnapshotAndVerifyForView:appBarController.view]; | ||
} | ||
|
||
- (void)testTabBarViewInAppBarViewBottomBarWithWidthEqualToIntrinsicContentSize { | ||
// Given | ||
MDCAppBarViewController *appBarController = [[MDCAppBarViewController alloc] init]; | ||
appBarController.navigationBar.title = @"TabBarView"; | ||
appBarController.headerView.minimumHeight = 120; | ||
appBarController.headerView.backgroundColor = UIColor.orangeColor; | ||
CGSize tabBarViewIntrinsicContentSize = self.tabBarView.intrinsicContentSize; | ||
|
||
// When | ||
appBarController.headerStackView.bottomBar = self.tabBarView; | ||
appBarController.view.bounds = CGRectMake(0, 0, tabBarViewIntrinsicContentSize.width, | ||
tabBarViewIntrinsicContentSize.height + 50); | ||
[appBarController.view layoutIfNeeded]; | ||
|
||
// Then | ||
[self generateSnapshotAndVerifyForView:appBarController.view]; | ||
} | ||
|
||
- (void)testTabBarViewInAppBarViewBottomBarWithWidthGreaterThanIntrinsicContentSize { | ||
// Given | ||
MDCAppBarViewController *appBarController = [[MDCAppBarViewController alloc] init]; | ||
appBarController.navigationBar.title = @"TabBarView"; | ||
appBarController.headerView.minimumHeight = 120; | ||
appBarController.headerView.backgroundColor = UIColor.orangeColor; | ||
CGSize tabBarViewIntrinsicContentSize = self.tabBarView.intrinsicContentSize; | ||
|
||
// When | ||
appBarController.headerStackView.bottomBar = self.tabBarView; | ||
appBarController.view.bounds = CGRectMake(0, 0, tabBarViewIntrinsicContentSize.width + 50, | ||
tabBarViewIntrinsicContentSize.height + 50); | ||
[appBarController.view layoutIfNeeded]; | ||
|
||
// Then | ||
[self generateSnapshotAndVerifyForView:appBarController.view]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+13.3 KB
...TabBarViewInAppBarViewBottomBarWithWidthEqualToIntrinsicContentSize_11_2@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15.6 KB
...arViewInAppBarViewBottomBarWithWidthGreaterThanIntrinsicContentSize_11_2@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.8 KB
...abBarViewInAppBarViewBottomBarWithWidthLessThanIntrinsicContentSize_11_2@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.22 KB
...rViewInHeaderStackViewBottomBarWithWidthEqualToIntrinsicContentSize_11_2@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.4 KB
...wInHeaderStackViewBottomBarWithWidthGreaterThanIntrinsicContentSize_11_2@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.89 KB
...ViewInHeaderStackViewBottomBarWithWidthLessThanIntrinsicContentSize_11_2@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.03 KB
(89%)
...oldens/goldens_64/MDCTabBarViewSnapshotTests/testBottomDividerColor_11_2@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.04 KB
(89%)
.../MDCTabBarViewSnapshotTests/testCustomSelectionIndicatorStrokeColor_11_2@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.01 KB
(92%)
...t_test_goldens/goldens_64/MDCTabBarViewSnapshotTests/testCustomView_11_2@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.46 KB
(76%)
..._64/MDCTabBarViewSnapshotTests/testRemovingSelectedItemUpdatesStyle_11_2@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.26 KB
(88%)
..._test_goldens/goldens_64/MDCTabBarViewSnapshotTests/testRippleColor_11_2@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.04 KB
(89%)
...rViewSnapshotTests/testSelectionIndicatorStrokeColorResetsToDefault_11_2@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.04 KB
(89%)
...BarViewSnapshotTests/testSetTitleFontExplicitlyToNilUsesDefaultFont_11_2@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1 KB
(89%)
...64/MDCTabBarViewSnapshotTests/testSetTitleFontForExplicitItemStates_11_2@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-955 Bytes
(88%)
...ewSnapshotTests/testSetTitleFontForNormalStateAppliesToSelectedItem_11_2@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.