[NavigationBar] typography implementation.
* Navigation Bar Typography Themer implementation.
Tests and example added.
* fixing merge conflict mistake and tests.
MODIFY
MaterialComponents.podspec
MaterialComponents.podspec
@@ -460,6 +460,14 @@ Pod::Spec.new do |mdc|
extension.dependency "MaterialComponents/NavigationBar"
extension.dependency "MaterialComponents/schemes/Color"
end
+ component.subspec "TypographyThemer" do |extension|
+ extension.ios.deployment_target = '8.0'
+ extension.public_header_files = "components/NavigationBar/src/#{extension.base_name}/*.h"
+ extension.source_files = "components/NavigationBar/src/#{extension.base_name}/*.{h,m}"
+
+ extension.dependency "MaterialComponents/NavigationBar"
+ extension.dependency "MaterialComponents/schemes/Typography"
+ end
end
mdc.subspec "OverlayWindow" do |component|

MODIFY
components/NavigationBar/BUILD
components/NavigationBar/BUILD
@@ -47,6 +47,18 @@ 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"],
+ deps = [
+ ":NavigationBar",
+ "//components/schemes/Typography",
+ ],
+ visibility = ["//visibility:public"],
+)
+
mdc_objc_library(
name = "unit_test_sources",
testonly = 1,
@@ -61,6 +73,7 @@ mdc_objc_library(
deps = [
":NavigationBar",
":ColorThemer",
+ ":TypographyThemer",
"@material_text_accessibility_ios//:MDFTextAccessibility",
],
visibility = ["//visibility:private"],

MODIFY
components/NavigationBar/examples/NavigationBarIconsExample.m
components/NavigationBar/examples/NavigationBarIconsExample.m
#import "MaterialIcons+ic_reorder.h"
#import "MaterialNavigationBar.h"
#import "MDCNavigationBarColorThemer.h"
+#import "MDCNavigationBarTypographyThemer.h"
#import "supplemental/NavigationBarTypicalUseExampleSupplemental.h"
@interface NavigationBarIconsExample ()
self.navigationBar = [[MDCNavigationBar alloc] initWithFrame:CGRectZero];
self.navigationBar.translatesAutoresizingMaskIntoConstraints = NO;
[self.navigationBar observeNavigationItem:self.navigationItem];
+ MDCTypographyScheme *typographyScheme = [[MDCTypographyScheme alloc] init];
+ [MDCNavigationBarTypographyThemer applyTypographyScheme:typographyScheme
+ toNavigationBar:self.navigationBar];
[self.view addSubview:self.navigationBar];
id<MDCColorScheming> colorScheme = [[MDCSemanticColorScheme alloc] init];

ADD
components/NavigationBar/src/TypographyThemer/MDCNavigationBarTypographyThemer.h
+/*
+ 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 "MaterialNavigationBar.h"
+#import "MaterialTypographyScheme.h"
+
+/**
+ Used to apply a typography scheme to theme MDCNavigationBar.
+ */
+@interface MDCNavigationBarTypographyThemer : NSObject
+
+/**
+ Applies a typography scheme to theme a MDCNavigationBar.
+
+ @param typographyScheme The typography scheme to apply to MDCNavigationBar.
+ @param navigationBar A MDCNavigationBar instance to apply a typography scheme.
+ */
++ (void)applyTypographyScheme:(nonnull id<MDCTypographyScheming>)typographyScheme
+ toNavigationBar:(nonnull MDCNavigationBar *)navigationBar;
+
+@end

ADD
components/NavigationBar/src/TypographyThemer/MDCNavigationBarTypographyThemer.m
+/*
+ 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 "MDCNavigationBarTypographyThemer.h"
+
+@implementation MDCNavigationBarTypographyThemer
+
++ (void)applyTypographyScheme:(id<MDCTypographyScheming>)typographyScheme
+ toNavigationBar:(MDCNavigationBar *)navigationBar {
+ navigationBar.titleFont = typographyScheme.headline6;
+}
+
+@end

MODIFY
components/NavigationBar/tests/unit/NavigationBarTests.m
components/NavigationBar/tests/unit/NavigationBarTests.m
#import "MaterialButtonBar.h"
#import "MaterialNavigationBar.h"
+#import "MDCNavigationBarTypographyThemer.h"
static const CGFloat kEpsilonAccuracy = 0.001f;
@@ -293,6 +294,28 @@ static const CGFloat kEpsilonAccuracy = 0.001f;
}
}
+#pragma mark - Typography
+
+- (void)testTypographyThemer {
+ MDCNavigationBar *navBar = [[MDCNavigationBar alloc] init];
+ MDCTypographyScheme *scheme = [[MDCTypographyScheme alloc] init];
+ [MDCNavigationBarTypographyThemer applyTypographyScheme:scheme toNavigationBar:navBar];
+
+ // To enforce 20 point size we are using fontWithName:size: and for some reason even though the
+ // printout looks idential comparing the fonts returns false. (Using fontWithSize: did not work
+ // for system font medium, instead it returned a regular font).
+ UIFont *titleFont = navBar.titleLabel.font;
+ XCTAssertEqualObjects(titleFont.fontName, scheme.headline6.fontName);
+ XCTAssertEqual(titleFont.pointSize, scheme.headline6.pointSize);
+
+ // Weight for Fonts was not introduced on iOS 8
+ // TODO: remove this when we drop iOS 8 support.
+#if defined(__IPHONE_9_0) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0
+ XCTAssertEqual([NavigationBarTests weightForFont:titleFont],
+ [NavigationBarTests weightForFont:scheme.headline6]);
+#endif
+}
+
// I really don't like doing this but just to make sure the font has the right weight for the test
// I had to do this. Couldn't find any other way around it. When Apple support FontWithSize:
// properly for all fonts we can get rid of this.

[NavigationBar] typography implementation. (#3304)

* Navigation Bar Typography Themer implementation.
Tests and example added.

* fixing merge conflict mistake and tests.