-
Notifications
You must be signed in to change notification settings - Fork 946
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TextFields] Add a Theming extension for MDCTextInputControllerFilled. (
#6870) Includes support for theming MDCTextInputControllerFilled and tests of the behavior. Part of https://github.com/material-components/material-components-ios/issues/6836
- Loading branch information
Showing
8 changed files
with
211 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
components/TextFields/src/Theming/MDCTextInputControllerFilled+MaterialTheming.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2019-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 | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#import <MaterialComponents/MaterialTextFields.h> | ||
#import <MaterialComponentsBeta/MaterialContainerScheme.h> | ||
|
||
/** | ||
This category is used to style MDCTextInputControllerFilled instances to a specific Material style | ||
which can be found within the | ||
[Material Guidelines](https://material.io/design/components/text-fields.html). | ||
*/ | ||
@interface MDCTextInputControllerFilled (MaterialTheming) | ||
|
||
/** | ||
Applies a container scheme to this instance. | ||
@param scheme A container scheme instance containing any desired customizations to the theming | ||
system. | ||
*/ | ||
- (void)applyThemeWithScheme:(nonnull id<MDCContainerScheming>)scheme; | ||
|
||
@end |
39 changes: 39 additions & 0 deletions
39
components/TextFields/src/Theming/MDCTextInputControllerFilled+MaterialTheming.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2019-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 | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#import "MDCTextInputControllerFilled+MaterialTheming.h" | ||
|
||
#import <MaterialComponents/MaterialTextFields+ColorThemer.h> | ||
#import <MaterialComponents/MaterialTextFields+TypographyThemer.h> | ||
|
||
@implementation MDCTextInputControllerFilled (MaterialTheming) | ||
|
||
- (void)applyThemeWithScheme:(nonnull id<MDCContainerScheming>)scheme { | ||
// Color | ||
[self applyColorThemeWithScheme:scheme.colorScheme]; | ||
|
||
// Typography | ||
[self applyTypographyThemeWithScheme:scheme.typographyScheme]; | ||
} | ||
|
||
- (void)applyColorThemeWithScheme:(nonnull id<MDCColorScheming>)colorScheme { | ||
[MDCFilledTextFieldColorThemer applySemanticColorScheme:colorScheme | ||
toTextInputControllerFilled:self]; | ||
} | ||
|
||
- (void)applyTypographyThemeWithScheme:(nonnull id<MDCTypographyScheming>)typographyScheme { | ||
[MDCTextFieldTypographyThemer applyTypographyScheme:typographyScheme toTextInputController:self]; | ||
} | ||
|
||
@end |
15 changes: 15 additions & 0 deletions
15
components/TextFields/src/Theming/MaterialTextFields+Theming.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright 2019-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 | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#import "MDCTextInputControllerFilled+MaterialTheming.h" |
76 changes: 76 additions & 0 deletions
76
components/TextFields/tests/unit/Theming/TextFieldsMaterialThemingTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright 2019-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 | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import XCTest | ||
|
||
import MaterialComponents.MaterialTextFields | ||
import MaterialComponents.MaterialColorScheme | ||
import MaterialComponents.MaterialTypographyScheme | ||
import MaterialComponentsBeta.MaterialContainerScheme | ||
import MaterialComponentsBeta.MaterialTextFields_Theming | ||
|
||
class TextFieldsMaterialThemingTests: XCTestCase { | ||
|
||
let filledActiveAlpha: CGFloat = 0.87 | ||
let filledOnSurfaceAlpha: CGFloat = 0.6 | ||
let filledDisabledAlpha: CGFloat = 0.38 | ||
let filledSurfaceOverlayAlpha: CGFloat = 0.04 | ||
let filledIndicatorLineAlpha: CGFloat = 0.42 | ||
let filledIconAlpha: CGFloat = 0.54 | ||
|
||
func testMDCTextInputControllerFilledThemingWithContainerScheme() { | ||
// Given | ||
let textFieldFilled = MDCTextField() | ||
let textFieldControllerFilled = MDCTextInputControllerFilled(textInput: textFieldFilled) | ||
let scheme: MDCContainerScheme = MDCContainerScheme() | ||
|
||
// When | ||
textFieldControllerFilled.applyTheme(withScheme: scheme) | ||
|
||
// Then | ||
// Color | ||
XCTAssertEqual(textFieldControllerFilled.borderFillColor, | ||
scheme.colorScheme.onSurfaceColor.withAlphaComponent(filledSurfaceOverlayAlpha)) | ||
XCTAssertEqual(textFieldControllerFilled.normalColor, | ||
scheme.colorScheme.onSurfaceColor.withAlphaComponent(filledIndicatorLineAlpha)) | ||
XCTAssertEqual(textFieldControllerFilled.inlinePlaceholderColor, | ||
scheme.colorScheme.onSurfaceColor.withAlphaComponent(filledOnSurfaceAlpha)) | ||
XCTAssertEqual(textFieldControllerFilled.leadingUnderlineLabelTextColor, | ||
scheme.colorScheme.onSurfaceColor.withAlphaComponent(filledOnSurfaceAlpha)) | ||
XCTAssertEqual(textFieldControllerFilled.activeColor, scheme.colorScheme.primaryColor) | ||
//XCTAssertEqual(textFieldControllerFilled.textInput.textColor, | ||
// scheme.colorScheme.onSurfaceColor.withAlphaComponent(filledActiveAlpha)) | ||
XCTAssertEqual(textFieldControllerFilled.errorColor, scheme.colorScheme.errorColor) | ||
XCTAssertEqual(textFieldControllerFilled.disabledColor, | ||
scheme.colorScheme.onSurfaceColor.withAlphaComponent(filledDisabledAlpha)) | ||
XCTAssertEqual(textFieldControllerFilled.floatingPlaceholderNormalColor, | ||
scheme.colorScheme.onSurfaceColor.withAlphaComponent(filledOnSurfaceAlpha)) | ||
XCTAssertEqual(textFieldControllerFilled.floatingPlaceholderActiveColor, | ||
scheme.colorScheme.primaryColor.withAlphaComponent(filledActiveAlpha)) | ||
XCTAssertEqual(textFieldControllerFilled.textInputClearButtonTintColor, | ||
scheme.colorScheme.onSurfaceColor.withAlphaComponent(filledIconAlpha)) | ||
|
||
// Typography | ||
XCTAssertEqual(textFieldControllerFilled.inlinePlaceholderFont, | ||
scheme.typographyScheme.subtitle1) | ||
XCTAssertEqual(textFieldControllerFilled.leadingUnderlineLabelFont, | ||
scheme.typographyScheme.caption) | ||
XCTAssertEqual(textFieldControllerFilled.trailingUnderlineLabelFont, | ||
scheme.typographyScheme.caption) | ||
let placeholderScale: CGFloat = | ||
scheme.typographyScheme.caption.pointSize / scheme.typographyScheme.subtitle1.pointSize | ||
XCTAssertEqual(CGFloat(textFieldControllerFilled.floatingPlaceholderScale.doubleValue), | ||
placeholderScale) | ||
} | ||
} |