From 511da587d485fac0407ccc8a0519aaa941dceea5 Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Mon, 24 Feb 2020 14:03:29 -0500 Subject: [PATCH] [Dialogs] Delete deprecated DialogThemer (#9776) DialogThemer (`MDCAlertControllerThemer` and `MDCAlertScheme`) is deprecated and has no internal use. --- components/Dialogs/README.md | 42 ----- components/Dialogs/docs/theming.md | 41 ----- .../DialogThemer/MDCAlertControllerThemer.h | 41 ----- .../DialogThemer/MDCAlertControllerThemer.m | 75 --------- .../Dialogs/src/DialogThemer/MDCAlertScheme.h | 72 --------- .../Dialogs/src/DialogThemer/MDCAlertScheme.m | 36 ----- .../MaterialDialogs+DialogThemer.h | 16 -- .../MDCAlertControllerAlertThemerTests.swift | 148 ------------------ 8 files changed, 471 deletions(-) delete mode 100644 components/Dialogs/src/DialogThemer/MDCAlertControllerThemer.h delete mode 100644 components/Dialogs/src/DialogThemer/MDCAlertControllerThemer.m delete mode 100644 components/Dialogs/src/DialogThemer/MDCAlertScheme.h delete mode 100644 components/Dialogs/src/DialogThemer/MDCAlertScheme.m delete mode 100644 components/Dialogs/src/DialogThemer/MaterialDialogs+DialogThemer.h delete mode 100644 components/Dialogs/tests/unit/MDCAlertControllerAlertThemerTests.swift diff --git a/components/Dialogs/README.md b/components/Dialogs/README.md index d659268bd..e0e75a8a0 100644 --- a/components/Dialogs/README.md +++ b/components/Dialogs/README.md @@ -293,48 +293,6 @@ High, Medium and low emphasis are supported. ``` -### 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. - - -#### 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]; -``` - - - ## Accessibility diff --git a/components/Dialogs/docs/theming.md b/components/Dialogs/docs/theming.md index 1f4241150..92b3f2771 100644 --- a/components/Dialogs/docs/theming.md +++ b/components/Dialogs/docs/theming.md @@ -97,44 +97,3 @@ High, Medium and low emphasis are supported. [self presentViewController:alert animated:YES completion:...]; ``` - -### 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. - - -#### 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]; -``` - diff --git a/components/Dialogs/src/DialogThemer/MDCAlertControllerThemer.h b/components/Dialogs/src/DialogThemer/MDCAlertControllerThemer.h deleted file mode 100644 index d1b395562..000000000 --- a/components/Dialogs/src/DialogThemer/MDCAlertControllerThemer.h +++ /dev/null @@ -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 - -#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)alertScheme - toAlertController:(nonnull MDCAlertController *)alertController; -#pragma clang diagnostic pop -@end diff --git a/components/Dialogs/src/DialogThemer/MDCAlertControllerThemer.m b/components/Dialogs/src/DialogThemer/MDCAlertControllerThemer.m deleted file mode 100644 index 05cb885e0..000000000 --- a/components/Dialogs/src/DialogThemer/MDCAlertControllerThemer.m +++ /dev/null @@ -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)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)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 diff --git a/components/Dialogs/src/DialogThemer/MDCAlertScheme.h b/components/Dialogs/src/DialogThemer/MDCAlertScheme.h deleted file mode 100644 index 91c4c5bb3..000000000 --- a/components/Dialogs/src/DialogThemer/MDCAlertScheme.h +++ /dev/null @@ -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 - -#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 colorScheme; - -/** The typography scheme to apply to Dialog. */ -@property(nonnull, readonly, nonatomic) id typographyScheme; - -/** The button scheme to apply to Dialog's actions. */ -@property(nonnull, readonly, nonatomic) id 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 - -/** The color scheme to apply to Dialog. */ -@property(nonnull, readwrite, nonatomic) id colorScheme; - -/** The typography scheme to apply to Dialog. */ -@property(nonnull, readwrite, nonatomic) id typographyScheme; - -/** The button scheme to apply to Dialog's actions. */ -@property(nonnull, readwrite, nonatomic) id 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 diff --git a/components/Dialogs/src/DialogThemer/MDCAlertScheme.m b/components/Dialogs/src/DialogThemer/MDCAlertScheme.m deleted file mode 100644 index 9adaa1d04..000000000 --- a/components/Dialogs/src/DialogThemer/MDCAlertScheme.m +++ /dev/null @@ -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 diff --git a/components/Dialogs/src/DialogThemer/MaterialDialogs+DialogThemer.h b/components/Dialogs/src/DialogThemer/MaterialDialogs+DialogThemer.h deleted file mode 100644 index 048d5f9da..000000000 --- a/components/Dialogs/src/DialogThemer/MaterialDialogs+DialogThemer.h +++ /dev/null @@ -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" diff --git a/components/Dialogs/tests/unit/MDCAlertControllerAlertThemerTests.swift b/components/Dialogs/tests/unit/MDCAlertControllerAlertThemerTests.swift deleted file mode 100644 index 35f2f5c5b..000000000 --- a/components/Dialogs/tests/unit/MDCAlertControllerAlertThemerTests.swift +++ /dev/null @@ -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) - } -}