Skip to content

Commit

Permalink
[Tabs] Implementing TabBar Typography Themer. (#3278)
Browse files Browse the repository at this point in the history
* Implementing TabBar Typography Themer.

* add typographyScheme to a tabbar example.

* couple of nits.
  • Loading branch information
mohammadcazig committed Apr 9, 2018
1 parent 42de89c commit 207e59d
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 0 deletions.
8 changes: 8 additions & 0 deletions MaterialComponents.podspec
Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions components/Tabs/BUILD
Expand Up @@ -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"]),
Expand All @@ -100,6 +115,7 @@ mdc_objc_library(
":Tabs",
":ColorThemer",
":FontThemer",
":TypographyThemer",
":private",
],
visibility = ["//visibility:private"],
Expand Down
Expand Up @@ -21,6 +21,7 @@
#import "TabBarIconExampleSupplemental.h"

#import "MaterialPalettes.h"
#import "MDCTabBarTypographyThemer.h"

// Exposing selectors defined in the main example class
@interface TabBarIconExample ()
Expand All @@ -37,6 +38,9 @@ - (void)setupExampleViews {
[self setupScrollingContent];

[self setupAlignmentButton];

MDCTypographyScheme *typographyScheme = [[MDCTypographyScheme alloc] init];
[MDCTabBarTypographyThemer applyTypographyScheme:typographyScheme toTabBar:self.tabBar];
}

- (void)setupAlignmentButton {
Expand Down
1 change: 1 addition & 0 deletions components/Tabs/src/FontThemer/MDCTabBarFontThemer.h
Expand Up @@ -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

Expand Down
34 changes: 34 additions & 0 deletions 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<MDCTypographyScheming>)typographyScheme
toTabBar:(nonnull MDCTabBar *)tabBar;

@end
27 changes: 27 additions & 0 deletions 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<MDCTypographyScheming>)typographyScheme
toTabBar:(nonnull MDCTabBar *)tabBar {
tabBar.selectedItemTitleFont = typographyScheme.button;
tabBar.unselectedItemTitleFont = typographyScheme.button;
}

@end
36 changes: 36 additions & 0 deletions 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 <XCTest/XCTest.h>

@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

0 comments on commit 207e59d

Please sign in to comment.