Create default light and dark color schemes for MDCSlider
MODIFY
MaterialComponents.podspec
MaterialComponents.podspec
@@ -427,6 +427,7 @@ Pod::Spec.new do |mdc|
spec.ios.deployment_target = '8.0'
spec.public_header_files = "components/#{component.base_name}/src/#{spec.base_name}/*.h"
spec.source_files = "components/#{component.base_name}/src/#{spec.base_name}/*.{h,m}"
+ spec.dependency "MaterialComponents/Palettes"
spec.dependency "MaterialComponents/Slider/Component"
spec.dependency "MaterialComponents/Themes"
end

MODIFY
components/Slider/src/ColorThemer/MDCSliderColorThemer.h
components/Slider/src/ColorThemer/MDCSliderColorThemer.h
@param colorScheme The color scheme to apply to MDCSlider.
@param slider A MDCSlider instance to apply a color scheme.
*/
-+ (void)applyColorScheme:(NSObject<MDCColorScheme> *)colorScheme
- toSlider:(MDCSlider *)slider;
++ (void)applyColorScheme:(nonnull NSObject<MDCColorScheme> *)colorScheme
+ toSlider:(nonnull MDCSlider *)slider;
+
+/**
+ * A default color scheme for sliders displayed on light backgrounds. The primary color is blue and
+ * the primary light and primary dark are gray.
+ */
++ (nonnull MDCBasicColorScheme *)defaultSliderLightColorScheme;
+
+/**
+ * A default color scheme for sliders displayed on dark backgrounds. The primary color is blue and
+ * the primary light and primary dark are white.
+ */
++ (nonnull MDCBasicColorScheme *)defaultSliderDarkColorScheme;
+
@end

MODIFY
components/Slider/src/ColorThemer/MDCSliderColorThemer.m
components/Slider/src/ColorThemer/MDCSliderColorThemer.m
*/
#import "MDCSliderColorThemer.h"
+#import "MaterialPalettes.h"
+
+static const CGFloat kSliderThemerLightAlpha = 0.26f;
+static const CGFloat kSliderThemerDarkAlpha = 0.3f;
@implementation MDCSliderColorThemer
toSlider:(MDCSlider *)slider {
slider.trackBackgroundColor = colorScheme.primaryLightColor;
slider.color = colorScheme.primaryColor;
+ slider.disabledColor = colorScheme.primaryDarkColor;
+}
+
+#pragma mark - Default color schemes
+
++ (MDCBasicColorScheme *)defaultSliderLightColorScheme {
+ UIColor *lightTrackOffColor =
+ [[UIColor whiteColor] colorWithAlphaComponent:kSliderThemerLightAlpha];
+ UIColor *lightDisabledColor =
+ [[UIColor whiteColor] colorWithAlphaComponent:kSliderThemerLightAlpha];
+
+ MDCBasicColorScheme *lightScheme =
+ [[MDCBasicColorScheme alloc] initWithPrimaryColor:MDCPalette.bluePalette.tint500
+ primaryLightColor:lightTrackOffColor
+ primaryDarkColor:lightDisabledColor];
+ return lightScheme;
+}
+
++ (MDCBasicColorScheme *)defaultSliderDarkColorScheme {
+ UIColor *darkTrackOffColor =
+ [[UIColor whiteColor] colorWithAlphaComponent:kSliderThemerDarkAlpha];
+ UIColor *darkDisabledColor =
+ [[UIColor whiteColor] colorWithAlphaComponent:kSliderThemerDarkAlpha];
+
+ MDCBasicColorScheme *darkScheme =
+ [[MDCBasicColorScheme alloc] initWithPrimaryColor:MDCPalette.bluePalette.tint500
+ primaryLightColor:darkTrackOffColor
+ primaryDarkColor:darkDisabledColor];
+ return darkScheme;
}
@end

MODIFY
components/Slider/src/MDCSlider.h
components/Slider/src/MDCSlider.h
@@ -48,6 +48,13 @@ IB_DESIGNABLE
*/
@property(nonatomic, strong, null_resettable) UIColor *color;
+/**
+ The color of the cursor (thumb) and track while the slider is disabled.
+
+ Default color is gray.
+ */
+@property(nonatomic, strong, null_resettable) UIColor *disabledColor;
+
/*
The color of the unfilled track that the cursor moves along (right side).

MODIFY
components/Slider/src/MDCSlider.m
components/Slider/src/MDCSlider.m
@@ -98,13 +98,23 @@ static inline UIColor *MDCColorFromRGB(uint32_t rgbValue) {
- (void)setTrackBackgroundColor:(UIColor *)trackBackgroundColor {
_thumbTrack.trackOffColor =
trackBackgroundColor ? trackBackgroundColor : [[self class] defaultTrackOffColor];
- ;
}
- (UIColor *)trackBackgroundColor {
return _thumbTrack.trackOffColor;
}
+- (void)setDisabledColor:(UIColor *)disabledColor {
+ _thumbTrack.trackDisabledColor =
+ disabledColor ?: [[self class] defaultDisabledColor];
+ _thumbTrack.thumbDisabledColor =
+ disabledColor ?: [[self class] defaultDisabledColor];
+}
+
+- (UIColor *)disabledColor {
+ return _thumbTrack.trackDisabledColor;
+}
+
- (void)setColor:(UIColor *)color {
_thumbTrack.primaryColor = color ? color : [[self class] defaultColor];
}

MODIFY
components/Slider/tests/unit/SliderTests.m
components/Slider/tests/unit/SliderTests.m
@@ -336,6 +336,31 @@ static inline UIColor *MDCColorFromRGB(uint32_t rgbValue) {
XCTAssertEqualObjects(actualColor, expectedColor);
}
+- (void)testDisabledColor {
+ // Given
+ MDCSlider *slider = [[MDCSlider alloc] init];
+
+ // When
+ UIColor *actualColor = slider.disabledColor;
+
+ // Then
+ UIColor *expectedColor = [[UIColor blackColor] colorWithAlphaComponent:0.26f];
+ XCTAssertEqualObjects(actualColor, expectedColor);
+}
+
+- (void)testDisabledColorNullRestable {
+ // Given
+ MDCSlider *slider = [[MDCSlider alloc] init];
+
+ // When
+ slider.trackBackgroundColor = nil;
+
+ // Then
+ UIColor *actualColor = slider.trackBackgroundColor;
+ UIColor *expectedColor = [[UIColor blackColor] colorWithAlphaComponent:0.26f];
+ XCTAssertEqualObjects(actualColor, expectedColor);
+}
+
#pragma mark numeric value label
- (void)testNumericValueLabelString {

Create default light and dark color schemes for MDCSlider (#2362)