[TextFields] Adding the expected opacities to color themer.
* Adding the expected opacities to color themer for textfields.
Updated tests.
* making sure precision is defined for constant values.
* define the type of values to be float (warning as error fix)
MODIFY
components/TextFields/src/ColorThemer/MDCTextFieldColorThemer.m
components/TextFields/src/ColorThemer/MDCTextFieldColorThemer.m
+ (void)applySemanticColorScheme:(id<MDCColorScheming>)colorScheme
toTextInputController:(id<MDCTextInputController>)textInputController {
+ UIColor *onSurface87Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.87f];
+ UIColor *onSurface60Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.60f];
textInputController.activeColor = colorScheme.primaryColor;
textInputController.errorColor = colorScheme.errorColor;
- textInputController.normalColor = colorScheme.onSurfaceColor;
- textInputController.inlinePlaceholderColor = colorScheme.onSurfaceColor;
- textInputController.trailingUnderlineLabelTextColor = colorScheme.onSurfaceColor;
- textInputController.leadingUnderlineLabelTextColor = colorScheme.onSurfaceColor;
+ textInputController.normalColor = onSurface87Opacity;
+ textInputController.inlinePlaceholderColor = onSurface60Opacity;
+ textInputController.trailingUnderlineLabelTextColor = onSurface60Opacity;
+ textInputController.leadingUnderlineLabelTextColor = onSurface60Opacity;
if ([textInputController
conformsToProtocol:@protocol(MDCTextInputControllerFloatingPlaceholder)]) {
if ([textInputControllerFloatingPlaceholder
respondsToSelector:@selector(setFloatingPlaceholderNormalColor:)]) {
- textInputControllerFloatingPlaceholder.floatingPlaceholderNormalColor =
- colorScheme.primaryColor;
+ UIColor *primary87Opacity = [colorScheme.primaryColor colorWithAlphaComponent:0.87f];
+ textInputControllerFloatingPlaceholder.floatingPlaceholderNormalColor = primary87Opacity;
}
}
}
+ (void)applySemanticColorScheme:(nonnull id<MDCColorScheming>)colorScheme
toTextInput:(nonnull id<MDCTextInput>)textInput {
+ UIColor *onSurface87Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.87f];
+ UIColor *onSurface60Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.60f];
textInput.cursorColor = colorScheme.primaryColor;
- textInput.textColor = colorScheme.onSurfaceColor;
- textInput.placeholderLabel.textColor = colorScheme.onSurfaceColor;
- textInput.trailingUnderlineLabel.textColor = colorScheme.onSurfaceColor;
- textInput.leadingUnderlineLabel.textColor = colorScheme.onSurfaceColor;
+ textInput.textColor = onSurface87Opacity;
+ textInput.placeholderLabel.textColor = onSurface60Opacity;
+ textInput.trailingUnderlineLabel.textColor = onSurface60Opacity;
+ textInput.leadingUnderlineLabel.textColor = onSurface60Opacity;
}
// TODO: (larche) Drop this if defined and the pragmas when we drop Xcode 8 support.
#endif
+ (void)applySemanticColorScheme:(id<MDCColorScheming>)colorScheme
toAllTextInputControllersOfClass:(Class<MDCTextInputController>)textInputControllerClass {
+ UIColor *onSurface87Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.87f];
+ UIColor *onSurface60Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.60f];
[textInputControllerClass setActiveColorDefault:colorScheme.primaryColor];
[textInputControllerClass setErrorColorDefault:colorScheme.errorColor];
- [textInputControllerClass setNormalColorDefault:colorScheme.onSurfaceColor];
- [textInputControllerClass setInlinePlaceholderColorDefault:colorScheme.onSurfaceColor];
- [textInputControllerClass setTrailingUnderlineLabelTextColorDefault:colorScheme.onSurfaceColor];
- [textInputControllerClass setLeadingUnderlineLabelTextColorDefault:colorScheme.onSurfaceColor];
+ [textInputControllerClass setNormalColorDefault:onSurface87Opacity];
+ [textInputControllerClass setInlinePlaceholderColorDefault:onSurface60Opacity];
+ [textInputControllerClass setTrailingUnderlineLabelTextColorDefault:onSurface60Opacity];
+ [textInputControllerClass setLeadingUnderlineLabelTextColorDefault:onSurface60Opacity];
if ([textInputControllerClass
conformsToProtocol:@protocol(MDCTextInputControllerFloatingPlaceholder)]) {
Class<MDCTextInputControllerFloatingPlaceholder> textInputControllerFloatingPlaceholderClass =
(Class<MDCTextInputControllerFloatingPlaceholder>)textInputControllerClass;
+ UIColor *primary87Opacity = [colorScheme.primaryColor colorWithAlphaComponent:0.87f];
[textInputControllerFloatingPlaceholderClass
- setFloatingPlaceholderNormalColorDefault:colorScheme.primaryColor];
+ setFloatingPlaceholderNormalColorDefault:primary87Opacity];
}
}
#if !defined(__IPHONE_11_0)

MODIFY
components/TextFields/tests/unit/TextFieldColorThemerTests.m
components/TextFields/tests/unit/TextFieldColorThemerTests.m
- (void)testDefaultValuesAreSet {
MDCSemanticColorScheme *colorScheme = [[MDCSemanticColorScheme alloc] init];
+ UIColor *primary87Opacity = [colorScheme.primaryColor colorWithAlphaComponent:0.87f];
+ UIColor *onSurface87Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.87f];
+ UIColor *onSurface60Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.60f];
+
XCTAssertEqualObjects(MDCTextInputControllerBase.activeColorDefault, colorScheme.primaryColor);
XCTAssertEqualObjects(MDCTextInputControllerBase.errorColorDefault, colorScheme.errorColor);
- XCTAssertEqualObjects(MDCTextInputControllerBase.normalColorDefault, colorScheme.onSurfaceColor);
+ XCTAssertEqualObjects(MDCTextInputControllerBase.normalColorDefault, onSurface87Opacity);
XCTAssertEqualObjects(MDCTextInputControllerBase.inlinePlaceholderColorDefault,
- colorScheme.onSurfaceColor);
+ onSurface60Opacity);
XCTAssertEqualObjects(MDCTextInputControllerBase.trailingUnderlineLabelTextColorDefault,
- colorScheme.onSurfaceColor);
+ onSurface60Opacity);
XCTAssertEqualObjects(MDCTextInputControllerBase.leadingUnderlineLabelTextColorDefault,
- colorScheme.onSurfaceColor);
+ onSurface60Opacity);
XCTAssertEqualObjects(MDCTextInputControllerBase.floatingPlaceholderNormalColorDefault,
- colorScheme.primaryColor);
+ primary87Opacity);
XCTAssertEqualObjects(MDCTextInputControllerFullWidth.errorColorDefault, colorScheme.errorColor);
XCTAssertEqualObjects(MDCTextInputControllerFullWidth.inlinePlaceholderColorDefault,
- colorScheme.onSurfaceColor);
+ onSurface60Opacity);
XCTAssertEqualObjects(MDCTextInputControllerFullWidth.trailingUnderlineLabelTextColorDefault,
- colorScheme.onSurfaceColor);
+ onSurface60Opacity);
}
- (void)testInstanceColorValuesAreSet {
+ MDCSemanticColorScheme *colorScheme = [[MDCSemanticColorScheme alloc] init];
+ colorScheme.primaryColor = [UIColor blueColor];
+ colorScheme.errorColor = [UIColor yellowColor];
+ colorScheme.onSurfaceColor = [UIColor greenColor];
+ colorScheme.errorColor = [UIColor redColor];
+
+ UIColor *onSurface87Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.87f];
+ UIColor *onSurface60Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.60f];
+
MDCTextField *textField = [[MDCTextField alloc] initWithFrame:CGRectZero];
MDCTextField *baseTextField = [[MDCTextField alloc] initWithFrame:CGRectZero];
MDCTextField *fullWidthTextField = [[MDCTextField alloc] initWithFrame:CGRectZero];
MDCTextInputControllerFullWidth *fullWidthInputController =
[[MDCTextInputControllerFullWidth alloc] initWithTextInput:fullWidthTextField];
- MDCSemanticColorScheme *colorScheme = [[MDCSemanticColorScheme alloc] init];
- colorScheme.primaryColor = [UIColor blueColor];
- colorScheme.errorColor = [UIColor yellowColor];
- colorScheme.onSurfaceColor = [UIColor greenColor];
- colorScheme.errorColor = [UIColor redColor];
[MDCTextFieldColorThemer applySemanticColorScheme:colorScheme
toTextInput:textField];
XCTAssertEqualObjects(textField.cursorColor, colorScheme.primaryColor);
- XCTAssertEqualObjects(textField.textColor, colorScheme.onSurfaceColor);
- XCTAssertEqualObjects(textField.placeholderLabel.textColor, colorScheme.onSurfaceColor);
- XCTAssertEqualObjects(textField.trailingUnderlineLabel.textColor, colorScheme.onSurfaceColor);
- XCTAssertEqualObjects(textField.leadingUnderlineLabel.textColor, colorScheme.onSurfaceColor);
+ XCTAssertEqualObjects(textField.textColor, onSurface87Opacity);
+ XCTAssertEqualObjects(textField.placeholderLabel.textColor, onSurface60Opacity);
+ XCTAssertEqualObjects(textField.trailingUnderlineLabel.textColor, onSurface60Opacity);
+ XCTAssertEqualObjects(textField.leadingUnderlineLabel.textColor, onSurface60Opacity);
[MDCTextFieldColorThemer applySemanticColorScheme:colorScheme
toTextInputController:baseInputController];
XCTAssertEqualObjects(baseInputController.activeColor, colorScheme.primaryColor);
XCTAssertEqualObjects(baseInputController.errorColor, colorScheme.errorColor);
- XCTAssertEqualObjects(baseInputController.normalColor, colorScheme.onSurfaceColor);
- XCTAssertEqualObjects(baseInputController.inlinePlaceholderColor, colorScheme.onSurfaceColor);
- XCTAssertEqualObjects(baseInputController.trailingUnderlineLabelTextColor,
- colorScheme.onSurfaceColor);
- XCTAssertEqualObjects(baseInputController.leadingUnderlineLabelTextColor,
- colorScheme.onSurfaceColor);
+ XCTAssertEqualObjects(baseInputController.normalColor, onSurface87Opacity);
+ XCTAssertEqualObjects(baseInputController.inlinePlaceholderColor, onSurface60Opacity);
+ XCTAssertEqualObjects(baseInputController.trailingUnderlineLabelTextColor, onSurface60Opacity);
+ XCTAssertEqualObjects(baseInputController.leadingUnderlineLabelTextColor, onSurface60Opacity);
[MDCTextFieldColorThemer applySemanticColorScheme:colorScheme
toTextInputController:fullWidthInputController];
XCTAssertEqualObjects(fullWidthInputController.errorColor, colorScheme.errorColor);
- XCTAssertEqualObjects(fullWidthInputController.inlinePlaceholderColor,
- colorScheme.onSurfaceColor);
+ XCTAssertEqualObjects(fullWidthInputController.inlinePlaceholderColor, onSurface60Opacity);
XCTAssertEqualObjects(fullWidthInputController.trailingUnderlineLabelTextColor,
- colorScheme.onSurfaceColor);
+ onSurface60Opacity);
}
@end

[TextFields] Adding the expected opacities to color themer. (#3347)

* Adding the expected opacities to color themer for textfields.
Updated tests.

* making sure precision is defined for constant values.

* define the type of values to be float (warning as error fix)