Skip to content

Commit

Permalink
Update the MDCBottomDrawerViewController MDC themer to use dynamic co…
Browse files Browse the repository at this point in the history
…lors.

PiperOrigin-RevId: 321004879
  • Loading branch information
jakerockland authored and material-automation committed Jul 13, 2020
1 parent 98f43fa commit dde7180
Showing 1 changed file with 24 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
// limitations under the License.

#import "MaterialElevation.h"
#import "MaterialNavigationDrawer.h"
#import "MDCBottomDrawerViewController+MaterialTheming.h"
#import "UIColor+MaterialDynamic.h"
#import "MaterialColorScheme.h"

static const CGFloat kCollapsedCornerRadius = 8.0f;
static const CGFloat kFullScreenCornerRadius = 0.0f;
Expand All @@ -39,57 +36,46 @@ - (void)applyThemeWithScheme:(id<MDCContainerScheming>)scheme

- (void)applyColorThemeWithColorScheme:(id<MDCColorScheming>)colorScheme
applyToTrackingScrollView:(BOOL)applyToTrackingScrollView {
[MDCBottomDrawerViewController mdc_setBackgroundColorForBottomDrawer:self
applyToTrackingScrollView:applyToTrackingScrollView
withScheme:colorScheme];
[MDCBottomDrawerViewController
mdc_setResolvedBackgroundColorForBottomDrawer:self
applyToTrackingScrollView:applyToTrackingScrollView
withScheme:colorScheme];
if (colorScheme.elevationOverlayEnabledForDarkMode) {
self.mdc_elevationDidChangeBlock = ^(id<MDCElevatable> _Nonnull object,
CGFloat absoluteElevation) {
if ([object isKindOfClass:[MDCBottomDrawerViewController class]]) {
MDCBottomDrawerViewController *bottomDrawer = (MDCBottomDrawerViewController *)object;
[MDCBottomDrawerViewController
mdc_setBackgroundColorForBottomDrawer:bottomDrawer
applyToTrackingScrollView:applyToTrackingScrollView
withScheme:colorScheme];
mdc_setResolvedBackgroundColorForBottomDrawer:bottomDrawer
applyToTrackingScrollView:applyToTrackingScrollView
withScheme:colorScheme];
}
};
#if defined(__IPHONE_13_0) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0)
if (@available(iOS 13.0, *)) {
self.traitCollectionDidChangeBlock = ^(MDCBottomDrawerViewController *_Nonnull bottomDrawer,
UITraitCollection *_Nullable previousTraitCollection) {
if ([bottomDrawer.traitCollection
hasDifferentColorAppearanceComparedToTraitCollection:previousTraitCollection]) {
[MDCBottomDrawerViewController
mdc_setResolvedBackgroundColorForBottomDrawer:bottomDrawer
applyToTrackingScrollView:applyToTrackingScrollView
withScheme:colorScheme];
}
};
}
#endif
}
self.scrimColor = [colorScheme.onSurfaceColor colorWithAlphaComponent:kScrimAlpha];
self.topHandleColor = [colorScheme.onSurfaceColor colorWithAlphaComponent:kTopHandleAlpha];
}

+ (void)mdc_setBackgroundColorForBottomDrawer:(MDCBottomDrawerViewController *)bottomDrawer
applyToTrackingScrollView:(BOOL)applyToTrackingScrollView
withScheme:(id<MDCColorScheming>)scheme {
+ (void)mdc_setResolvedBackgroundColorForBottomDrawer:(MDCBottomDrawerViewController *)bottomDrawer
applyToTrackingScrollView:(BOOL)applyToTrackingScrollView
withScheme:(id<MDCColorScheming>)scheme {
UIColor *backgroundColor = [scheme.backgroundColor
mdc_resolvedColorWithTraitCollection:bottomDrawer.traitCollection
elevation:bottomDrawer.view.mdc_absoluteElevation];
#if defined(__IPHONE_13_0) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0)
if (@available(iOS 13.0, *)) {
// Note that UITraitCollection with explicit `traitCollectionWithUserInterfaceStyle:` must
// come after `bottomDrawer.traitCollection` for the `userInterfaceStyle` to be properly
// overwritten.
UITraitCollection *darkTraitCollection =
[UITraitCollection traitCollectionWithTraitsFromCollections:@[
bottomDrawer.traitCollection,
[UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark]
]];
UITraitCollection *lightTraitCollection =
[UITraitCollection traitCollectionWithTraitsFromCollections:@[
bottomDrawer.traitCollection,
[UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleLight]
]];
UIColor *darkBackgroundColor = [scheme.backgroundColor
mdc_resolvedColorWithTraitCollection:darkTraitCollection
elevation:bottomDrawer.view.mdc_absoluteElevation];
UIColor *lightBackgroundColor = [scheme.backgroundColor
mdc_resolvedColorWithTraitCollection:lightTraitCollection
elevation:bottomDrawer.view.mdc_absoluteElevation];
backgroundColor = [UIColor colorWithUserInterfaceStyleDarkColor:darkBackgroundColor
defaultColor:lightBackgroundColor];
}
#endif

bottomDrawer.headerViewController.view.backgroundColor = backgroundColor;
bottomDrawer.contentViewController.view.backgroundColor = backgroundColor;
if (applyToTrackingScrollView) {
Expand Down

0 comments on commit dde7180

Please sign in to comment.