Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Dialogs] Implement MDCAlertController typography themer. (#3302)
* Implementing MDCAlertTypographyThemer. * fixed the test. * Implementing MDCAlertTypographyThemer. * fixed the test. * Dialogs: Example for typography added.
- Loading branch information
1 parent
8563ec0
commit 7716981
Showing
6 changed files
with
136 additions
and
1 deletion.
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
35 changes: 35 additions & 0 deletions
35
components/Dialogs/src/TypographyThemer/MDCAlertTypographyThemer.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,35 @@ | ||
/* | ||
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 <UIKit/UIKit.h> | ||
|
||
#import "MaterialDialogs.h" | ||
#import "MaterialTypographyScheme.h" | ||
|
||
/** | ||
Used to apply a typography scheme to theme a MDCAlertController alert dialogs. | ||
*/ | ||
@interface MDCAlertTypographyThemer : NSObject | ||
|
||
/** | ||
Applies a typography scheme to theme a MDCAlertController alert dialogs. | ||
@param typographyScheme The typography scheme to apply to a MDCAlertController alert dialogs. | ||
*/ | ||
+ (void)applyTypographyScheme:(nonnull id<MDCTypographyScheming>)typographyScheme | ||
toAlertController:(nonnull MDCAlertController *)alertController; | ||
|
||
@end |
28 changes: 28 additions & 0 deletions
28
components/Dialogs/src/TypographyThemer/MDCAlertTypographyThemer.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,28 @@ | ||
/* | ||
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 "MDCAlertTypographyThemer.h" | ||
|
||
@implementation MDCAlertTypographyThemer | ||
|
||
+ (void)applyTypographyScheme:(nonnull id<MDCTypographyScheming>)typographyScheme | ||
toAlertController:(nonnull MDCAlertController *)alertController { | ||
alertController.titleFont = typographyScheme.headline6; | ||
alertController.messageFont = typographyScheme.body1; | ||
alertController.buttonFont = typographyScheme.button; | ||
} | ||
|
||
@end |
44 changes: 44 additions & 0 deletions
44
components/Dialogs/tests/unit/MDCAlertControllerTypographyThemerTests.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,44 @@ | ||
/* | ||
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 "MaterialDialogs.h" | ||
#import "MDCAlertTypographyThemer.h" | ||
|
||
#import "MDCAlertControllerView+Private.h" | ||
|
||
#import <XCTest/XCTest.h> | ||
|
||
@interface MDCAlertControllerTypographyThemerTests : XCTestCase | ||
|
||
@end | ||
|
||
@implementation MDCAlertControllerTypographyThemerTests | ||
|
||
- (void)testApplyingTypographyScheme { | ||
MDCAlertController *alert = [MDCAlertController alertControllerWithTitle:@"title" | ||
message:@"message"]; | ||
MDCTypographyScheme *typographyScheme = [[MDCTypographyScheme alloc] init]; | ||
[MDCAlertTypographyThemer applyTypographyScheme:typographyScheme toAlertController:alert]; | ||
|
||
MDCAlertControllerView *view = (MDCAlertControllerView *)alert.view; | ||
XCTAssertEqual(view.titleLabel.font, typographyScheme.headline6); | ||
XCTAssertEqual(view.messageLabel.font, typographyScheme.body1); | ||
for (UIButton *button in view.actionButtons) { | ||
XCTAssertEqual(button.titleLabel.font, typographyScheme.button); | ||
} | ||
} | ||
|
||
@end |