diff --git a/MaterialComponents.podspec b/MaterialComponents.podspec index b9ba24ef806..2b0ca7e55aa 100644 --- a/MaterialComponents.podspec +++ b/MaterialComponents.podspec @@ -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' diff --git a/components/Dialogs/BUILD b/components/Dialogs/BUILD index d9b76f6d2ca..6a583c62f06 100644 --- a/components/Dialogs/BUILD +++ b/components/Dialogs/BUILD @@ -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"]), @@ -88,6 +103,7 @@ mdc_objc_library( deps = [ ":Dialogs", ":ColorThemer", + ":TypographyThemer", ":private", ], visibility = ["//visibility:private"], diff --git a/components/Dialogs/examples/DialogsAlertViewController.m b/components/Dialogs/examples/DialogsAlertViewController.m index 9be8f875086..e0b6c945309 100644 --- a/components/Dialogs/examples/DialogsAlertViewController.m +++ b/components/Dialogs/examples/DialogsAlertViewController.m @@ -17,6 +17,7 @@ #import "supplemental/DialogsAlertViewControllerSupplemental.h" #import "MaterialButtons.h" #import "MaterialDialogs.h" +#import "MDCAlertTypographyThemer.h" @implementation DialogsAlertViewController @@ -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) { diff --git a/components/Dialogs/src/TypographyThemer/MDCAlertTypographyThemer.h b/components/Dialogs/src/TypographyThemer/MDCAlertTypographyThemer.h new file mode 100644 index 00000000000..35842972cc7 --- /dev/null +++ b/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 + +#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)typographyScheme + toAlertController:(nonnull MDCAlertController *)alertController; + +@end diff --git a/components/Dialogs/src/TypographyThemer/MDCAlertTypographyThemer.m b/components/Dialogs/src/TypographyThemer/MDCAlertTypographyThemer.m new file mode 100644 index 00000000000..7e4cbb21f47 --- /dev/null +++ b/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)typographyScheme + toAlertController:(nonnull MDCAlertController *)alertController { + alertController.titleFont = typographyScheme.headline6; + alertController.messageFont = typographyScheme.body1; + alertController.buttonFont = typographyScheme.button; +} + +@end diff --git a/components/Dialogs/tests/unit/MDCAlertControllerTypographyThemerTests.m b/components/Dialogs/tests/unit/MDCAlertControllerTypographyThemerTests.m new file mode 100644 index 00000000000..2685f3a75be --- /dev/null +++ b/components/Dialogs/tests/unit/MDCAlertControllerTypographyThemerTests.m @@ -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 + +@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