[chips] Updating chips color Themer.
* updating chips color Themer.
* missing new line.
* tests are updated.
define the constant as floating point to avoid build erros.
MODIFY
components/Chips/src/ColorThemer/MDCChipViewColorThemer.m
components/Chips/src/ColorThemer/MDCChipViewColorThemer.m
/*
Copyright 2018-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
[MDCChipViewColorThemer resetUIControlStatesForChipTheming:chipView];
UIColor *onSurface12Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.12f];
UIColor *onSurface87Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.87f];
+ UIColor *onSurface16Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.16f];
+
UIColor *backgroundColor =
[MDCSemanticColorScheme blendColor:onSurface12Opacity
withBackgroundColor:colorScheme.surfaceColor];
+ UIColor *selectedBackgroundColor =
+ [MDCSemanticColorScheme blendColor:onSurface12Opacity
+ withBackgroundColor:backgroundColor];
UIColor *textColor =
[MDCSemanticColorScheme blendColor:onSurface87Opacity
- withBackgroundColor:colorScheme.surfaceColor];
+ withBackgroundColor:backgroundColor];
+ UIColor *selectedTextColor =
+ [MDCSemanticColorScheme blendColor:onSurface87Opacity
+ withBackgroundColor:selectedBackgroundColor];
+
+ [chipView setInkColor:onSurface16Opacity forState:UIControlStateNormal];
[chipView setTitleColor:textColor forState:UIControlStateNormal];
[chipView setBackgroundColor:backgroundColor forState:UIControlStateNormal];
+
+ [chipView setTitleColor:selectedTextColor forState:UIControlStateSelected];
+ [chipView setBackgroundColor:selectedBackgroundColor forState:UIControlStateSelected];
+
+ [chipView setTitleColor:[textColor colorWithAlphaComponent:0.38f]
+ forState:UIControlStateDisabled];
+ [chipView setBackgroundColor:[backgroundColor colorWithAlphaComponent:0.38f]
+ forState:UIControlStateDisabled];
}
+ (void)applySemanticColorScheme:(nonnull id<MDCColorScheming>)colorScheme
[MDCChipViewColorThemer resetUIControlStatesForChipTheming:strokedChipView];
UIColor *onSurface12Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.12f];
UIColor *onSurface87Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.87f];
+ UIColor *onSurface16Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.16f];
+ UIColor *selectedBackgroundColor =
+ [MDCSemanticColorScheme blendColor:onSurface12Opacity
+ withBackgroundColor:colorScheme.surfaceColor];
UIColor *borderColor =
[MDCSemanticColorScheme blendColor:onSurface12Opacity
withBackgroundColor:colorScheme.surfaceColor];
UIColor *textColor =
[MDCSemanticColorScheme blendColor:onSurface87Opacity
withBackgroundColor:colorScheme.surfaceColor];
+ UIColor *selectedTextColor =
+ [MDCSemanticColorScheme blendColor:onSurface87Opacity
+ withBackgroundColor:selectedBackgroundColor];
+
+ [strokedChipView setInkColor:onSurface16Opacity forState:UIControlStateNormal];
[strokedChipView setTitleColor:textColor forState:UIControlStateNormal];
[strokedChipView setBackgroundColor:colorScheme.surfaceColor forState:UIControlStateNormal];
[strokedChipView setBorderColor:borderColor forState:UIControlStateNormal];
+
+ [strokedChipView setTitleColor:selectedTextColor forState:UIControlStateSelected];
+ [strokedChipView setBackgroundColor:selectedBackgroundColor forState:UIControlStateSelected];
+ [strokedChipView setBorderColor:[UIColor clearColor] forState:UIControlStateSelected];
+
+ [strokedChipView setTitleColor:[textColor colorWithAlphaComponent:0.38f]
+ forState:UIControlStateDisabled];
+ [strokedChipView setBackgroundColor:[colorScheme.surfaceColor colorWithAlphaComponent:0.38f]
+ forState:UIControlStateDisabled];
+ [strokedChipView setBorderColor:[borderColor colorWithAlphaComponent:0.38f]
+ forState:UIControlStateDisabled];
}
+ (void)resetUIControlStatesForChipTheming:(nonnull MDCChipView *)chipView {

MODIFY
components/Chips/tests/unit/ChipViewColorThemerTests.m
components/Chips/tests/unit/ChipViewColorThemerTests.m
- (void)testInputChipViewColorThemer {
[MDCChipViewColorThemer applySemanticColorScheme:self.colorScheme toChipView:self.chip];
- [self verifyColorsWithColorScheme:self.colorScheme ChipView:self.chip stroked:NO];
+ UIColor *onSurface12Opacity = [self.colorScheme.onSurfaceColor colorWithAlphaComponent:0.12f];
+ UIColor *onSurface87Opacity = [self.colorScheme.onSurfaceColor colorWithAlphaComponent:0.87f];
+ UIColor *onSurface16Opacity = [self.colorScheme.onSurfaceColor colorWithAlphaComponent:0.16f];
+
+ UIColor *backgroundColor =
+ [MDCSemanticColorScheme blendColor:onSurface12Opacity
+ withBackgroundColor:self.colorScheme.surfaceColor];
+ UIColor *selectedBackgroundColor =
+ [MDCSemanticColorScheme blendColor:onSurface12Opacity
+ withBackgroundColor:backgroundColor];
+ UIColor *textColor =
+ [MDCSemanticColorScheme blendColor:onSurface87Opacity
+ withBackgroundColor:backgroundColor];
+ UIColor *selectedTextColor =
+ [MDCSemanticColorScheme blendColor:onSurface87Opacity
+ withBackgroundColor:selectedBackgroundColor];
+
+ XCTAssertEqualObjects([self.chip inkColorForState:UIControlStateNormal], onSurface16Opacity);
+ XCTAssertEqualObjects([self.chip titleColorForState:UIControlStateNormal], textColor);
+ XCTAssertEqualObjects([self.chip backgroundColorForState:UIControlStateNormal], backgroundColor);
+ XCTAssertEqualObjects([self.chip backgroundColorForState:UIControlStateSelected],
+ selectedBackgroundColor);
+ XCTAssertEqualObjects([self.chip titleColorForState:UIControlStateSelected], selectedTextColor);
+ XCTAssertEqualObjects([self.chip backgroundColorForState:UIControlStateDisabled],
+ [backgroundColor colorWithAlphaComponent:0.38f]);
+ XCTAssertEqualObjects([self.chip titleColorForState:UIControlStateDisabled],
+ [textColor colorWithAlphaComponent:0.38f]);
+
}
- (void)testStrokedChipViewColorThemer {
[MDCChipViewColorThemer applySemanticColorScheme:self.colorScheme toStrokedChipView:self.chip];
- [self verifyColorsWithColorScheme:self.colorScheme ChipView:self.chip stroked:YES];
-}
-
-- (void)verifyColorsWithColorScheme:(MDCSemanticColorScheme *)colorScheme
- ChipView:(MDCChipView *)chipView
- stroked:(BOOL)isStroked {
- UIColor *onSurface12Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.12f];
- UIColor *onSurface87Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.87f];
-
- UIColor *backgroundColor =
+ UIColor *onSurface12Opacity = [self.colorScheme.onSurfaceColor colorWithAlphaComponent:0.12f];
+ UIColor *onSurface87Opacity = [self.colorScheme.onSurfaceColor colorWithAlphaComponent:0.87f];
+ UIColor *onSurface16Opacity = [self.colorScheme.onSurfaceColor colorWithAlphaComponent:0.16f];
+ UIColor *selectedBackgroundColor =
[MDCSemanticColorScheme blendColor:onSurface12Opacity
- withBackgroundColor:colorScheme.surfaceColor];
+ withBackgroundColor:self.colorScheme.surfaceColor];
+ UIColor *borderColor =
+ [MDCSemanticColorScheme blendColor:onSurface12Opacity
+ withBackgroundColor:self.colorScheme.surfaceColor];
UIColor *textColor =
[MDCSemanticColorScheme blendColor:onSurface87Opacity
- withBackgroundColor:colorScheme.surfaceColor];
-
- XCTAssertEqualObjects([chipView titleColorForState:UIControlStateNormal], textColor);
- if (!isStroked) {
- XCTAssertEqualObjects([chipView backgroundColorForState:UIControlStateNormal], backgroundColor);
- } else {
- XCTAssertEqualObjects([chipView backgroundColorForState:UIControlStateNormal],
- colorScheme.surfaceColor);
- XCTAssertEqualObjects([chipView borderColorForState:UIControlStateNormal],
- backgroundColor);
- }
+ withBackgroundColor:self.colorScheme.surfaceColor];
+ UIColor *selectedTextColor =
+ [MDCSemanticColorScheme blendColor:onSurface87Opacity
+ withBackgroundColor:selectedBackgroundColor];
+
+ XCTAssertEqualObjects([self.chip borderColorForState:UIControlStateNormal], borderColor);
+ XCTAssertEqualObjects([self.chip borderColorForState:UIControlStateSelected],
+ [UIColor clearColor]);
+ XCTAssertEqualObjects([self.chip inkColorForState:UIControlStateNormal], onSurface16Opacity);
+ XCTAssertEqualObjects([self.chip titleColorForState:UIControlStateNormal], textColor);
+ XCTAssertEqualObjects([self.chip backgroundColorForState:UIControlStateNormal],
+ self.colorScheme.surfaceColor);
+ XCTAssertEqualObjects([self.chip backgroundColorForState:UIControlStateSelected],
+ selectedBackgroundColor);
+ XCTAssertEqualObjects([self.chip titleColorForState:UIControlStateSelected], selectedTextColor);
+ XCTAssertEqualObjects([self.chip backgroundColorForState:UIControlStateDisabled],
+ [self.colorScheme.surfaceColor colorWithAlphaComponent:0.38f]);
+ XCTAssertEqualObjects([self.chip titleColorForState:UIControlStateDisabled],
+ [textColor colorWithAlphaComponent:0.38f]);
}
@end

[chips] Updating chips color Themer. (#3452)

* updating chips color Themer.

* missing new line.

* tests are updated.
define the constant as floating point to avoid build erros.

https://github.com/material-components/material-components-ios/pull/3452