Skip to content

Commit

Permalink
[Dialogs] Implement MDCAlertController typography themer. (#3302)
Browse files Browse the repository at this point in the history
* Implementing MDCAlertTypographyThemer.

* fixed the test.

* Implementing MDCAlertTypographyThemer.

* fixed the test.

* Dialogs: Example for typography added.
  • Loading branch information
mohammadcazig committed Apr 9, 2018
1 parent 8563ec0 commit 7716981
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 1 deletion.
10 changes: 9 additions & 1 deletion MaterialComponents.podspec
Expand Up @@ -308,7 +308,15 @@ Pod::Spec.new do |mdc|
extension.dependency "MaterialComponents/Dialogs"
extension.dependency "MaterialComponents/Themes"
end
end
component.subspec "TypographyThemer" do |extension|
extension.ios.deployment_target = '8.0'
extension.public_header_files = "components/Dialogs/src/#{extension.base_name}/*.h"
extension.source_files = "components/Dialogs/src/#{extension.base_name}/*.{h,m}"

extension.dependency "MaterialComponents/Dialogs"
extension.dependency "MaterialComponents/schemes/Typography"
end
end

mdc.subspec "FeatureHighlight" do |component|
component.ios.deployment_target = '8.0'
Expand Down
16 changes: 16 additions & 0 deletions components/Dialogs/BUILD
Expand Up @@ -67,6 +67,21 @@ mdc_objc_library(
visibility = ["//visibility:public"],
)

mdc_objc_library(
name = "TypographyThemer",
srcs = native.glob(["src/TypographyThemer/*.m"]),
hdrs = native.glob(["src/TypographyThemer/*.h"]),
includes = ["src/TypographyThemer"],
sdk_frameworks = [
"UIKit",
],
deps = [
":Dialogs",
"//components/schemes/Typography",
],
visibility = ["//visibility:public"],
)

mdc_objc_library(
name = "private",
hdrs = native.glob(["src/private/*.h"]),
Expand All @@ -88,6 +103,7 @@ mdc_objc_library(
deps = [
":Dialogs",
":ColorThemer",
":TypographyThemer",
":private",
],
visibility = ["//visibility:private"],
Expand Down
4 changes: 4 additions & 0 deletions components/Dialogs/examples/DialogsAlertViewController.m
Expand Up @@ -17,6 +17,7 @@
#import "supplemental/DialogsAlertViewControllerSupplemental.h"
#import "MaterialButtons.h"
#import "MaterialDialogs.h"
#import "MDCAlertTypographyThemer.h"

@implementation DialogsAlertViewController

Expand Down Expand Up @@ -66,6 +67,9 @@ - (IBAction)didTapShowAlert {

MDCAlertController *materialAlertController =
[MDCAlertController alertControllerWithTitle:titleString message:messageString];
MDCTypographyScheme *typographyScheme = [[MDCTypographyScheme alloc] init];
[MDCAlertTypographyThemer applyTypographyScheme:typographyScheme
toAlertController:materialAlertController];

MDCAlertAction *agreeAaction = [MDCAlertAction actionWithTitle:@"AGREE"
handler:^(MDCAlertAction *action) {
Expand Down
35 changes: 35 additions & 0 deletions components/Dialogs/src/TypographyThemer/MDCAlertTypographyThemer.h
@@ -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 components/Dialogs/src/TypographyThemer/MDCAlertTypographyThemer.m
@@ -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
@@ -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

0 comments on commit 7716981

Please sign in to comment.