Skip to content
Permalink
Browse files

[BottomAppBar] add support for dynamic color. (#7975)

closes #7883.
  • Loading branch information
wenyuzhang666 committed Jul 22, 2019
1 parent 4d47e68 commit bc4a297012c66e9f82dd2cf4f76c83ca7882f185
@@ -83,6 +83,9 @@ - (void)commonMDCBottomAppBarViewInit {
[self addFloatingButton];
[self addBottomBarLayer];
[self addNavBar];

self.barTintColor = UIColor.whiteColor;
self.shadowColor = UIColor.blackColor;
}

- (void)addFloatingButton {
@@ -251,6 +254,9 @@ - (void)layoutSubviews {
self.floatingButton.center =
[self getFloatingButtonCenterPositionForAppBarWidth:CGRectGetWidth(self.bounds)];
[self renderPathBasedOnFloatingButtonVisibitlityAnimated:NO];

self.bottomBarLayer.fillColor = self.barTintColor.CGColor;
self.bottomBarLayer.shadowColor = self.shadowColor.CGColor;
}

- (UIEdgeInsets)mdc_safeAreaInsets {
@@ -384,13 +390,10 @@ - (void)setTrailingBarButtonItems:(NSArray<UIBarButtonItem *> *)trailingBarButto
}

- (void)setBarTintColor:(UIColor *)barTintColor {
_barTintColor = barTintColor;
_bottomBarLayer.fillColor = barTintColor.CGColor;
}

- (UIColor *)barTintColor {
return [UIColor colorWithCGColor:_bottomBarLayer.fillColor];
}

- (void)setLeadingBarItemsTintColor:(UIColor *)leadingBarItemsTintColor {
NSParameterAssert(leadingBarItemsTintColor);
if (!leadingBarItemsTintColor) {
@@ -416,13 +419,10 @@ - (UIColor *)trailingBarItemsTintColor {
}

- (void)setShadowColor:(UIColor *)shadowColor {
_shadowColor = shadowColor;
_bottomBarLayer.shadowColor = shadowColor.CGColor;
}

- (UIColor *)shadowColor {
return [UIColor colorWithCGColor:_bottomBarLayer.shadowColor];
}

#pragma mark TraitCollection

- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
@@ -163,4 +163,41 @@ - (void)testFloatingButtonElevationSecondaryRTL {
[self generateSnapshotAndVerifyForView:self.appBar];
}

- (void)testDynamicColorSupportOniOS13AndAbove {
#if defined(__IPHONE_13_0) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0)
if (@available(iOS 13.0, *)) {
// Given
UIColor *barTintDynamicColor =
[UIColor colorWithDynamicProvider:^(UITraitCollection *traitCollection) {
if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) {
return UIColor.blackColor;
} else {
return UIColor.purpleColor;
}
}];
UIColor *shadowDynamicColor =
[UIColor colorWithDynamicProvider:^(UITraitCollection *traitCollection) {
if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) {
return UIColor.blackColor;
} else {
return UIColor.blueColor;
}
}];
self.appBar.barTintColor = barTintDynamicColor;
self.appBar.shadowColor = shadowDynamicColor;

// When
self.appBar.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;

// Then
CGSize aSize = [self.appBar sizeThatFits:CGSizeMake(360, INFINITY)];
self.appBar.bounds = CGRectMake(0, 0, aSize.width, aSize.height);
[self.appBar layoutIfNeeded];
UIView *snapshotView =
[self.appBar mdc_addToBackgroundViewWithInsets:UIEdgeInsetsMake(50, 50, 50, 50)];
[self snapshotVerifyViewForIOS13:snapshotView];
}
#endif
}

@end
Binary file not shown.

0 comments on commit bc4a297

Please sign in to comment.
You can’t perform that action at this time.