mirror of
https://github.com/material-components/material-components-ios.git
synced 2026-02-20 08:27:32 +08:00
[Dialogs] Delete deprecated DialogThemer (#9776)
DialogThemer (`MDCAlertControllerThemer` and `MDCAlertScheme`) is deprecated and has no internal use.
This commit is contained in:
parent
b027eeed70
commit
511da587d4
@ -293,48 +293,6 @@ High, Medium and low emphasis are supported.
|
||||
```
|
||||
<!--</div>-->
|
||||
|
||||
### Using a Themer
|
||||
|
||||
You can theme an MDCDialog to match the Material Design Dialog using your app's schemes in the DialogThemer
|
||||
extension.
|
||||
|
||||
You must first add the DialogThemer extension to your project:
|
||||
|
||||
```bash
|
||||
pod 'MaterialComponents/Dialogs+DialogThemer'
|
||||
```
|
||||
|
||||
You can then import the extension and create an `MDCAlertControllerThemer` instance. A dialog scheme defines
|
||||
the design parameters that you can use to theme your dialogs.
|
||||
|
||||
<!--<div class="material-code-render" markdown="1">-->
|
||||
#### Swift
|
||||
```swift
|
||||
// Step 1: Import the DialogThemer extension
|
||||
import MaterialComponents.MaterialDialogs_DialogThemer
|
||||
|
||||
// Step 2: Create or get a alert scheme
|
||||
let alertScheme = MDCAlertScheme()
|
||||
|
||||
// Step 3: Apply the alert scheme to your component using the desired alert style
|
||||
MDCAlertControllerThemer.applyScheme(scheme, to: alertController)
|
||||
```
|
||||
|
||||
#### Objective-C
|
||||
|
||||
```objc
|
||||
// Step 1: Import the DialogThemer extension
|
||||
#import "MaterialDialogs+DialogThemer.h"
|
||||
|
||||
// Step 2: Create or get a alert scheme
|
||||
MDCAlertScheme *alertScheme = [[MDCAlertScheme alloc] init];
|
||||
|
||||
// Step 3: Apply the alert scheme to your component using the desired alert style
|
||||
[MDCAlertControllerThemer applyScheme:alertScheme toAlertController:alertController];
|
||||
```
|
||||
<!--</div>-->
|
||||
|
||||
|
||||
## Accessibility
|
||||
|
||||
<!-- Extracted from docs/accessibility.md -->
|
||||
|
||||
@ -97,44 +97,3 @@ High, Medium and low emphasis are supported.
|
||||
[self presentViewController:alert animated:YES completion:...];
|
||||
```
|
||||
<!--</div>-->
|
||||
|
||||
### Using a Themer
|
||||
|
||||
You can theme an MDCDialog to match the Material Design Dialog using your app's schemes in the DialogThemer
|
||||
extension.
|
||||
|
||||
You must first add the DialogThemer extension to your project:
|
||||
|
||||
```bash
|
||||
pod 'MaterialComponents/Dialogs+DialogThemer'
|
||||
```
|
||||
|
||||
You can then import the extension and create an `MDCAlertControllerThemer` instance. A dialog scheme defines
|
||||
the design parameters that you can use to theme your dialogs.
|
||||
|
||||
<!--<div class="material-code-render" markdown="1">-->
|
||||
#### Swift
|
||||
```swift
|
||||
// Step 1: Import the DialogThemer extension
|
||||
import MaterialComponents.MaterialDialogs_DialogThemer
|
||||
|
||||
// Step 2: Create or get a alert scheme
|
||||
let alertScheme = MDCAlertScheme()
|
||||
|
||||
// Step 3: Apply the alert scheme to your component using the desired alert style
|
||||
MDCAlertControllerThemer.applyScheme(scheme, to: alertController)
|
||||
```
|
||||
|
||||
#### Objective-C
|
||||
|
||||
```objc
|
||||
// Step 1: Import the DialogThemer extension
|
||||
#import "MaterialDialogs+DialogThemer.h"
|
||||
|
||||
// Step 2: Create or get a alert scheme
|
||||
MDCAlertScheme *alertScheme = [[MDCAlertScheme alloc] init];
|
||||
|
||||
// Step 3: Apply the alert scheme to your component using the desired alert style
|
||||
[MDCAlertControllerThemer applyScheme:alertScheme toAlertController:alertController];
|
||||
```
|
||||
<!--</div>-->
|
||||
|
||||
@ -1,41 +0,0 @@
|
||||
// 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
|
||||
//
|
||||
// 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 <Foundation/Foundation.h>
|
||||
|
||||
#import "MDCAlertScheme.h"
|
||||
#import "MaterialDialogs.h"
|
||||
|
||||
/**
|
||||
@warning This API is deprecated. Learn more at
|
||||
docs/theming.md#migration-guide-themers-to-theming-extensions
|
||||
*/
|
||||
__deprecated_msg("Please use MaterialDialogs+Theming.") @interface MDCAlertControllerThemer
|
||||
: NSObject
|
||||
|
||||
/**
|
||||
Applies a component scheme's properties to an MDCAlertController.
|
||||
|
||||
@param alertScheme The component scheme to apply to the alert dialog instance.
|
||||
@param alertController An alert dialog instance to which the component scheme should be applied.
|
||||
|
||||
@warning This API is deprecated. Learn more at
|
||||
docs/theming.md#migration-guide-themers-to-theming-extensions
|
||||
*/
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
+ (void)applyScheme:(nonnull id<MDCAlertScheming>)alertScheme
|
||||
toAlertController:(nonnull MDCAlertController *)alertController;
|
||||
#pragma clang diagnostic pop
|
||||
@end
|
||||
@ -1,75 +0,0 @@
|
||||
// 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
|
||||
//
|
||||
// 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 "MDCAlertControllerThemer.h"
|
||||
|
||||
#import "../MDCAlertController+ButtonForAction.h"
|
||||
#import "MDCAlertColorThemer.h"
|
||||
#import "MDCAlertTypographyThemer.h"
|
||||
#import "MaterialButtons+ColorThemer.h"
|
||||
#import "MaterialButtons+ShapeThemer.h"
|
||||
#import "MaterialButtons+TypographyThemer.h"
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
|
||||
@implementation MDCAlertControllerThemer
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
+ (void)applyScheme:(nonnull id<MDCAlertScheming>)alertScheme
|
||||
toAlertController:(nonnull MDCAlertController *)alertController {
|
||||
[MDCAlertColorThemer applySemanticColorScheme:alertScheme.colorScheme
|
||||
toAlertController:alertController];
|
||||
|
||||
[MDCAlertTypographyThemer applyTypographyScheme:alertScheme.typographyScheme
|
||||
toAlertController:alertController];
|
||||
|
||||
alertController.cornerRadius = alertScheme.cornerRadius;
|
||||
alertController.elevation = alertScheme.elevation;
|
||||
|
||||
// Apply theming to buttons based on the action emphasis
|
||||
for (MDCAlertAction *action in alertController.actions) {
|
||||
MDCButton *button = [alertController buttonForAction:action];
|
||||
// todo: b/117265609: Incorporate dynamic type support in semantic themers
|
||||
switch (action.emphasis) {
|
||||
case MDCActionEmphasisHigh:
|
||||
[MDCContainedButtonThemer applyScheme:alertScheme.buttonScheme toButton:button];
|
||||
break;
|
||||
case MDCActionEmphasisMedium:
|
||||
[self applyOutlinedScheme:alertScheme.buttonScheme toButton:button];
|
||||
break;
|
||||
case MDCActionEmphasisLow: // fallthrough
|
||||
default:
|
||||
[MDCTextButtonThemer applyScheme:alertScheme.buttonScheme toButton:button];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Helpers
|
||||
+ (void)applyOutlinedScheme:(nonnull id<MDCButtonScheming>)scheme
|
||||
toButton:(nonnull MDCButton *)button {
|
||||
[MDCOutlinedButtonColorThemer applySemanticColorScheme:scheme.colorScheme toButton:button];
|
||||
[MDCButtonShapeThemer applyShapeScheme:scheme.shapeScheme toButton:button];
|
||||
[MDCButtonTypographyThemer applyTypographyScheme:scheme.typographyScheme toButton:button];
|
||||
button.minimumSize = CGSizeMake(0, scheme.minimumHeight);
|
||||
button.layer.cornerRadius = scheme.cornerRadius;
|
||||
|
||||
NSUInteger maximumStateValue = UIControlStateNormal | UIControlStateSelected |
|
||||
UIControlStateHighlighted | UIControlStateDisabled;
|
||||
for (NSUInteger state = 0; state <= maximumStateValue; ++state) {
|
||||
[button setBorderWidth:1 forState:state];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@ -1,72 +0,0 @@
|
||||
// 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
|
||||
//
|
||||
// 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 <Foundation/Foundation.h>
|
||||
|
||||
#import "MaterialButtons+ButtonThemer.h"
|
||||
#import "MaterialColorScheme.h"
|
||||
#import "MaterialShadowElevations.h"
|
||||
#import "MaterialTypographyScheme.h"
|
||||
|
||||
/**
|
||||
Defines a readonly immutable interface for component style data to be applied by a themer.
|
||||
|
||||
@warning This API is deprecated. Learn more at
|
||||
docs/theming.md#migration-guide-themers-to-theming-extensions
|
||||
*/
|
||||
__deprecated_msg("Please use MDCContainerScheming") @protocol MDCAlertScheming
|
||||
|
||||
/** The color scheme to apply to Dialog. */
|
||||
@property(nonnull, readonly, nonatomic) id<MDCColorScheming> colorScheme;
|
||||
|
||||
/** The typography scheme to apply to Dialog. */
|
||||
@property(nonnull, readonly, nonatomic) id<MDCTypographyScheming> typographyScheme;
|
||||
|
||||
/** The button scheme to apply to Dialog's actions. */
|
||||
@property(nonnull, readonly, nonatomic) id<MDCButtonScheming> buttonScheme;
|
||||
|
||||
/** The corner radius to apply to Dialog. */
|
||||
@property(readonly, nonatomic) CGFloat cornerRadius;
|
||||
|
||||
/** The elevation to apply to the Dialog. */
|
||||
@property(readonly, nonatomic) CGFloat elevation;
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
A simple implementation of @c MDCAlertScheming that provides default color,
|
||||
typography and shape schemes, from which customizations can be made.
|
||||
|
||||
@warning This API is deprecated. Learn more at
|
||||
docs/theming.md#migration-guide-themers-to-theming-extensions
|
||||
*/
|
||||
__deprecated_msg("Please use MDCContainerScheme") @interface MDCAlertScheme
|
||||
: NSObject<MDCAlertScheming>
|
||||
|
||||
/** The color scheme to apply to Dialog. */
|
||||
@property(nonnull, readwrite, nonatomic) id<MDCColorScheming> colorScheme;
|
||||
|
||||
/** The typography scheme to apply to Dialog. */
|
||||
@property(nonnull, readwrite, nonatomic) id<MDCTypographyScheming> typographyScheme;
|
||||
|
||||
/** The button scheme to apply to Dialog's actions. */
|
||||
@property(nonnull, readwrite, nonatomic) id<MDCButtonScheming> buttonScheme;
|
||||
|
||||
/** The corner radius to apply to Dialog. */
|
||||
@property(readwrite, nonatomic) CGFloat cornerRadius;
|
||||
|
||||
/** The elevation to apply to the Dialog. */
|
||||
@property(readwrite, nonatomic) MDCShadowElevation elevation;
|
||||
|
||||
@end
|
||||
@ -1,36 +0,0 @@
|
||||
// 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
|
||||
//
|
||||
// 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 "MDCAlertScheme.h"
|
||||
|
||||
static const CGFloat kCornerRadius = 4;
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
|
||||
@implementation MDCAlertScheme
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_colorScheme =
|
||||
[[MDCSemanticColorScheme alloc] initWithDefaults:MDCColorSchemeDefaultsMaterial201804];
|
||||
_typographyScheme = [[MDCTypographyScheme alloc] init];
|
||||
_buttonScheme = [[MDCButtonScheme alloc] init];
|
||||
_cornerRadius = kCornerRadius;
|
||||
_elevation = MDCShadowElevationDialog;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@end
|
||||
@ -1,16 +0,0 @@
|
||||
// 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
|
||||
//
|
||||
// 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 "MDCAlertControllerThemer.h"
|
||||
#import "MDCAlertScheme.h"
|
||||
@ -1,148 +0,0 @@
|
||||
// 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
|
||||
//
|
||||
// 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.MaterialShadowElevations
|
||||
import MaterialComponents.MaterialDialogs
|
||||
import MaterialComponents.MaterialDialogs_DialogThemer
|
||||
|
||||
class MDCAlertControllerAlertThemerTests: XCTestCase {
|
||||
|
||||
let defaultCornerRadius: CGFloat = 4.0
|
||||
let defaultElevation: ShadowElevation = .dialog
|
||||
var alertScheme: MDCAlertScheme! = MDCAlertScheme()
|
||||
var alert: MDCAlertController! = MDCAlertController(title: "Title", message: "Message")
|
||||
var alertView: MDCAlertControllerView { return alert.view as! MDCAlertControllerView }
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
|
||||
alertScheme = MDCAlertScheme()
|
||||
alertScheme.colorScheme = MDCSemanticColorScheme()
|
||||
alertScheme.typographyScheme = MDCTypographyScheme()
|
||||
|
||||
alert = MDCAlertController(title: "Title", message: "Message")
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
alertScheme = nil
|
||||
alert = nil
|
||||
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
|
||||
func testDefaultAlertScheme() {
|
||||
XCTAssertEqual(alertScheme.colorScheme.primaryColor, MDCSemanticColorScheme().primaryColor)
|
||||
XCTAssertEqual(alertScheme.typographyScheme.body1, MDCTypographyScheme().body1)
|
||||
XCTAssertEqual(alertScheme.cornerRadius, defaultCornerRadius)
|
||||
XCTAssertEqual(alertScheme.elevation, defaultElevation)
|
||||
}
|
||||
|
||||
func testApplyingAlertSchemeWithCustomColor() {
|
||||
// Given
|
||||
let colorScheme = MDCSemanticColorScheme()
|
||||
colorScheme.onSurfaceColor = .orange
|
||||
colorScheme.primaryColor = .green
|
||||
alertScheme.colorScheme = colorScheme
|
||||
|
||||
// When
|
||||
MDCAlertControllerThemer.applyScheme(alertScheme, to: alert)
|
||||
|
||||
// Then
|
||||
XCTAssertEqual(alertScheme.colorScheme.onSurfaceColor, colorScheme.onSurfaceColor)
|
||||
XCTAssertEqual(alertView.titleColor,
|
||||
alertScheme.colorScheme.onSurfaceColor.withAlphaComponent(0.87))
|
||||
XCTAssertNotEqual(alertView.titleColor,
|
||||
MDCSemanticColorScheme().onSurfaceColor.withAlphaComponent(0.87))
|
||||
XCTAssertEqual(alertView.titleIconTintColor, colorScheme.primaryColor)
|
||||
}
|
||||
|
||||
// Testing soon-to-be-deprecated old approach to button theming // b/117717380: Will be deprecated
|
||||
func testApplyingCustomTitleIconTintColor() {
|
||||
// Given
|
||||
let iconColor = UIColor.red
|
||||
let primaryColor = UIColor.green
|
||||
|
||||
// When
|
||||
alert.buttonTitleColor = primaryColor
|
||||
alert.titleIconTintColor = iconColor
|
||||
|
||||
// Then
|
||||
XCTAssertEqual(alert.buttonTitleColor, primaryColor)
|
||||
XCTAssertEqual(alertView.buttonColor, primaryColor)
|
||||
XCTAssertEqual(alertView.titleIconTintColor, iconColor)
|
||||
}
|
||||
|
||||
func testApplyingAlertSchemeScrimColorToPresentationController() {
|
||||
// Given
|
||||
let colorScheme = MDCSemanticColorScheme()
|
||||
colorScheme.onSurfaceColor = UIColor.green
|
||||
alertScheme.colorScheme = colorScheme
|
||||
let scrimColor = colorScheme.onSurfaceColor.withAlphaComponent(0.32)
|
||||
let presentationController = alert.mdc_dialogPresentationController!
|
||||
|
||||
// When
|
||||
MDCAlertControllerThemer.applyScheme(alertScheme, to: alert)
|
||||
|
||||
// Then
|
||||
XCTAssertEqual(presentationController.scrimColor, scrimColor)
|
||||
}
|
||||
|
||||
func testApplyingAlertSchemeWithCustomTypography() {
|
||||
// Given
|
||||
let typographyScheme = MDCTypographyScheme()
|
||||
let testFont = UIFont.boldSystemFont(ofSize: 55.0)
|
||||
typographyScheme.headline6 = testFont
|
||||
alertScheme.typographyScheme = typographyScheme
|
||||
|
||||
// When
|
||||
MDCAlertControllerThemer.applyScheme(alertScheme, to: alert)
|
||||
|
||||
// Then
|
||||
XCTAssertEqual(alertScheme.typographyScheme.headline6, typographyScheme.headline6)
|
||||
XCTAssertEqual(alertView.titleFont, alertScheme.typographyScheme.headline6)
|
||||
XCTAssertNotEqual(alertView.titleFont, MDCTypographyScheme().headline6)
|
||||
XCTAssertEqual(alertView.titleFont, testFont)
|
||||
}
|
||||
|
||||
func testApplyingAlertSchemeWithCustomShape() {
|
||||
// Given
|
||||
let cornerRadius: CGFloat = 33.3
|
||||
alertScheme.cornerRadius = cornerRadius
|
||||
|
||||
// When
|
||||
MDCAlertControllerThemer.applyScheme(alertScheme, to: alert)
|
||||
|
||||
// Then
|
||||
XCTAssertEqual(alertScheme.cornerRadius, cornerRadius, accuracy: 0.0)
|
||||
XCTAssertEqual(alertView.cornerRadius, cornerRadius, accuracy: 0.0)
|
||||
XCTAssertNotEqual(alertScheme.cornerRadius, defaultCornerRadius, accuracy: 0.0)
|
||||
}
|
||||
|
||||
func testApplyAlertSchemeWithCustomElevation() {
|
||||
// Given
|
||||
let elevation: ShadowElevation = ShadowElevation(rawValue: 10.0)
|
||||
alertScheme.elevation = elevation
|
||||
|
||||
// When
|
||||
MDCAlertControllerThemer.applyScheme(alertScheme, to: alert)
|
||||
|
||||
// Then
|
||||
XCTAssertEqual(alertScheme.elevation.rawValue, elevation.rawValue, accuracy: 0.001)
|
||||
XCTAssertEqual(alert.elevation.rawValue, elevation.rawValue, accuracy: 0.001)
|
||||
XCTAssertNotEqual(alertScheme.elevation.rawValue, defaultElevation.rawValue, accuracy: 0.001)
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user