Chips typography implementation.
Tests and example added.
MODIFY
MaterialComponents.podspec
MaterialComponents.podspec
@@ -247,6 +247,14 @@ Pod::Spec.new do |mdc|
extension.dependency "MaterialComponents/Chips"
extension.dependency "MaterialComponents/Themes"
end
+ component.subspec "TypographyThemer" do |extension|
+ extension.ios.deployment_target = '8.0'
+ extension.public_header_files = "components/Chips/src/#{extension.base_name}/*.h"
+ extension.source_files = "components/Chips/src/#{extension.base_name}/*.{h,m}"
+
+ extension.dependency "MaterialComponents/Chips"
+ extension.dependency "MaterialComponents/schemes/Typography"
+ end
end
mdc.subspec "CollectionCells" do |component|

MODIFY
components/Chips/BUILD
components/Chips/BUILD
@@ -51,6 +51,18 @@ mdc_objc_library(
],
)
+mdc_objc_library(
+ name = "TypographyThemer",
+ srcs = native.glob(["src/TypographyThemer/*.m"]),
+ hdrs = native.glob(["src/TypographyThemer/*.h"]),
+ includes = ["src/TypographyThemer"],
+ visibility = ["//visibility:public"],
+ deps = [
+ ":Chips",
+ "//components/schemes/Typography",
+ ],
+)
+
mdc_objc_library(
name = "private",
testonly = 1,
@@ -73,6 +85,7 @@ mdc_objc_library(
deps = [
":Chips",
":FontThemer",
+ ":TypographyThemer",
":private",
"//components/private/ShapeLibrary",
],

MODIFY
components/Chips/examples/ChipsTypicalUseViewController.m
components/Chips/examples/ChipsTypicalUseViewController.m
#import "ChipsExamplesSupplemental.h"
#import "MaterialChips.h"
+#import "MDCChipViewTypographyThemer.h"
@implementation ChipsTypicalUseViewController {
MDCChipView *_sizingChip;
if (self) {
_sizingChip = [[MDCChipView alloc] init];
_sizingChip.mdc_adjustsFontForContentSizeCategory = YES;
+ MDCTypographyScheme *typographyScheme = [[MDCTypographyScheme alloc] init];
+ [MDCChipViewTypographyThemer applyTypographyScheme:typographyScheme toChipView:_sizingChip];
}
return self;
}
ChipModel *model = self.model[indexPath.row];
[model apply:cell.chipView];
+ MDCTypographyScheme *typographyScheme = [[MDCTypographyScheme alloc] init];
+ [MDCChipViewTypographyThemer applyTypographyScheme:typographyScheme toChipView:cell.chipView];
return cell;
}

ADD
components/Chips/src/TypographyThemer/MDCChipViewTypographyThemer.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 "MaterialChips.h"
+#import "MaterialTypographyScheme.h"
+
+/**
+ Used to apply a typography scheme to theme MDCChipView.
+ */
+@interface MDCChipViewTypographyThemer : NSObject
+
+/**
+ Applies a typography scheme to theme an MDCChipView.
+
+ @param typographyScheme The typography scheme to apply to an MDCChipView.
+ @param chipView An MDCChipView instance to apply a typography scheme.
+ */
++ (void)applyTypographyScheme:(nonnull id<MDCTypographyScheming>)typographyScheme
+ toChipView:(nonnull MDCChipView *)chipView;
+
+@end

ADD
components/Chips/src/TypographyThemer/MDCChipViewTypographyThemer.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 "MDCChipViewTypographyThemer.h"
+
+@implementation MDCChipViewTypographyThemer
+
++ (void)applyTypographyScheme:(nonnull id<MDCTypographyScheming>)typographyScheme
+ toChipView:(nonnull MDCChipView *)chipView {
+ chipView.titleFont = typographyScheme.body2;
+}
+
+@end

ADD
components/Chips/tests/unit/ChipViewTypographyThemerTests.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 <XCTest/XCTest.h>
+
+#import "MaterialChips.h"
+#import "MDCChipViewTypographyThemer.h"
+
+@interface ChipViewTypographyThemerTests : XCTestCase
+
+@end
+
+@implementation ChipViewTypographyThemerTests
+
+- (void)testFontThemer {
+ MDCChipView *chip = [[MDCChipView alloc] init];
+ MDCTypographyScheme *typographyScheme = [[MDCTypographyScheme alloc] init];
+
+ [MDCChipViewTypographyThemer applyTypographyScheme:typographyScheme toChipView:chip];
+
+ XCTAssertEqualObjects(chip.titleLabel.font, typographyScheme.body2);
+}
+
+@end

Chips typography implementation. (#3312)

Tests and example added.