diff --git a/MaterialComponents.podspec b/MaterialComponents.podspec index 00b8ac0e13b..3db18367255 100644 --- a/MaterialComponents.podspec +++ b/MaterialComponents.podspec @@ -606,6 +606,14 @@ end extension.dependency "MaterialComponents/Tabs" extension.dependency "MaterialComponents/Themes" end + component.subspec "TypographyThemer" do |extension| + extension.ios.deployment_target = '8.0' + extension.public_header_files = "components/Tabs/src/#{extension.base_name}/*.h" + extension.source_files = "components/Tabs/src/#{extension.base_name}/*.{h,m}" + + extension.dependency "MaterialComponents/Tabs" + extension.dependency "MaterialComponents/schemes/Typography" + end end diff --git a/components/Tabs/BUILD b/components/Tabs/BUILD index 743668748d4..afa42e4a764 100644 --- a/components/Tabs/BUILD +++ b/components/Tabs/BUILD @@ -78,6 +78,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 = [ + ":Tabs", + "//components/schemes/Typography", + ], + visibility = ["//visibility:public"], +) + mdc_objc_library( name = "private", hdrs = native.glob(["src/private/*.h"]), @@ -100,6 +115,7 @@ mdc_objc_library( ":Tabs", ":ColorThemer", ":FontThemer", + ":TypographyThemer", ":private", ], visibility = ["//visibility:private"], diff --git a/components/Tabs/examples/supplemental/TabBarIconExampleSupplemental.m b/components/Tabs/examples/supplemental/TabBarIconExampleSupplemental.m index 9fba3fd04b2..e4829c62f45 100644 --- a/components/Tabs/examples/supplemental/TabBarIconExampleSupplemental.m +++ b/components/Tabs/examples/supplemental/TabBarIconExampleSupplemental.m @@ -21,6 +21,7 @@ #import "TabBarIconExampleSupplemental.h" #import "MaterialPalettes.h" +#import "MDCTabBarTypographyThemer.h" // Exposing selectors defined in the main example class @interface TabBarIconExample () @@ -37,6 +38,9 @@ - (void)setupExampleViews { [self setupScrollingContent]; [self setupAlignmentButton]; + + MDCTypographyScheme *typographyScheme = [[MDCTypographyScheme alloc] init]; + [MDCTabBarTypographyThemer applyTypographyScheme:typographyScheme toTabBar:self.tabBar]; } - (void)setupAlignmentButton { diff --git a/components/Tabs/src/FontThemer/MDCTabBarFontThemer.h b/components/Tabs/src/FontThemer/MDCTabBarFontThemer.h index 596b98a3c3f..9f54f30c0be 100644 --- a/components/Tabs/src/FontThemer/MDCTabBarFontThemer.h +++ b/components/Tabs/src/FontThemer/MDCTabBarFontThemer.h @@ -19,6 +19,7 @@ limitations under the License. /** Used to apply a font scheme to theme MDCTabBar. + This Class will be deprecated soon please use MDCTabBarTypographyThemer instead. */ @interface MDCTabBarFontThemer : NSObject diff --git a/components/Tabs/src/TypographyThemer/MDCTabBarTypographyThemer.h b/components/Tabs/src/TypographyThemer/MDCTabBarTypographyThemer.h new file mode 100644 index 00000000000..7ddde683a67 --- /dev/null +++ b/components/Tabs/src/TypographyThemer/MDCTabBarTypographyThemer.h @@ -0,0 +1,34 @@ +/* +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 "MaterialTabs.h" +#import "MaterialTypographyScheme.h" + +/** + Used to apply a typography scheme to theme MDCTabBar. + */ +@interface MDCTabBarTypographyThemer : NSObject + +/** + Applies a typography scheme to theme a MDCTabBar. + + @param typographyScheme The typography scheme to apply to MDCTabBar. + @param tabBar A MDCTabBar instance to apply a color scheme. + */ ++ (void)applyTypographyScheme:(nonnull id)typographyScheme + toTabBar:(nonnull MDCTabBar *)tabBar; + +@end diff --git a/components/Tabs/src/TypographyThemer/MDCTabBarTypographyThemer.m b/components/Tabs/src/TypographyThemer/MDCTabBarTypographyThemer.m new file mode 100644 index 00000000000..9ffe11cd75d --- /dev/null +++ b/components/Tabs/src/TypographyThemer/MDCTabBarTypographyThemer.m @@ -0,0 +1,27 @@ +/* + 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 "MDCTabBarTypographyThemer.h" + +@implementation MDCTabBarTypographyThemer + ++ (void)applyTypographyScheme:(nonnull id)typographyScheme + toTabBar:(nonnull MDCTabBar *)tabBar { + tabBar.selectedItemTitleFont = typographyScheme.button; + tabBar.unselectedItemTitleFont = typographyScheme.button; +} + +@end diff --git a/components/Tabs/tests/unit/MDCTabBarTypographyThemerTests.m b/components/Tabs/tests/unit/MDCTabBarTypographyThemerTests.m new file mode 100644 index 00000000000..65c324fc114 --- /dev/null +++ b/components/Tabs/tests/unit/MDCTabBarTypographyThemerTests.m @@ -0,0 +1,36 @@ +/* + 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 "MaterialTabs.h" +#import "MDCTabBarTypographyThemer.h" + +#import + +@interface MDCTabBarTypographyThemerTests : XCTestCase + +@end + +@implementation MDCTabBarTypographyThemerTests + +- (void)testTabBarFontThemerApplyFontSchemeProperly { + MDCTypographyScheme *typographyScheme = [[MDCTypographyScheme alloc] init]; + MDCTabBar *tabBar = [[MDCTabBar alloc] init]; + [MDCTabBarTypographyThemer applyTypographyScheme:typographyScheme toTabBar:tabBar]; + XCTAssertEqualObjects(tabBar.selectedItemTitleFont, typographyScheme.button); + XCTAssertEqualObjects(tabBar.unselectedItemTitleFont, typographyScheme.button); +} + +@end