message:
[TextFields] Typography Themer implementation.
* TextFields Typography Themer added.
Tests and example included.
* Removing extra checks, comment the reason behind checking pointsize
* fixing typo.

diff:
@@ -681,6 +681,14 @@ end
extension.dependency "MaterialComponents/TextFields"
extension.dependency "MaterialComponents/Themes"
end
+ component.subspec "TypographyThemer" do |extension|
+ extension.ios.deployment_target = '8.0'
+ extension.public_header_files = "components/TextFields/src/#{extension.base_name}/*.h"
+ extension.source_files = "components/TextFields/src/#{extension.base_name}/*.{h,m}"
+
+ extension.dependency "MaterialComponents/TextFields"
+ extension.dependency "MaterialComponents/schemes/Typography"
+ end
end

old_path: components/TextFields/BUILD

new_path: components/TextFields/BUILD

diff:
@@ -64,6 +64,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 = [
+ ":TextFields",
+ "//components/schemes/Typography",
+ ],
+ visibility = ["//visibility:public"],
+)
+
mdc_objc_library(
name = "unit_test_sources",
testonly = 1,
@@ -77,6 +92,7 @@ mdc_objc_library(
":TextFields",
":ColorThemer",
":FontThemer",
+ ":TypographyThemer",
],
visibility = ["//visibility:private"],
)

diff:
@@ -282,7 +282,10 @@ final class TextFieldFilledSwiftExample: UIViewController {
func style(textInputController : MDCTextInputController) {
let colorScheme = MDCSemanticColorScheme()
MDCTextFieldColorThemer.applySemanticColorScheme(colorScheme, to:textInputController)
+ let typographyScheme = MDCTypographyScheme()
+ MDCTextFieldTypographyThemer.applyTypographyScheme(typographyScheme, to: textInputController)
}
+
func addGestureRecognizer() {
let tapRecognizer = UITapGestureRecognizer(target: self,
action: #selector(tapDidTouch(sender: )))

diff:
+/*
+ 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 "MaterialTextFields.h"
+#import "MaterialTypographyScheme.h"
+
+
+/**
+ Used to apply a typography scheme to theme an MDCTextField/MDCTextInputController.
+ */
+@interface MDCTextFieldTypographyThemer : NSObject
+
+/**
+ Applies a typography scheme to theme an MDCTextInputController instance.
+
+ @param typographyScheme The typography scheme that applies to a MDCTextInputController.
+ @param textInputController A MDCTextInputController instance that typography scheme will be applied
+ to.
+ */
++ (void)applyTypographyScheme:(nonnull id<MDCTypographyScheming>)typographyScheme
+ toTextInputController:(nonnull id<MDCTextInputController>)textInputController;
+
+/**
+ Applies a typography scheme to theme an specific class type responding to MDCTextInputController
+ protocol. Will not apply to existing instances.
+
+ @param typographyScheme The typography scheme that applies to a MDCTextInputController.
+ @param textInputControllerClass A MDCTextInputController class that typography scheme will be
+ applied to.
+ */
++ (void)applyTypographyScheme:(nonnull id<MDCTypographyScheming>)typographyScheme
+ toAllTextInputControllersOfClass:(nonnull Class<MDCTextInputController>)textInputControllerClass
+ NS_SWIFT_NAME(apply(_:toAllControllersOfClass:));
+
+/**
+ Applies a typography scheme to a MDCTextField instance.
+
+ @param typographyScheme The typography scheme that applies to an MDCTextField.
+ @param textInput An MDCTextInput instance that typography scheme will be applied to.
+ */
++ (void)applyTypographyScheme:(nonnull id<MDCTypographyScheming>)typographyScheme
+ toTextInput:(nonnull id<MDCTextInput>)textInput;
+
+@end

diff:
+/*
+ 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 "MDCTextFieldTypographyThemer.h"
+
+@implementation MDCTextFieldTypographyThemer
+
++ (void)applyTypographyScheme:(id<MDCTypographyScheming>)typographyScheme
+ toTextInputController:(id<MDCTextInputController>)textInputController {
+ textInputController.inlinePlaceholderFont = typographyScheme.subtitle1;
+ textInputController.leadingUnderlineLabelFont = typographyScheme.caption;
+ textInputController.trailingUnderlineLabelFont = typographyScheme.caption;
+ if ([textInputController
+ conformsToProtocol:@protocol(MDCTextInputControllerFloatingPlaceholder)]) {
+ id<MDCTextInputControllerFloatingPlaceholder> textInputControllerFloatingPlaceholder =
+ (id<MDCTextInputControllerFloatingPlaceholder>)textInputController;
+
+ // if caption.pointSize <= 0 there is no meaningful ratio so we fallback to default.
+ if (typographyScheme.caption.pointSize <= 0) {
+ textInputControllerFloatingPlaceholder.floatingPlaceholderScale = nil;
+ } else {
+ double ratio = typographyScheme.caption.pointSize/typographyScheme.subtitle1.pointSize;
+ textInputControllerFloatingPlaceholder.floatingPlaceholderScale =
+ [NSNumber numberWithDouble:ratio];
+ }
+ }
+}
+
++ (void)applyTypographyScheme:(id<MDCTypographyScheming>)typographyScheme
+ toTextInput:(id<MDCTextInput>)textInput {
+ textInput.font = typographyScheme.subtitle1;
+ textInput.placeholderLabel.font = typographyScheme.subtitle1;
+ textInput.leadingUnderlineLabel.font = typographyScheme.caption;
+ textInput.trailingUnderlineLabel.font = typographyScheme.caption;
+}
+
+// TODO: (larche) Drop this "#if !defined..." and the pragmas when we drop Xcode 8 support.
+// This is to silence a warning that doesn't appear in Xcode 9 when you use Class as an object.
+#if !defined(__IPHONE_11_0)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wobjc-method-access"
+#endif
++ (void)applyTypographyScheme:(id<MDCTypographyScheming>)typographyScheme
+ toAllTextInputControllersOfClass:(Class<MDCTextInputController>)textInputControllerClass {
+ [textInputControllerClass setInlinePlaceholderFontDefault:typographyScheme.subtitle1];
+ [textInputControllerClass setTrailingUnderlineLabelFontDefault:typographyScheme.caption];
+ [textInputControllerClass setLeadingUnderlineLabelFontDefault:typographyScheme.caption];
+ if ([textInputControllerClass
+ conformsToProtocol:@protocol(MDCTextInputControllerFloatingPlaceholder)]) {
+ Class<MDCTextInputControllerFloatingPlaceholder> textInputControllerFloatingPlaceholderClass =
+ (Class<MDCTextInputControllerFloatingPlaceholder>)textInputControllerClass;
+ // if caption.pointSize <= 0 there is no meaningful ratio so we fallback to default.
+ if (typographyScheme.caption.pointSize <= 0) {
+ [textInputControllerFloatingPlaceholderClass setFloatingPlaceholderScaleDefault:0];
+ } else {
+ CGFloat scale = typographyScheme.caption.pointSize/typographyScheme.subtitle1.pointSize;
+ [textInputControllerFloatingPlaceholderClass setFloatingPlaceholderScaleDefault:scale];
+ }
+ }
+}
+#if !defined(__IPHONE_11_0)
+#pragma clang diagnostic pop
+#endif
+
+
+@end

diff:
+/*
+ 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 "MaterialTextFields.h"
+#import "MaterialThemes.h"
+#import "MDCTextFieldTypographyThemer.h"
+
+@interface MDCTextFieldTypographyThemer (ResetDefaults)
+
++ (void)resetDefaultsForClass:(Class<MDCTextInputController>)class;
+
+@end
+
+@implementation MDCTextFieldTypographyThemer (ResetDefaults)
+
+// TODO: (larche) Drop this if defined and the pragmas when we drop Xcode 8 support.
+// This is to silence a warning that doesn't appear in Xcode 9 when you use Class as an object.
+#if !defined(__IPHONE_11_0)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wobjc-method-access"
+#endif
++ (void)resetDefaultsForClass:(Class<MDCTextInputController>)textInputControllerClass {
+ [textInputControllerClass setInlinePlaceholderFontDefault:nil];
+ [textInputControllerClass setTrailingUnderlineLabelFontDefault:nil];
+ [textInputControllerClass setLeadingUnderlineLabelFontDefault:nil];
+
+ if ([textInputControllerClass
+ conformsToProtocol:@protocol(MDCTextInputControllerFloatingPlaceholder)]) {
+ Class<MDCTextInputControllerFloatingPlaceholder> textInputControllerFloatingPlaceholderClass =
+ (Class<MDCTextInputControllerFloatingPlaceholder>)textInputControllerClass;
+ [textInputControllerFloatingPlaceholderClass setFloatingPlaceholderScaleDefault:0];
+ }
+}
+#if !defined(__IPHONE_11_0)
+#pragma clang diagnostic pop
+#endif
+
+@end
+
+@interface TextFieldTypographyThemer : XCTestCase
+
+@end
+
+@implementation TextFieldTypographyThemer
+
+- (void)tearDown {
+ [super tearDown];
+ [MDCTextFieldTypographyThemer resetDefaultsForClass:[MDCTextInputControllerFullWidth class]];
+ [MDCTextFieldTypographyThemer resetDefaultsForClass:[MDCTextInputControllerBase class]];
+}
+
+- (void)testTypographyThemerSetsTheFontsForTextFieldProperly {
+ MDCTextField *textField = [[MDCTextField alloc] initWithFrame:CGRectZero];
+ textField.font = [UIFont systemFontOfSize:28];
+ textField.leadingUnderlineLabel.font = [UIFont systemFontOfSize:28];
+ textField.trailingUnderlineLabel.font = [UIFont systemFontOfSize:28];
+ textField.placeholderLabel.font = [UIFont systemFontOfSize:28];
+ MDCTypographyScheme *typographyScheme = [[MDCTypographyScheme alloc] init];
+ [MDCTextFieldTypographyThemer applyTypographyScheme:typographyScheme toTextInput:textField];
+ XCTAssertEqualObjects(textField.leadingUnderlineLabel.font, typographyScheme.caption);
+ XCTAssertEqualObjects(textField.trailingUnderlineLabel.font, typographyScheme.caption);
+ XCTAssertEqualObjects(textField.placeholderLabel.font, typographyScheme.subtitle1);
+ XCTAssertEqualObjects(textField.font, typographyScheme.subtitle1);
+}
+
+- (void)testTypographyThemerSetsTheFontsForTextInputControllerClass {
+ MDCTypographyScheme *typographyScheme = [[MDCTypographyScheme alloc] init];
+ [MDCTextFieldTypographyThemer applyTypographyScheme:typographyScheme
+ toAllTextInputControllersOfClass:[MDCTextInputControllerFullWidth class]];
+ XCTAssertEqualObjects([MDCTextInputControllerFullWidth trailingUnderlineLabelFontDefault],
+ typographyScheme.caption);
+ XCTAssertEqualObjects([MDCTextInputControllerFullWidth inlinePlaceholderFontDefault],
+ typographyScheme.subtitle1);
+}
+
+- (void)testTypographyThemerSetsTheFontsForTextInputControllerFloatingPlaceHolderClass {
+ MDCTypographyScheme *typographyScheme = [[MDCTypographyScheme alloc] init];
+ [MDCTextFieldTypographyThemer applyTypographyScheme:typographyScheme
+ toAllTextInputControllersOfClass:[MDCTextInputControllerBase class]];
+ XCTAssertEqualObjects([MDCTextInputControllerBase trailingUnderlineLabelFontDefault],
+ typographyScheme.caption);
+ XCTAssertEqualObjects([MDCTextInputControllerBase leadingUnderlineLabelFontDefault],
+ typographyScheme.caption);
+ XCTAssertEqualObjects([MDCTextInputControllerBase inlinePlaceholderFontDefault],
+ typographyScheme.subtitle1);
+ XCTAssertEqual([MDCTextInputControllerBase floatingPlaceholderScaleDefault],
+ typographyScheme.caption.pointSize/typographyScheme.subtitle1.pointSize);
+}
+
+- (void)testTypographyThemerSetsTheFontsForTextInputControllerInstance {
+ MDCTextInputControllerFullWidth *inputController = [[MDCTextInputControllerFullWidth alloc] init];
+ inputController.trailingUnderlineLabelFont = [UIFont systemFontOfSize:80];
+ inputController.inlinePlaceholderFont = [UIFont systemFontOfSize:80];
+ MDCTypographyScheme *typographyScheme = [[MDCTypographyScheme alloc] init];
+ [MDCTextFieldTypographyThemer applyTypographyScheme:typographyScheme
+ toTextInputController:inputController];
+ XCTAssertEqualObjects(inputController.trailingUnderlineLabelFont, typographyScheme.caption);
+ XCTAssertEqualObjects(inputController.inlinePlaceholderFont, typographyScheme.subtitle1);
+}
+
+- (void)testTypographyThemerSetsTheFontsForTextInputControllerFloatingPlaceHolderInstance {
+ MDCTextInputControllerBase *floatingInputController = [[MDCTextInputControllerBase alloc] init];
+ floatingInputController.trailingUnderlineLabelFont = [UIFont systemFontOfSize:80];
+ floatingInputController.leadingUnderlineLabelFont = [UIFont systemFontOfSize:80];
+ floatingInputController.inlinePlaceholderFont = [UIFont systemFontOfSize:80];
+ MDCTypographyScheme *typographyScheme = [[MDCTypographyScheme alloc] init];
+ [MDCTextFieldTypographyThemer applyTypographyScheme:typographyScheme
+ toTextInputController:floatingInputController];
+ XCTAssertEqualObjects(floatingInputController.trailingUnderlineLabelFont,
+ typographyScheme.caption);
+ XCTAssertEqualObjects(floatingInputController.leadingUnderlineLabelFont,
+ typographyScheme.caption);
+ XCTAssertEqualObjects(floatingInputController.inlinePlaceholderFont, typographyScheme.subtitle1);
+ XCTAssertEqual([floatingInputController.floatingPlaceholderScale doubleValue],
+ typographyScheme.caption.pointSize/typographyScheme.subtitle1.pointSize);
+}
+
+@end

original_message:
[TextFields] Typography Themer implementation. (#3303)

* TextFields Typography Themer added.
Tests and example included.

* Removing extra checks, comment the reason behind checking pointsize

* fixing typo.


message:
Chips typography implementation.
Tests and example added.

change_type: MODIFY

diff:
@@ -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|

old_path: components/Chips/BUILD

new_path: components/Chips/BUILD

diff:
@@ -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",
],

diff:
#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;
}

change_type: ADD

diff:
+/*
+ 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

diff:
+/*
+ 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

diff:
+/*
+ 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

license: Apache License 2.0

original_message:
Chips typography implementation. (#3312)

Tests and example added.


diff:
@@ -970,7 +970,7 @@ static const CGFloat kSingleCycleRotation =
#pragma mark - Accessibility
- (BOOL)isAccessibilityElement {
- return YES;
+ return self.isAnimating;
}
- (NSString *)accessibilityLabel {

original_message:
MDCActivityIndicator shouldnt register as accessibility element when hidden (#3331)

#3233
https://www.pivotaltracker.com/story/show/156738102


message:
[BottomSheet] Adds a setting to make sheets impossible to dismiss.
Exported from an internally lgtm'ed CL: cl/192175794

diff:
*/
@property(nonatomic, weak, nullable) UIScrollView *trackingScrollView;
+/**
+ When set to false, the bottom sheet controller can't be dismissed by tapping outside of sheet area.
+ */
+@property(nonatomic, assign) BOOL dismissOnBackgroundTap;
+
/**
The bottom sheet delegate.
*/

diff:
super.transitioningDelegate = _transitionController;
super.modalPresentationStyle = UIModalPresentationCustom;
+ self.dismissOnBackgroundTap = YES;
}
return self;
}
}
- (BOOL)accessibilityPerformEscape {
+ if (!self.dismissOnBackgroundTap) {
+ return NO;
+ }
[self dismissViewControllerAnimated:YES completion:nil];
return YES;
}
_transitionController.trackingScrollView = trackingScrollView;
}
+- (BOOL)dismissOnBackgroundTap {
+ return _transitionController.dismissOnBackgroundTap;
+}
+
+- (void)setDismissOnBackgroundTap:(BOOL)dismissOnBackgroundTap {
+ _transitionController.dismissOnBackgroundTap = dismissOnBackgroundTap;
+ self.mdc_bottomSheetPresentationController.dismissOnBackgroundTap = dismissOnBackgroundTap;
+}
+
/* Disable setter. Always use internal transition controller */
- (void)setTransitioningDelegate:
(__unused id<UIViewControllerTransitioningDelegate>)transitioningDelegate {

diff:
*/
@property(nonatomic, weak, nullable) UIScrollView *trackingScrollView;
+/**
+ When set to false, the bottom sheet controller can't be dismissed by tapping outside of sheet area.
+ */
+@property(nonatomic, assign) BOOL dismissOnBackgroundTap;
+
/**
Delegate to tell the presenter when to dismiss.
*/

diff:
@@ -174,6 +174,9 @@ static UIScrollView *MDCBottomSheetGetPrimaryScrollView(UIViewController *viewCo
}
- (void)dismissPresentedControllerIfNecessary:(UITapGestureRecognizer *)tapRecognizer {
+ if (!_dismissOnBackgroundTap) {
+ return;
+ }
// Only dismiss if the tap is outside of the presented view.
UIView *contentView = self.presentedViewController.view;
CGPoint pointInContentView = [tapRecognizer locationInView:contentView];

diff:
*/
@property(nonatomic, weak, nullable) UIScrollView *trackingScrollView;
+/**
+ When set to false, the bottom sheet controller can't be dismissed by tapping outside of sheet area.
+ */
+@property(nonatomic, assign) BOOL dismissOnBackgroundTap;
+
@end

diff:
@@ -32,6 +32,7 @@ static const NSTimeInterval MDCBottomSheetTransitionDuration = 0.25;
[[MDCBottomSheetPresentationController alloc] initWithPresentedViewController:presented
presentingViewController:presenting];
presentationController.trackingScrollView = self.trackingScrollView;
+ presentationController.dismissOnBackgroundTap = self.dismissOnBackgroundTap;
return presentationController;
}

original_message:
[BottomSheet] Adds a setting to make sheets impossible to dismiss. (#3325)

Exported from an internally lgtm'ed CL: cl/192175794


message:
[TextFields] Adding the expected opacities to color themer.
* Adding the expected opacities to color themer for textfields.
Updated tests.
* making sure precision is defined for constant values.
* define the type of values to be float (warning as error fix)

diff:
+ (void)applySemanticColorScheme:(id<MDCColorScheming>)colorScheme
toTextInputController:(id<MDCTextInputController>)textInputController {
+ UIColor *onSurface87Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.87f];
+ UIColor *onSurface60Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.60f];
textInputController.activeColor = colorScheme.primaryColor;
textInputController.errorColor = colorScheme.errorColor;
- textInputController.normalColor = colorScheme.onSurfaceColor;
- textInputController.inlinePlaceholderColor = colorScheme.onSurfaceColor;
- textInputController.trailingUnderlineLabelTextColor = colorScheme.onSurfaceColor;
- textInputController.leadingUnderlineLabelTextColor = colorScheme.onSurfaceColor;
+ textInputController.normalColor = onSurface87Opacity;
+ textInputController.inlinePlaceholderColor = onSurface60Opacity;
+ textInputController.trailingUnderlineLabelTextColor = onSurface60Opacity;
+ textInputController.leadingUnderlineLabelTextColor = onSurface60Opacity;
if ([textInputController
conformsToProtocol:@protocol(MDCTextInputControllerFloatingPlaceholder)]) {
if ([textInputControllerFloatingPlaceholder
respondsToSelector:@selector(setFloatingPlaceholderNormalColor:)]) {
- textInputControllerFloatingPlaceholder.floatingPlaceholderNormalColor =
- colorScheme.primaryColor;
+ UIColor *primary87Opacity = [colorScheme.primaryColor colorWithAlphaComponent:0.87f];
+ textInputControllerFloatingPlaceholder.floatingPlaceholderNormalColor = primary87Opacity;
}
}
}
+ (void)applySemanticColorScheme:(nonnull id<MDCColorScheming>)colorScheme
toTextInput:(nonnull id<MDCTextInput>)textInput {
+ UIColor *onSurface87Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.87f];
+ UIColor *onSurface60Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.60f];
textInput.cursorColor = colorScheme.primaryColor;
- textInput.textColor = colorScheme.onSurfaceColor;
- textInput.placeholderLabel.textColor = colorScheme.onSurfaceColor;
- textInput.trailingUnderlineLabel.textColor = colorScheme.onSurfaceColor;
- textInput.leadingUnderlineLabel.textColor = colorScheme.onSurfaceColor;
+ textInput.textColor = onSurface87Opacity;
+ textInput.placeholderLabel.textColor = onSurface60Opacity;
+ textInput.trailingUnderlineLabel.textColor = onSurface60Opacity;
+ textInput.leadingUnderlineLabel.textColor = onSurface60Opacity;
}
// TODO: (larche) Drop this if defined and the pragmas when we drop Xcode 8 support.
#endif
+ (void)applySemanticColorScheme:(id<MDCColorScheming>)colorScheme
toAllTextInputControllersOfClass:(Class<MDCTextInputController>)textInputControllerClass {
+ UIColor *onSurface87Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.87f];
+ UIColor *onSurface60Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.60f];
[textInputControllerClass setActiveColorDefault:colorScheme.primaryColor];
[textInputControllerClass setErrorColorDefault:colorScheme.errorColor];
- [textInputControllerClass setNormalColorDefault:colorScheme.onSurfaceColor];
- [textInputControllerClass setInlinePlaceholderColorDefault:colorScheme.onSurfaceColor];
- [textInputControllerClass setTrailingUnderlineLabelTextColorDefault:colorScheme.onSurfaceColor];
- [textInputControllerClass setLeadingUnderlineLabelTextColorDefault:colorScheme.onSurfaceColor];
+ [textInputControllerClass setNormalColorDefault:onSurface87Opacity];
+ [textInputControllerClass setInlinePlaceholderColorDefault:onSurface60Opacity];
+ [textInputControllerClass setTrailingUnderlineLabelTextColorDefault:onSurface60Opacity];
+ [textInputControllerClass setLeadingUnderlineLabelTextColorDefault:onSurface60Opacity];
if ([textInputControllerClass
conformsToProtocol:@protocol(MDCTextInputControllerFloatingPlaceholder)]) {
Class<MDCTextInputControllerFloatingPlaceholder> textInputControllerFloatingPlaceholderClass =
(Class<MDCTextInputControllerFloatingPlaceholder>)textInputControllerClass;
+ UIColor *primary87Opacity = [colorScheme.primaryColor colorWithAlphaComponent:0.87f];
[textInputControllerFloatingPlaceholderClass
- setFloatingPlaceholderNormalColorDefault:colorScheme.primaryColor];
+ setFloatingPlaceholderNormalColorDefault:primary87Opacity];
}
}
#if !defined(__IPHONE_11_0)

diff:
- (void)testDefaultValuesAreSet {
MDCSemanticColorScheme *colorScheme = [[MDCSemanticColorScheme alloc] init];
+ UIColor *primary87Opacity = [colorScheme.primaryColor colorWithAlphaComponent:0.87f];
+ UIColor *onSurface87Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.87f];
+ UIColor *onSurface60Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.60f];
+
XCTAssertEqualObjects(MDCTextInputControllerBase.activeColorDefault, colorScheme.primaryColor);
XCTAssertEqualObjects(MDCTextInputControllerBase.errorColorDefault, colorScheme.errorColor);
- XCTAssertEqualObjects(MDCTextInputControllerBase.normalColorDefault, colorScheme.onSurfaceColor);
+ XCTAssertEqualObjects(MDCTextInputControllerBase.normalColorDefault, onSurface87Opacity);
XCTAssertEqualObjects(MDCTextInputControllerBase.inlinePlaceholderColorDefault,
- colorScheme.onSurfaceColor);
+ onSurface60Opacity);
XCTAssertEqualObjects(MDCTextInputControllerBase.trailingUnderlineLabelTextColorDefault,
- colorScheme.onSurfaceColor);
+ onSurface60Opacity);
XCTAssertEqualObjects(MDCTextInputControllerBase.leadingUnderlineLabelTextColorDefault,
- colorScheme.onSurfaceColor);
+ onSurface60Opacity);
XCTAssertEqualObjects(MDCTextInputControllerBase.floatingPlaceholderNormalColorDefault,
- colorScheme.primaryColor);
+ primary87Opacity);
XCTAssertEqualObjects(MDCTextInputControllerFullWidth.errorColorDefault, colorScheme.errorColor);
XCTAssertEqualObjects(MDCTextInputControllerFullWidth.inlinePlaceholderColorDefault,
- colorScheme.onSurfaceColor);
+ onSurface60Opacity);
XCTAssertEqualObjects(MDCTextInputControllerFullWidth.trailingUnderlineLabelTextColorDefault,
- colorScheme.onSurfaceColor);
+ onSurface60Opacity);
}
- (void)testInstanceColorValuesAreSet {
+ MDCSemanticColorScheme *colorScheme = [[MDCSemanticColorScheme alloc] init];
+ colorScheme.primaryColor = [UIColor blueColor];
+ colorScheme.errorColor = [UIColor yellowColor];
+ colorScheme.onSurfaceColor = [UIColor greenColor];
+ colorScheme.errorColor = [UIColor redColor];
+
+ UIColor *onSurface87Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.87f];
+ UIColor *onSurface60Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.60f];
+
MDCTextField *textField = [[MDCTextField alloc] initWithFrame:CGRectZero];
MDCTextField *baseTextField = [[MDCTextField alloc] initWithFrame:CGRectZero];
MDCTextField *fullWidthTextField = [[MDCTextField alloc] initWithFrame:CGRectZero];
MDCTextInputControllerFullWidth *fullWidthInputController =
[[MDCTextInputControllerFullWidth alloc] initWithTextInput:fullWidthTextField];
- MDCSemanticColorScheme *colorScheme = [[MDCSemanticColorScheme alloc] init];
- colorScheme.primaryColor = [UIColor blueColor];
- colorScheme.errorColor = [UIColor yellowColor];
- colorScheme.onSurfaceColor = [UIColor greenColor];
- colorScheme.errorColor = [UIColor redColor];
[MDCTextFieldColorThemer applySemanticColorScheme:colorScheme
toTextInput:textField];
XCTAssertEqualObjects(textField.cursorColor, colorScheme.primaryColor);
- XCTAssertEqualObjects(textField.textColor, colorScheme.onSurfaceColor);
- XCTAssertEqualObjects(textField.placeholderLabel.textColor, colorScheme.onSurfaceColor);
- XCTAssertEqualObjects(textField.trailingUnderlineLabel.textColor, colorScheme.onSurfaceColor);
- XCTAssertEqualObjects(textField.leadingUnderlineLabel.textColor, colorScheme.onSurfaceColor);
+ XCTAssertEqualObjects(textField.textColor, onSurface87Opacity);
+ XCTAssertEqualObjects(textField.placeholderLabel.textColor, onSurface60Opacity);
+ XCTAssertEqualObjects(textField.trailingUnderlineLabel.textColor, onSurface60Opacity);
+ XCTAssertEqualObjects(textField.leadingUnderlineLabel.textColor, onSurface60Opacity);
[MDCTextFieldColorThemer applySemanticColorScheme:colorScheme
toTextInputController:baseInputController];
XCTAssertEqualObjects(baseInputController.activeColor, colorScheme.primaryColor);
XCTAssertEqualObjects(baseInputController.errorColor, colorScheme.errorColor);
- XCTAssertEqualObjects(baseInputController.normalColor, colorScheme.onSurfaceColor);
- XCTAssertEqualObjects(baseInputController.inlinePlaceholderColor, colorScheme.onSurfaceColor);
- XCTAssertEqualObjects(baseInputController.trailingUnderlineLabelTextColor,
- colorScheme.onSurfaceColor);
- XCTAssertEqualObjects(baseInputController.leadingUnderlineLabelTextColor,
- colorScheme.onSurfaceColor);
+ XCTAssertEqualObjects(baseInputController.normalColor, onSurface87Opacity);
+ XCTAssertEqualObjects(baseInputController.inlinePlaceholderColor, onSurface60Opacity);
+ XCTAssertEqualObjects(baseInputController.trailingUnderlineLabelTextColor, onSurface60Opacity);
+ XCTAssertEqualObjects(baseInputController.leadingUnderlineLabelTextColor, onSurface60Opacity);
[MDCTextFieldColorThemer applySemanticColorScheme:colorScheme
toTextInputController:fullWidthInputController];
XCTAssertEqualObjects(fullWidthInputController.errorColor, colorScheme.errorColor);
- XCTAssertEqualObjects(fullWidthInputController.inlinePlaceholderColor,
- colorScheme.onSurfaceColor);
+ XCTAssertEqualObjects(fullWidthInputController.inlinePlaceholderColor, onSurface60Opacity);
XCTAssertEqualObjects(fullWidthInputController.trailingUnderlineLabelTextColor,
- colorScheme.onSurfaceColor);
+ onSurface60Opacity);
}
@end

original_message:
[TextFields] Adding the expected opacities to color themer. (#3347)

* Adding the expected opacities to color themer for textfields.
Updated tests.

* making sure precision is defined for constant values.

* define the type of values to be float (warning as error fix)


message:
Fix crasher within tab example
Triggering loadView in init causes a crash when instantiating through a nib

diff:
@@ -78,7 +78,7 @@ const CGFloat MDCTabBarViewControllerAnimationDuration = 0.3f;
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
- self.viewControllers = [aDecoder decodeObjectOfClass:[NSArray class]
+ _viewControllers = [aDecoder decodeObjectOfClass:[NSArray class]
forKey:MDCTabBarViewControllerViewControllersKey];
self.selectedViewController =
[aDecoder decodeObjectOfClass:[UIViewController class]

original_message:
Fix crasher within tab example (#3370)

Triggering loadView in init causes a crash when instantiating through a nib


message:
[Chips] Adding Examples/Documentation for all chips types.
* Added example for Action Chips Type.
Cleaned up/Documented the examples for Filter and Choice chips type.
Added More documentation to MDCChipCollectionViewCell.
* typo.
PR:

diff:
+/*
+ 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 "ChipsExamplesSupplemental.h"
+
+#import "MaterialChips.h"
+#import "MDCChipViewColorThemer.h"
+
+@implementation ChipsActionExampleViewController {
+ UICollectionView *_collectionView;
+ MDCChipView *_sizingChip;
+ MDCSemanticColorScheme *_colorScheme;
+}
+
+- (void)loadView {
+ [super loadView];
+
+ _colorScheme = [[MDCSemanticColorScheme alloc] init];
+
+ // Our preferred CollectionView Layout For chips
+ MDCChipCollectionViewFlowLayout *layout = [[MDCChipCollectionViewFlowLayout alloc] init];
+ layout.minimumInteritemSpacing = 10;
+
+
+ // Action chips should allow single selection, collection view default is based on single
+ // selection. Note that MDCChipCollectionViewCell manages the state of the chip accordingly.
+ _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
+
+ // Since there is no scrolling turning off the delaysContentTouches makes the cells respond faster
+ _collectionView.delaysContentTouches = NO;
+
+ // Collection view setup
+ _collectionView.dataSource = self;
+ _collectionView.delegate = self;
+ _collectionView.backgroundColor = [UIColor whiteColor];
+ _collectionView.contentInset = UIEdgeInsetsMake(4, 8, 4, 8);
+ [_collectionView registerClass:[MDCChipCollectionViewCell class]
+ forCellWithReuseIdentifier:@"Cell"];
+
+ // This is used to calculate the size of each chip based on the chip setup
+ _sizingChip = [[MDCChipView alloc] init];
+
+ [self.view addSubview:_collectionView];
+}
+
+- (void)viewWillLayoutSubviews {
+ [super viewWillLayoutSubviews];
+
+ _collectionView.frame = self.view.bounds;
+}
+
+- (NSInteger)collectionView:(UICollectionView *)collectionView
+ numberOfItemsInSection:(NSInteger)section {
+ return self.titles.count;
+}
+
+- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
+ cellForItemAtIndexPath:(NSIndexPath *)indexPath {
+ MDCChipCollectionViewCell *cell =
+ [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
+ MDCChipView *chipView = cell.chipView;
+
+ // Customize Chip
+ chipView.titleLabel.text = self.titles[indexPath.row];
+
+ // Apply Theming
+ [MDCChipViewColorThemer applySemanticColorScheme:_colorScheme toChipView:cell.chipView];
+
+ return cell;
+}
+
+- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
+ // For action chips, we never want the chip to stay in selected state.
+ // Other possible apporaches would be relying on theming or Customizing collectionViewCell
+ // selected state.
+ [collectionView deselectItemAtIndexPath:indexPath animated:NO];
+
+ // Do the action related to the chip
+ [self setTitle:[NSString stringWithFormat:@"Action %d", (int)indexPath.row]];
+
+}
+
+- (CGSize)collectionView:(UICollectionView *)collectionView
+ layout:(UICollectionViewLayout*)collectionViewLayout
+ sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
+ _sizingChip.titleLabel.text = self.titles[indexPath.row];
+ return [_sizingChip sizeThatFits:collectionView.bounds.size];
+}
+
+- (NSArray *)titles {
+ if (!_titles) {
+ _titles = @[
+ @"Change Title to Action 0",
+ @"Change Title to Action 1",
+ @"Change Title to Action 2",
+ @"Change Title to Action 3",
+ ];
+ }
+ return _titles;
+}
+
+@end
+

diff:
@implementation ChipsChoiceExampleViewController {
MDCSemanticColorScheme *_colorScheme;
+ MDCChipView *_sizingChip;
}
- (void)loadView {
_colorScheme = [[MDCSemanticColorScheme alloc] init];
- CGSize estimatedItemSize = CGSizeMake(60, 33);
- CGRect collectionStartingRect = CGRectMake(0, 0, 100, estimatedItemSize.height);
+ // This is used to calculate the size of each chip based on the chip setup
+ _sizingChip = [[MDCChipView alloc] init];
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
- layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
- layout.minimumInteritemSpacing = 10.0f;
- layout.estimatedItemSize = estimatedItemSize;
+ // Our preferred CollectionView Layout For chips
+ MDCChipCollectionViewFlowLayout *layout = [[MDCChipCollectionViewFlowLayout alloc] init];
+ layout.minimumInteritemSpacing = 10;
- _collectionView = [[UICollectionView alloc] initWithFrame:collectionStartingRect
- collectionViewLayout:layout];
+ _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
+
+ // Since there is no scrolling turning off the delaysContentTouches makes the cells respond faster
+ _collectionView.delaysContentTouches = NO;
+
+ // Collection view setup
_collectionView.dataSource = self;
_collectionView.delegate = self;
_collectionView.backgroundColor = [UIColor whiteColor];
- _collectionView.delaysContentTouches = NO;
- _collectionView.clipsToBounds = NO;
+ _collectionView.contentInset = UIEdgeInsetsMake(20, 20, 20, 20);
[_collectionView registerClass:[MDCChipCollectionViewCell class]
forCellWithReuseIdentifier:@"Cell"];
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
- // increased the height so bottom slider doesn't overlap with chips
- _collectionView.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 45);
+ _collectionView.frame = self.view.bounds;
}
+
- (NSInteger)collectionView:(UICollectionView *)collectionView
numberOfItemsInSection:(NSInteger)section {
return self.titles.count;
cellForItemAtIndexPath:(NSIndexPath *)indexPath {
MDCChipCollectionViewCell *cell =
[collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
- cell.chipView.titleLabel.text = self.titles[indexPath.row];
- // Every other chip is stroked
- if (indexPath.row % 2) {
- [cell.chipView setBorderWidth:0 forState:UIControlStateNormal];
- [MDCChipViewColorThemer applySemanticColorScheme:_colorScheme toChipView:cell.chipView];
- } else {
- [cell.chipView setBorderWidth:1 forState:UIControlStateNormal];
- [MDCChipViewColorThemer applySemanticColorScheme:_colorScheme
- toStrokedChipView:cell.chipView];
- }
+ MDCChipView *chipView = cell.chipView;
+
+ // Customize Chip
+ chipView.titleLabel.text = self.titles[indexPath.row];
+
return cell;
}
+- (CGSize)collectionView:(UICollectionView *)collectionView
+ layout:(UICollectionViewLayout*)collectionViewLayout
+ sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
+
+ // The size of the chip depends on title here.
+ _sizingChip.titleLabel.text = self.titles[indexPath.row];
+ return [_sizingChip sizeThatFits:collectionView.bounds.size];
+}
+
- (NSArray *)titles {
if (!_titles) {
_titles = @[

diff:
_colorScheme = [[MDCSemanticColorScheme alloc] init];
+ // Our preferred CollectionView Layout For chips
MDCChipCollectionViewFlowLayout *layout = [[MDCChipCollectionViewFlowLayout alloc] init];
layout.minimumInteritemSpacing = 10;
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
+ // Filter chips should allow multiSelection, MDCChipCollectionViewCell manages the state of the
+ // chip accordingly.
+ _collectionView.allowsMultipleSelection = YES;
+
+ // Since there is no scrolling turning off the delaysContentTouches makes the cells respond faster
+ _collectionView.delaysContentTouches = NO;
+
+ // Collection view setup
_collectionView.dataSource = self;
_collectionView.delegate = self;
- _collectionView.allowsMultipleSelection = YES;
_collectionView.backgroundColor = [UIColor whiteColor];
- _collectionView.delaysContentTouches = NO;
_collectionView.contentInset = UIEdgeInsetsMake(4, 8, 4, 8);
[_collectionView registerClass:[MDCChipCollectionViewCell class]
forCellWithReuseIdentifier:@"Cell"];
+ // This is used to calculate the size of each chip based on the chip setup
_sizingChip = [[MDCChipView alloc] init];
[self.view addSubview:_collectionView];
cellForItemAtIndexPath:(NSIndexPath *)indexPath {
MDCChipCollectionViewCell *cell =
[collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
- cell.chipView.titleLabel.text = self.titles[indexPath.row];
- cell.chipView.selectedImageView.image = [self doneImage];
+ MDCChipView *chipView = cell.chipView;
+
+ // Customize Chip
+ chipView.titleLabel.text = self.titles[indexPath.row];
+ chipView.selectedImageView.image = [self doneImage];
cell.alwaysAnimateResize = YES;
- if (indexPath.row % 2) {
- [cell.chipView setBorderWidth:0 forState:UIControlStateNormal];
- [MDCChipViewColorThemer applySemanticColorScheme:_colorScheme toChipView:cell.chipView];
- } else {
- [cell.chipView setBorderWidth:1 forState:UIControlStateNormal];
- [MDCChipViewColorThemer applySemanticColorScheme:_colorScheme
- toStrokedChipView:cell.chipView];
- }
+
return cell;
}
layout:(UICollectionViewLayout*)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
NSArray *selectedPaths = [collectionView indexPathsForSelectedItems];
+
+ // The size of the chip depends on title, image and selection state.
_sizingChip.selected = [selectedPaths containsObject:indexPath];
_sizingChip.titleLabel.text = self.titles[indexPath.row];
_sizingChip.selectedImageView.image = [self doneImage];
- (void)collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
+ // Animating Chip Selection
[collectionView performBatchUpdates:nil completion:nil];
}
- (void)collectionView:(UICollectionView *)collectionView
didDeselectItemAtIndexPath:(NSIndexPath *)indexPath {
+ // Animating Chip Deselection
[collectionView performBatchUpdates:nil completion:nil];
}

diff:
@property(nonatomic, strong) UICollectionView *collectionView;
@end
+@interface ChipsActionExampleViewController : UIViewController
+ <UICollectionViewDelegate, UICollectionViewDataSource>
+@property(nonatomic, strong) NSArray<NSString *> *titles;
+@property(nonatomic, strong) UICollectionView *collectionView;
+@end
+
@interface ChipsCollectionExampleViewController : ExampleChipCollectionViewController
<UICollectionViewDelegate, UICollectionViewDataSource>
@property(nonatomic, strong) NSArray<NSString *> *titles;

diff:
@@ -88,6 +88,25 @@ static UIButton *DeleteButton() {
@end
+@interface ChipsActionExampleViewController (Supplemental)
+@end
+
+@implementation ChipsActionExampleViewController (Supplemental)
+
++ (NSArray *)catalogBreadcrumbs {
+ return @[ @"Chips", @"Action" ];
+}
+
++ (BOOL)catalogIsPrimaryDemo {
+ return NO;
+}
+
++ (BOOL)catalogIsPresentable {
+ return YES;
+}
+
+@end
+
@interface ChipsCollectionExampleViewController (Supplemental)
@end

diff:
/*
A collection view cell containing a single MDCChipView.
+ MDCChipCollectionViewCell manages the state of its chipView based on its own states.
+ E.g: setting the state of the cell to selected will automatically apply to its chipView as well.
*/
@interface MDCChipCollectionViewCell : UICollectionViewCell

original_message:
[Chips] Adding Examples/Documentation for all chips types. (#3393)

* Added example for Action Chips Type.
Cleaned up/Documented the examples for Filter and Choice chips type.
Added More documentation to MDCChipCollectionViewCell.

* typo.

PR: https://github.com/material-components/material-components-ios/pull/3393


message:
Fix build breakage
Fix build breakage

diff:
@@ -39,9 +39,14 @@ static const CGFloat kUnselectedImageOpacity = 0.54f;
toTabs:(nonnull MDCTabBar *)tabBar {
tabBar.barTintColor = colorScheme.surfaceColor;
tabBar.tintColor = colorScheme.primaryColor;
- tabBar.selectedItemTintColor = colorScheme.primaryColor;
- tabBar.unselectedItemTintColor =
- [colorScheme.onSurfaceColor colorWithAlphaComponent:kUnselectedOpacity];
+ [tabBar setTitleColor:colorScheme.primaryColor forState:MDCTabBarItemStateSelected];
+ [tabBar setImageTintColor:colorScheme.primaryColor forState:MDCTabBarItemStateSelected];
+ UIColor *unselectedTitleColor =
+ [colorScheme.onSurfaceColor colorWithAlphaComponent:kUnselectedTitleOpacity];
+ UIColor *unselectedImageColor =
+ [colorScheme.onSurfaceColor colorWithAlphaComponent:kUnselectedImageOpacity];
+ [tabBar setTitleColor:unselectedTitleColor forState:MDCTabBarItemStateNormal];
+ [tabBar setImageTintColor:unselectedImageColor forState:MDCTabBarItemStateNormal];
}
+ (void)applyColorScheme:(id<MDCColorScheme>)colorScheme

original_message:
Fix build breakage (#3425)

Fix build breakage


message: Fix MDCTabBarColorThemerTests

diff:
XCTAssertEqualObjects(tabBar.tintColor, colorScheme.primaryColor);
XCTAssertEqualObjects(tabBar.selectedItemTintColor, colorScheme.primaryColor);
XCTAssertEqualObjects(tabBar.unselectedItemTintColor,
- [colorScheme.onSurfaceColor colorWithAlphaComponent:(CGFloat)0.6f]);
+ [colorScheme.onSurfaceColor colorWithAlphaComponent:(CGFloat)0.54f]);
}
- (void)testTabBarColorThemerApplyColorSchemeProperly {

original_message: Fix MDCTabBarColorThemerTests (#3428)


message:
[BottomNavigation] Add separate property for selected title color
Exposes a selected item title color. Does not implement the full title color image color for state pattern as MDCNavigationBar does not display a title in its unselected state, which made just this single property addition seem cleaner.

diff:
@@ -95,12 +95,17 @@ typedef NS_ENUM(NSInteger, MDCBottomNavigationBarAlignment) {
@property(nonatomic, strong, nonnull) UIFont *itemTitleFont UI_APPEARANCE_SELECTOR;
/**
- Color of selected item. Applies color to items' icons and text.
- Default color is black.
+ Color of selected item. Applies color to items' icons and text. If set also sets
+ selectedItemTitleColor. Default color is black.
*/
@property (nonatomic, strong, readwrite, nonnull) UIColor *selectedItemTintColor
UI_APPEARANCE_SELECTOR;
+/**
+ Color of the selected item's title text. Default color is black.
+ */
+@property(nonatomic, strong, readwrite, nonnull) UIColor *selectedItemTitleColor;
+
/**
Color of unselected items. Applies color to items' icons. Text is not displayed in unselected mode.
Default color is dark gray.

diff:
@@ -163,6 +163,7 @@ static NSString *const kMDCBottomNavigationBarTitleString = @"title";
- (void)commonMDCBottomNavigationBarInit {
_selectedItemTintColor = [UIColor blackColor];
_unselectedItemTintColor = [UIColor grayColor];
+ _selectedItemTitleColor = _selectedItemTintColor;
_titleVisibility = MDCBottomNavigationBarTitleVisibilitySelected;
_alignment = MDCBottomNavigationBarAlignmentJustified;
_itemsDistributed = YES;
@@ -423,6 +424,7 @@ static NSString *const kMDCBottomNavigationBarTitleString = @"title";
itemView.title = item.title;
itemView.itemTitleFont = self.itemTitleFont;
itemView.selectedItemTintColor = self.selectedItemTintColor;
+ itemView.selectedItemTitleColor = self.selectedItemTitleColor;
itemView.unselectedItemTintColor = self.unselectedItemTintColor;
itemView.titleVisibility = self.titleVisibility;
itemView.titleBelowIcon = self.titleBelowItem;
@@ -502,6 +504,7 @@ static NSString *const kMDCBottomNavigationBarTitleString = @"title";
- (void)setSelectedItemTintColor:(UIColor *)selectedItemTintColor {
_selectedItemTintColor = selectedItemTintColor;
+ _selectedItemTitleColor = selectedItemTintColor;
for (MDCBottomNavigationItemView *itemView in self.itemViews) {
itemView.selectedItemTintColor = selectedItemTintColor;
}
@@ -514,6 +517,13 @@ static NSString *const kMDCBottomNavigationBarTitleString = @"title";
}
}
+- (void)setSelectedItemTitleColor:(UIColor *)selectedItemTitleColor {
+ _selectedItemTitleColor = selectedItemTitleColor;
+ for (MDCBottomNavigationItemView *itemView in self.itemViews) {
+ itemView.selectedItemTitleColor = selectedItemTitleColor;
+ }
+}
+
- (void)setTitleVisibility:(MDCBottomNavigationBarTitleVisibility)titleVisibility {
_titleVisibility = titleVisibility;
for (MDCBottomNavigationItemView *itemView in self.itemViews) {

diff:
@property(nonatomic, strong) UIColor *badgeColor UI_APPEARANCE_SELECTOR;
@property(nonatomic, strong) UIColor *selectedItemTintColor UI_APPEARANCE_SELECTOR;
@property(nonatomic, strong) UIColor *unselectedItemTintColor UI_APPEARANCE_SELECTOR;
+@property(nonatomic, strong) UIColor *selectedItemTitleColor;
- (void)setSelected:(BOOL)selected animated:(BOOL)animated;

diff:
@@ -154,6 +154,7 @@ static NSString *const kMDCBottomNavigationItemViewTabString = @"tab";
if (!_unselectedItemTintColor) {
_unselectedItemTintColor = [UIColor grayColor];
}
+ _selectedItemTitleColor = _selectedItemTintColor;
if (!_iconImageView) {
_iconImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
@@ -166,7 +167,7 @@ static NSString *const kMDCBottomNavigationItemViewTabString = @"tab";
_label.text = _title;
_label.font = [UIFont systemFontOfSize:MDCBottomNavigationItemViewTitleFontSize];
_label.textAlignment = NSTextAlignmentCenter;
- _label.textColor = _selectedItemTintColor;
+ _label.textColor = _selectedItemTitleColor;
_label.isAccessibilityElement = NO;
[self addSubview:_label];
@@ -311,7 +312,7 @@ static NSString *const kMDCBottomNavigationItemViewTabString = @"tab";
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
_selected = selected;
if (selected) {
- self.label.textColor = self.selectedItemTintColor;
+ self.label.textColor = self.selectedItemTitleColor;
self.iconImageView.tintColor = self.selectedItemTintColor;
self.button.accessibilityTraits |= UIAccessibilityTraitSelected;
@@ -348,9 +349,10 @@ static NSString *const kMDCBottomNavigationItemViewTabString = @"tab";
- (void)setSelectedItemTintColor:(UIColor *)selectedItemTintColor {
_selectedItemTintColor = selectedItemTintColor;
+ _selectedItemTitleColor = selectedItemTintColor;
if (self.selected) {
self.iconImageView.tintColor = self.selectedItemTintColor;
- self.label.textColor = self.selectedItemTintColor;
+ self.label.textColor = self.selectedItemTitleColor;
self.inkView.inkColor =
[self.selectedItemTintColor colorWithAlphaComponent:MDCBottomNavigationItemViewInkOpacity];
}
@@ -366,6 +368,13 @@ static NSString *const kMDCBottomNavigationItemViewTabString = @"tab";
}
}
+- (void)setSelectedItemTitleColor:(UIColor *)selectedItemTitleColor {
+ _selectedItemTitleColor = selectedItemTitleColor;
+ if (self.selected) {
+ self.label.textColor = self.selectedItemTitleColor;
+ }
+}
+
- (void)setBadgeColor:(UIColor *)badgeColor {
_badgeColor = badgeColor;
self.badge.badgeColor = badgeColor;

diff:
#import "MDCBottomNavigationBarColorThemer.h"
#import "MaterialColorScheme.h"
#import "MaterialBottomNavigation.h"
+#import "../../src/private/MDCBottomNavigationItemView.h"
@interface FakeColorScheme : NSObject<MDCColorScheme>
@property(nonatomic, strong) UIColor *primaryColor;
@end
+@interface MDCBottomNavigationBar (Testing)
+@property(nonatomic, strong) NSMutableArray<MDCBottomNavigationItemView *> *itemViews;
+@end
+
@implementation BottomNavigationBarColorThemerTests
- (void)testColorScheming {
MDCSemanticColorScheme *colorScheme = [[MDCSemanticColorScheme alloc] init];
colorScheme.primaryColor = [UIColor redColor];
colorScheme.onPrimaryColor = [UIColor blueColor];
+ UITabBarItem *item = [[UITabBarItem alloc] init];
MDCBottomNavigationBar *bottomNavigationBar = [[MDCBottomNavigationBar alloc] init];
+ [bottomNavigationBar setItems:@[item]];
bottomNavigationBar.barTintColor = [UIColor greenColor];
bottomNavigationBar.selectedItemTintColor = [UIColor yellowColor];
// Then
XCTAssertEqualObjects(bottomNavigationBar.barTintColor, colorScheme.primaryColor);
XCTAssertEqualObjects(bottomNavigationBar.selectedItemTintColor, colorScheme.onPrimaryColor);
+
+ MDCBottomNavigationItemView *firstItemView = [bottomNavigationBar.itemViews firstObject];
+ XCTAssertEqualObjects(firstItemView.selectedItemTitleColor, colorScheme.onPrimaryColor);
}
- (void)testColorSchemeWithoutOptionalColorProperties {

original_message:
[BottomNavigation] Add separate property for selected title color (#3430)

Exposes a selected item title color. Does not implement the full title color image color for state pattern as MDCNavigationBar does not display a title in its unselected state, which made just this single property addition seem cleaner.

https://www.pivotaltracker.com/story/show/156742634


message:
[Buttons] Create a separate class for MDCFloatingButton color themer.
Added MDCFloatingButtonColorThemer to color theme a floating button.
examples and tests are updated.
![screen shot 2018-04-20 at 1 14 17 pm](https://user-images.githubusercontent.com/36271115/39068266-baf19f22-44a9-11e8-9eaa-fe58d74dd804.png)

diff:
#import "MaterialButtons.h"
#import "MaterialTypography.h"
#import "MDCTextButtonThemer.h"
+#import "MDCFloatingButtonColorThemer.h"
#import "MDCContainedButtonThemer.h"
#import "supplemental/ButtonsTypicalUseSupplemental.h"
UIImage *plusImage =
[[UIImage imageNamed:@"Plus"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[self.floatingButton setImage:plusImage forState:UIControlStateNormal];
- [MDCButtonColorThemer applySemanticColorScheme:colorScheme toFloatingButton:self.floatingButton];
+ [MDCFloatingButtonColorThemer applySemanticColorScheme:colorScheme toButton:self.floatingButton];
[self.floatingButton setTintColor:colorScheme.onSecondaryColor];
[self.view addSubview:self.floatingButton];

diff:
#import "MaterialButtons.h"
#import "MDCButtonColorThemer.h"
+#import "MDCFloatingButtonColorThemer.h"
@interface FloatingButtonExampleViewController : UIViewController
@property(nonatomic, strong) UILabel *iPadLabel;
[self.miniFloatingButton setMinimumSize:CGSizeMake(96, 40)
forShape:MDCFloatingButtonShapeMini
inMode:MDCFloatingButtonModeExpanded];
- [MDCButtonColorThemer applySemanticColorScheme:colorScheme
- toFloatingButton:self.miniFloatingButton];
+ [MDCFloatingButtonColorThemer applySemanticColorScheme:colorScheme
+ toButton:self.miniFloatingButton];
[self.miniFloatingButton setTintColor:colorScheme.onSecondaryColor];
self.defaultFloatingButton = [[MDCFloatingButton alloc] init];
self.defaultFloatingButton.translatesAutoresizingMaskIntoConstraints = NO;
[self.defaultFloatingButton setImage:plusImage forState:UIControlStateNormal];
- [MDCButtonColorThemer applySemanticColorScheme:colorScheme
- toFloatingButton:self.defaultFloatingButton];
+ [MDCFloatingButtonColorThemer applySemanticColorScheme:colorScheme
+ toButton:self.defaultFloatingButton];
[self.defaultFloatingButton setTintColor:colorScheme.onSecondaryColor];
self.largeIconFloatingButton = [[MDCFloatingButton alloc] init];
[self.largeIconFloatingButton setContentEdgeInsets:UIEdgeInsetsMake(-6, -6, -6, 0)
forShape:MDCFloatingButtonShapeDefault
inMode:MDCFloatingButtonModeExpanded];
- [MDCButtonColorThemer applySemanticColorScheme:colorScheme
- toFloatingButton:self.largeIconFloatingButton];
+ [MDCFloatingButtonColorThemer applySemanticColorScheme:colorScheme
+ toButton:self.largeIconFloatingButton];
[self.largeIconFloatingButton setTintColor:colorScheme.onSecondaryColor];
[self.view addSubview:self.iPadLabel];

diff:
/**
Applies a color scheme to theme to an MDCFloatingButton.
+ This method will soon be deprecated. Consider using MDCFloatingButtonColorThemer's
+ applySemanticColorScheme:toButton:
+
@param colorScheme The color scheme to apply to @c floatingButton.
@param floatingButton An MDCFloatingButton instance to apply a color scheme.
*/

diff:
toFlatButton:(nonnull MDCButton *)flatButton {
[MDCTextButtonColorThemer applySemanticColorScheme:colorScheme toButton:flatButton];
}
+
+ (void)applySemanticColorScheme:(nonnull id<MDCColorScheming>)colorScheme
toFloatingButton:(nonnull MDCFloatingButton *)floatingButton {
[self resetUIControlStatesForButtonTheming:floatingButton];

diff:
+/*
+ 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 "MaterialButtons.h"
+#import "MaterialColorScheme.h"
+
+/**
+ A color themer for a Material floating Button.
+ */
+@interface MDCFloatingButtonColorThemer : NSObject
+
+/**
+ Applies a color scheme to theme to an MDCFloatingButton.
+
+ @param colorScheme The color scheme to apply to @c floatingButton.
+ @param button An MDCFloatingButton instance to apply a color scheme.
+ */
++ (void)applySemanticColorScheme:(nonnull id<MDCColorScheming>)colorScheme
+ toButton:(nonnull MDCFloatingButton *)button;
+
+@end

diff:
+/*
+ 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 "MDCFloatingButtonColorThemer.h"
+
+@implementation MDCFloatingButtonColorThemer
+
++ (void)applySemanticColorScheme:(nonnull id<MDCColorScheming>)colorScheme
+ toButton:(nonnull MDCFloatingButton *)button {
+ [self resetUIControlStatesForButtonTheming:button];
+ [button setBackgroundColor:colorScheme.secondaryColor forState:UIControlStateNormal];
+ button.disabledAlpha = 1.f;
+}
+
++ (void)resetUIControlStatesForButtonTheming:(nonnull MDCButton *)button {
+ NSUInteger maximumStateValue = UIControlStateNormal | UIControlStateSelected |
+ UIControlStateHighlighted | UIControlStateDisabled;
+ for (NSUInteger state = 0; state <= maximumStateValue; ++state) {
+ [button setBackgroundColor:nil forState:state];
+ [button setTitleColor:nil forState:state];
+ }
+}
+
+@end

diff:
#import "MaterialButtons.h"
#import "MDCButtonColorThemer.h"
+#import "MDCFloatingButtonColorThemer.h"
#import "MDCTextButtonColorThemer.h"
#import "MDCContainedButtonColorThemer.h"
@@ -226,7 +227,7 @@ static const CGFloat kEpsilonAccuracy = 0.001f;
[button setBackgroundColor:UIColor.darkGrayColor forState:UIControlStateDisabled];
// Where
- [MDCButtonColorThemer applySemanticColorScheme:colorScheme toFloatingButton:button];
+ [MDCFloatingButtonColorThemer applySemanticColorScheme:colorScheme toButton:button];
// Then
NSUInteger maximumStateValue =

original_message:
[Buttons] Create a separate class for MDCFloatingButton color themer. (#3429)

Added MDCFloatingButtonColorThemer to color theme a floating button.
examples and tests are updated.

![screen shot 2018-04-20 at 1 14 17 pm](https://user-images.githubusercontent.com/36271115/39068266-baf19f22-44a9-11e8-9eaa-fe58d74dd804.png)


message:
[MDCButton] Added new API for coloring image tint color for state.
Examples updated.
Unit Test Written.
![screen shot 2018-04-20 at 1 14 17 pm](https://user-images.githubusercontent.com/36271115/39064922-27f71680-449e-11e8-99fb-9fcd0e69d870.png)
![screen shot 2018-04-20 at 1 14 21 pm](https://user-images.githubusercontent.com/36271115/39064929-2be07ffc-449e-11e8-820b-7812cbb8d382.png)

diff:
UIImage *plusImage = [UIImage imageNamed:@"Plus"];
plusImage = [plusImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[raisedButton setImage:plusImage forState:UIControlStateNormal];
- [raisedButton setTitleColor:
- [UIColor colorWithRed:71/255.0f green:50/255.0f blue:50/255.0f alpha:1]
- forState:UIControlStateNormal];
- raisedButton.imageView.tintColor =
- [UIColor colorWithRed:71/255.0f green:50/255.0f blue:50/255.0f alpha:1];
+ UIColor *titleAndImageColor = [UIColor colorWithRed:71/255.0f green:50/255.0f blue:50/255.0f alpha:1];
+ [raisedButton setTitleColor:titleAndImageColor forState:UIControlStateNormal];
+ [raisedButton setImageTintColor:titleAndImageColor forState:UIControlStateNormal];
[raisedButton setBackgroundColor:
[UIColor colorWithRed:242/255.0f green:174/255.0f blue:178/255.0f alpha:1]];
self.floatingButton = [[MDCFloatingButton alloc] init];
[self.floatingButton setTitleColor:titleColor forState:UIControlStateNormal];
- self.floatingButton.imageView.tintColor = UIColor.whiteColor;
+ [self.floatingButton setImageTintColor:UIColor.whiteColor forState:UIControlStateNormal];
[self.floatingButton setImage:plusImage forState:UIControlStateNormal];
[self.floatingButton sizeToFit];

diff:
[[UIImage imageNamed:@"Plus"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[self.floatingButton setImage:plusImage forState:UIControlStateNormal];
[MDCFloatingButtonColorThemer applySemanticColorScheme:colorScheme toButton:self.floatingButton];
- [self.floatingButton setTintColor:colorScheme.onSecondaryColor];
+ [self.floatingButton setImageTintColor:colorScheme.onSecondaryColor
+ forState:UIControlStateNormal];
[self.view addSubview:self.floatingButton];
self.buttons = @[

diff:
inMode:MDCFloatingButtonModeExpanded];
[MDCFloatingButtonColorThemer applySemanticColorScheme:colorScheme
toButton:self.miniFloatingButton];
- [self.miniFloatingButton setTintColor:colorScheme.onSecondaryColor];
+ [self.miniFloatingButton setImageTintColor:colorScheme.onSecondaryColor
+ forState:UIControlStateNormal];
self.defaultFloatingButton = [[MDCFloatingButton alloc] init];
[self.defaultFloatingButton setImage:plusImage forState:UIControlStateNormal];
[MDCFloatingButtonColorThemer applySemanticColorScheme:colorScheme
toButton:self.defaultFloatingButton];
- [self.defaultFloatingButton setTintColor:colorScheme.onSecondaryColor];
+ [self.defaultFloatingButton setImageTintColor:colorScheme.onSecondaryColor
+ forState:UIControlStateNormal];
self.largeIconFloatingButton = [[MDCFloatingButton alloc] init];
self.largeIconFloatingButton.translatesAutoresizingMaskIntoConstraints = NO;
inMode:MDCFloatingButtonModeExpanded];
[MDCFloatingButtonColorThemer applySemanticColorScheme:colorScheme
toButton:self.largeIconFloatingButton];
- [self.largeIconFloatingButton setTintColor:colorScheme.onSecondaryColor];
+ [self.largeIconFloatingButton setImageTintColor:colorScheme.onSecondaryColor
+ forState:UIControlStateNormal];
[self.view addSubview:self.iPadLabel];
[self.view addSubview:self.miniFloatingButton];

diff:
- (void)setBorderColor:(nullable UIColor *)borderColor forState:(UIControlState)state
UI_APPEARANCE_SELECTOR;
+/**
+ A color used as the button's imageView tint color @c imageTintColor for @c state.
+
+ If no image tint color has been set for a given state, the returned value will fall back to the
+ value set for UIControlStateNormal.
+
+ @param state The state.
+ @return The tint color.
+ */
+- (nullable UIColor *)imageTintColorForState:(UIControlState)state;
+
+/**
+ Sets the image view tint color for a particular control state.
+
+ If left unset or reset to nil for a given state, it falls back to UIControlStateNormal setting.
+
+ @param imageTintColor The imageView tint color to set.
+ @param state The state to set.
+ */
+- (void)setImageTintColor:(nullable UIColor *)imageTintColor forState:(UIControlState)state;
+
+
/**
The value set for the button's @c borderWidth for @c state.

diff:
@@ -115,10 +115,12 @@ static NSAttributedString *uppercaseAttributedString(NSAttributedString *string)
NSMutableDictionary<NSNumber *, UIColor *> *_borderColors;
NSMutableDictionary<NSNumber *, NSNumber *> *_borderWidths;
NSMutableDictionary<NSNumber *, UIColor *> *_shadowColors;
+ NSMutableDictionary<NSNumber *, UIColor *> *_imageTintColors;
NSMutableDictionary<NSNumber *, UIFont *> *_fonts;
CGFloat _enabledAlpha;
BOOL _hasCustomDisabledTitleColor;
+ BOOL _imageTintStatefulAPIEnabled;
// Cached accessibility settings.
NSMutableDictionary<NSNumber *, NSString *> *_nontransformedTitles;
@@ -296,6 +298,7 @@ static NSAttributedString *uppercaseAttributedString(NSAttributedString *string)
_userElevations = [NSMutableDictionary dictionary];
_nontransformedTitles = [NSMutableDictionary dictionary];
_borderColors = [NSMutableDictionary dictionary];
+ _imageTintColors = [NSMutableDictionary dictionary];
_borderWidths = [NSMutableDictionary dictionary];
_fonts = [NSMutableDictionary dictionary];
@@ -510,6 +513,7 @@ static NSAttributedString *uppercaseAttributedString(NSAttributedString *string)
[self updateBorderWidth];
[self updateShadowColor];
[self updateTitleFont];
+ [self updateImageTintColor];
}
#pragma mark - Title Uppercasing
@@ -689,6 +693,26 @@ static NSAttributedString *uppercaseAttributedString(NSAttributedString *string)
[self updateAlphaAndBackgroundColorAnimated:NO];
}
+#pragma mark - Image Tint Color
+
+- (nullable UIColor *)imageTintColorForState:(UIControlState)state {
+
+ return _imageTintColors[@(state)] ?: _imageTintColors[@(UIControlStateNormal)];
+}
+
+- (void)setImageTintColor:(nullable UIColor *)imageTintColor forState:(UIControlState)state {
+ _imageTintColors[@(state)] = imageTintColor;
+ _imageTintStatefulAPIEnabled = YES;
+ [self updateImageTintColor];
+}
+
+- (void)updateImageTintColor {
+ if (!_imageTintStatefulAPIEnabled) {
+ return;
+ }
+ self.imageView.tintColor = [self imageTintColorForState:self.state];
+}
+
#pragma mark - Elevations
- (CGFloat)elevationForState:(UIControlState)state {

diff:
@@ -366,6 +366,91 @@ static NSString *controlStateDescription(UIControlState controlState) {
}
}
+#pragma mark - imageTintColor:forState:
+
+- (void)testRemovedImageTintColorForState {
+ // Given
+ MDCButton *button = [[MDCButton alloc] init];
+
+ // When
+ [button setImageTintColor:nil forState:UIControlStateNormal];
+
+ // Then
+ XCTAssertNil([button imageTintColorForState:UIControlStateNormal]);
+ XCTAssertNil([button imageTintColorForState:UIControlStateHighlighted]);
+}
+
+- (void)testDefaultImageTintColorForState {
+ // Given
+ MDCButton *button = [[MDCButton alloc] init];
+
+ // Then
+ XCTAssertNil([button imageTintColorForState:UIControlStateSelected]);
+}
+
+- (void)testImageTintForUnspecifiedStateEqualsNormalState {
+ // Given
+ MDCButton *button = [[MDCButton alloc] init];
+ UIColor *color = randomColor();
+
+ // When
+ [button setImageTintColor:color forState:UIControlStateNormal];
+
+ XCTAssertEqual([button imageTintColorForState:UIControlStateHighlighted], color);
+}
+
+- (void)testImageTintColorForState {
+ // Given
+ MDCButton *button = [[MDCButton alloc] init];
+
+ for (NSUInteger controlState = 0; controlState < kNumUIControlStates; ++controlState) {
+ // And given
+ UIColor *color = randomColor();
+
+ // When
+ [button setImageTintColor:color forState:controlState];
+
+ // Then
+ XCTAssertEqualObjects([button imageTintColorForState:controlState], color);
+ }
+}
+
+- (void)testImageTintColorForStateFallsBackToDefault {
+ // Given
+ MDCButton *button = [[MDCButton alloc] init];
+ UIColor *normalTint = [UIColor yellowColor];
+ UIColor *selectedTint = [UIColor redColor];
+
+ // When
+ [button setImageTintColor:normalTint forState:UIControlStateNormal];
+ [button setImageTintColor:selectedTint forState:UIControlStateSelected];
+
+ // Then
+ XCTAssertEqualObjects([button imageTintColorForState:UIControlStateNormal], normalTint);
+ XCTAssertEqualObjects([button imageTintColorForState:UIControlStateSelected], selectedTint);
+ XCTAssertEqualObjects([button imageTintColorForState:UIControlStateHighlighted], normalTint);
+}
+
+- (void)testImageTintColorForStateSetsImageViewTintColor {
+ // Given
+ MDCButton *button = [[MDCButton alloc] init];
+ UIColor *normalTint = [UIColor yellowColor];
+ UIColor *selectedTint = [UIColor redColor];
+
+ // When
+ [button setImageTintColor:normalTint forState:UIControlStateNormal];
+ [button setImageTintColor:selectedTint forState:UIControlStateSelected];
+
+ // Then
+ XCTAssertEqualObjects(button.imageView.tintColor, normalTint);
+
+ // When
+ button.selected = YES;
+
+ // Then
+ XCTAssertEqualObjects(button.imageView.tintColor, selectedTint);
+}
+
#pragma mark - backgroundColor:forState:
- (void)testCurrentBackgroundColorNormal {

original_message:
[MDCButton] Added new API for coloring image tint color for state. (#3423)

Examples updated.
Unit Test Written.
![screen shot 2018-04-20 at 1 14 17 pm](https://user-images.githubusercontent.com/36271115/39064922-27f71680-449e-11e8-99fb-9fcd0e69d870.png)
![screen shot 2018-04-20 at 1 14 21 pm](https://user-images.githubusercontent.com/36271115/39064929-2be07ffc-449e-11e8-820b-7812cbb8d382.png)


diff:
[[UIImage imageNamed:@"Plus"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[self.floatingButton setImage:plusImage forState:UIControlStateNormal];
[MDCFloatingButtonColorThemer applySemanticColorScheme:colorScheme toButton:self.floatingButton];
- [self.floatingButton setImageTintColor:colorScheme.onSecondaryColor
- forState:UIControlStateNormal];
[self.view addSubview:self.floatingButton];
self.buttons = @[

diff:
inMode:MDCFloatingButtonModeExpanded];
[MDCFloatingButtonColorThemer applySemanticColorScheme:colorScheme
toButton:self.miniFloatingButton];
- [self.miniFloatingButton setImageTintColor:colorScheme.onSecondaryColor
- forState:UIControlStateNormal];
-
self.defaultFloatingButton = [[MDCFloatingButton alloc] init];
self.defaultFloatingButton.translatesAutoresizingMaskIntoConstraints = NO;
[self.defaultFloatingButton setImage:plusImage forState:UIControlStateNormal];
[MDCFloatingButtonColorThemer applySemanticColorScheme:colorScheme
toButton:self.defaultFloatingButton];
- [self.defaultFloatingButton setImageTintColor:colorScheme.onSecondaryColor
- forState:UIControlStateNormal];
self.largeIconFloatingButton = [[MDCFloatingButton alloc] init];
self.largeIconFloatingButton.translatesAutoresizingMaskIntoConstraints = NO;
inMode:MDCFloatingButtonModeExpanded];
[MDCFloatingButtonColorThemer applySemanticColorScheme:colorScheme
toButton:self.largeIconFloatingButton];
- [self.largeIconFloatingButton setImageTintColor:colorScheme.onSecondaryColor
- forState:UIControlStateNormal];
[self.view addSubview:self.iPadLabel];
[self.view addSubview:self.miniFloatingButton];

diff:
toButton:(nonnull MDCFloatingButton *)button {
[self resetUIControlStatesForButtonTheming:button];
[button setBackgroundColor:colorScheme.secondaryColor forState:UIControlStateNormal];
+ [button setImageTintColor:colorScheme.onSecondaryColor forState:UIControlStateNormal];
+
button.disabledAlpha = 1.f;
}

diff:
@@ -235,6 +235,7 @@ static const CGFloat kEpsilonAccuracy = 0.001f;
for (NSUInteger state = 0; state <= maximumStateValue; ++state) {
if (state == UIControlStateNormal) {
XCTAssertEqual([button backgroundColorForState:state], colorScheme.secondaryColor);
+ XCTAssertEqual([button imageTintColorForState:state], colorScheme.onSecondaryColor);
} else {
XCTAssertEqual([button backgroundColorForState:state], nil);
}

original_message:
Added ImageTintColor for theming FAB Button. (#3442)

https://github.com/material-components/material-components-ios/pull/3442


diff:
@@ -753,29 +753,27 @@ static inline CGSize CGSizeShrinkWithInsets(CGSize size, UIEdgeInsets edgeInsets
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
- [_inkView startTouchBeganAnimationAtPoint:[self locationFromTouches:touches] completion:nil];
+ [self startTouchBeganAnimationAtPoint:[self locationFromTouches:touches]];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event];
- [_inkView startTouchEndedAnimationAtPoint:[self locationFromTouches:touches] completion:nil];
+ [self startTouchEndedAnimationAtPoint:[self locationFromTouches:touches]];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesCancelled:touches withEvent:event];
- [_inkView startTouchEndedAnimationAtPoint:[self locationFromTouches:touches] completion:nil];
+ [self startTouchEndedAnimationAtPoint:[self locationFromTouches:touches]];
}
- (void)touchDragEnter:(__unused MDCChipView *)button forEvent:(UIEvent *)event {
- [_inkView startTouchBeganAnimationAtPoint:[self locationFromTouches:event.allTouches]
- completion:nil];
+ [self startTouchBeganAnimationAtPoint:[self locationFromTouches:event.allTouches]];
}
- (void)touchDragExit:(__unused MDCChipView *)button forEvent:(UIEvent *)event {
- [_inkView startTouchEndedAnimationAtPoint:[self locationFromTouches:event.allTouches]
- completion:nil];
+ [self startTouchEndedAnimationAtPoint:[self locationFromTouches:event.allTouches]];
}
- (CGPoint)locationFromTouches:(NSSet *)touches {
@@ -788,6 +786,9 @@ static inline CGSize CGSizeShrinkWithInsets(CGSize size, UIEdgeInsets edgeInsets
@implementation MDCChipView (Private)
- (void)startTouchBeganAnimationAtPoint:(CGPoint)point {
+ if (!self.enabled) {
+ return;
+ }
CGSize size = [self sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)];
CGFloat widthDiff = 24.f; // Difference between unselected and selected frame widths.
_inkView.maxRippleRadius =
@@ -797,6 +798,9 @@ static inline CGSize CGSizeShrinkWithInsets(CGSize size, UIEdgeInsets edgeInsets
}
- (void)startTouchEndedAnimationAtPoint:(CGPoint)point {
+ if (!self.enabled) {
+ return;
+ }
[_inkView startTouchEndedAnimationAtPoint:point completion:nil];
}

original_message:
We should not display ink when the chip is disabled. (#3445)

https://github.com/material-components/material-components-ios/pull/3445


message:
[chips] Updating chips color Themer.
* updating chips color Themer.
* missing new line.
* tests are updated.
define the constant as floating point to avoid build erros.

diff:
/*
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
[MDCChipViewColorThemer resetUIControlStatesForChipTheming:chipView];
UIColor *onSurface12Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.12f];
UIColor *onSurface87Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.87f];
+ UIColor *onSurface16Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.16f];
+
UIColor *backgroundColor =
[MDCSemanticColorScheme blendColor:onSurface12Opacity
withBackgroundColor:colorScheme.surfaceColor];
+ UIColor *selectedBackgroundColor =
+ [MDCSemanticColorScheme blendColor:onSurface12Opacity
+ withBackgroundColor:backgroundColor];
UIColor *textColor =
[MDCSemanticColorScheme blendColor:onSurface87Opacity
- withBackgroundColor:colorScheme.surfaceColor];
+ withBackgroundColor:backgroundColor];
+ UIColor *selectedTextColor =
+ [MDCSemanticColorScheme blendColor:onSurface87Opacity
+ withBackgroundColor:selectedBackgroundColor];
+
+ [chipView setInkColor:onSurface16Opacity forState:UIControlStateNormal];
[chipView setTitleColor:textColor forState:UIControlStateNormal];
[chipView setBackgroundColor:backgroundColor forState:UIControlStateNormal];
+
+ [chipView setTitleColor:selectedTextColor forState:UIControlStateSelected];
+ [chipView setBackgroundColor:selectedBackgroundColor forState:UIControlStateSelected];
+
+ [chipView setTitleColor:[textColor colorWithAlphaComponent:0.38f]
+ forState:UIControlStateDisabled];
+ [chipView setBackgroundColor:[backgroundColor colorWithAlphaComponent:0.38f]
+ forState:UIControlStateDisabled];
}
+ (void)applySemanticColorScheme:(nonnull id<MDCColorScheming>)colorScheme
[MDCChipViewColorThemer resetUIControlStatesForChipTheming:strokedChipView];
UIColor *onSurface12Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.12f];
UIColor *onSurface87Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.87f];
+ UIColor *onSurface16Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.16f];
+ UIColor *selectedBackgroundColor =
+ [MDCSemanticColorScheme blendColor:onSurface12Opacity
+ withBackgroundColor:colorScheme.surfaceColor];
UIColor *borderColor =
[MDCSemanticColorScheme blendColor:onSurface12Opacity
withBackgroundColor:colorScheme.surfaceColor];
UIColor *textColor =
[MDCSemanticColorScheme blendColor:onSurface87Opacity
withBackgroundColor:colorScheme.surfaceColor];
+ UIColor *selectedTextColor =
+ [MDCSemanticColorScheme blendColor:onSurface87Opacity
+ withBackgroundColor:selectedBackgroundColor];
+
+ [strokedChipView setInkColor:onSurface16Opacity forState:UIControlStateNormal];
[strokedChipView setTitleColor:textColor forState:UIControlStateNormal];
[strokedChipView setBackgroundColor:colorScheme.surfaceColor forState:UIControlStateNormal];
[strokedChipView setBorderColor:borderColor forState:UIControlStateNormal];
+
+ [strokedChipView setTitleColor:selectedTextColor forState:UIControlStateSelected];
+ [strokedChipView setBackgroundColor:selectedBackgroundColor forState:UIControlStateSelected];
+ [strokedChipView setBorderColor:[UIColor clearColor] forState:UIControlStateSelected];
+
+ [strokedChipView setTitleColor:[textColor colorWithAlphaComponent:0.38f]
+ forState:UIControlStateDisabled];
+ [strokedChipView setBackgroundColor:[colorScheme.surfaceColor colorWithAlphaComponent:0.38f]
+ forState:UIControlStateDisabled];
+ [strokedChipView setBorderColor:[borderColor colorWithAlphaComponent:0.38f]
+ forState:UIControlStateDisabled];
}
+ (void)resetUIControlStatesForChipTheming:(nonnull MDCChipView *)chipView {

diff:
- (void)testInputChipViewColorThemer {
[MDCChipViewColorThemer applySemanticColorScheme:self.colorScheme toChipView:self.chip];
- [self verifyColorsWithColorScheme:self.colorScheme ChipView:self.chip stroked:NO];
+ UIColor *onSurface12Opacity = [self.colorScheme.onSurfaceColor colorWithAlphaComponent:0.12f];
+ UIColor *onSurface87Opacity = [self.colorScheme.onSurfaceColor colorWithAlphaComponent:0.87f];
+ UIColor *onSurface16Opacity = [self.colorScheme.onSurfaceColor colorWithAlphaComponent:0.16f];
+
+ UIColor *backgroundColor =
+ [MDCSemanticColorScheme blendColor:onSurface12Opacity
+ withBackgroundColor:self.colorScheme.surfaceColor];
+ UIColor *selectedBackgroundColor =
+ [MDCSemanticColorScheme blendColor:onSurface12Opacity
+ withBackgroundColor:backgroundColor];
+ UIColor *textColor =
+ [MDCSemanticColorScheme blendColor:onSurface87Opacity
+ withBackgroundColor:backgroundColor];
+ UIColor *selectedTextColor =
+ [MDCSemanticColorScheme blendColor:onSurface87Opacity
+ withBackgroundColor:selectedBackgroundColor];
+
+ XCTAssertEqualObjects([self.chip inkColorForState:UIControlStateNormal], onSurface16Opacity);
+ XCTAssertEqualObjects([self.chip titleColorForState:UIControlStateNormal], textColor);
+ XCTAssertEqualObjects([self.chip backgroundColorForState:UIControlStateNormal], backgroundColor);
+ XCTAssertEqualObjects([self.chip backgroundColorForState:UIControlStateSelected],
+ selectedBackgroundColor);
+ XCTAssertEqualObjects([self.chip titleColorForState:UIControlStateSelected], selectedTextColor);
+ XCTAssertEqualObjects([self.chip backgroundColorForState:UIControlStateDisabled],
+ [backgroundColor colorWithAlphaComponent:0.38f]);
+ XCTAssertEqualObjects([self.chip titleColorForState:UIControlStateDisabled],
+ [textColor colorWithAlphaComponent:0.38f]);
+
}
- (void)testStrokedChipViewColorThemer {
[MDCChipViewColorThemer applySemanticColorScheme:self.colorScheme toStrokedChipView:self.chip];
- [self verifyColorsWithColorScheme:self.colorScheme ChipView:self.chip stroked:YES];
-}
-
-- (void)verifyColorsWithColorScheme:(MDCSemanticColorScheme *)colorScheme
- ChipView:(MDCChipView *)chipView
- stroked:(BOOL)isStroked {
- UIColor *onSurface12Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.12f];
- UIColor *onSurface87Opacity = [colorScheme.onSurfaceColor colorWithAlphaComponent:0.87f];
-
- UIColor *backgroundColor =
+ UIColor *onSurface12Opacity = [self.colorScheme.onSurfaceColor colorWithAlphaComponent:0.12f];
+ UIColor *onSurface87Opacity = [self.colorScheme.onSurfaceColor colorWithAlphaComponent:0.87f];
+ UIColor *onSurface16Opacity = [self.colorScheme.onSurfaceColor colorWithAlphaComponent:0.16f];
+ UIColor *selectedBackgroundColor =
[MDCSemanticColorScheme blendColor:onSurface12Opacity
- withBackgroundColor:colorScheme.surfaceColor];
+ withBackgroundColor:self.colorScheme.surfaceColor];
+ UIColor *borderColor =
+ [MDCSemanticColorScheme blendColor:onSurface12Opacity
+ withBackgroundColor:self.colorScheme.surfaceColor];
UIColor *textColor =
[MDCSemanticColorScheme blendColor:onSurface87Opacity
- withBackgroundColor:colorScheme.surfaceColor];
-
- XCTAssertEqualObjects([chipView titleColorForState:UIControlStateNormal], textColor);
- if (!isStroked) {
- XCTAssertEqualObjects([chipView backgroundColorForState:UIControlStateNormal], backgroundColor);
- } else {
- XCTAssertEqualObjects([chipView backgroundColorForState:UIControlStateNormal],
- colorScheme.surfaceColor);
- XCTAssertEqualObjects([chipView borderColorForState:UIControlStateNormal],
- backgroundColor);
- }
+ withBackgroundColor:self.colorScheme.surfaceColor];
+ UIColor *selectedTextColor =
+ [MDCSemanticColorScheme blendColor:onSurface87Opacity
+ withBackgroundColor:selectedBackgroundColor];
+
+ XCTAssertEqualObjects([self.chip borderColorForState:UIControlStateNormal], borderColor);
+ XCTAssertEqualObjects([self.chip borderColorForState:UIControlStateSelected],
+ [UIColor clearColor]);
+ XCTAssertEqualObjects([self.chip inkColorForState:UIControlStateNormal], onSurface16Opacity);
+ XCTAssertEqualObjects([self.chip titleColorForState:UIControlStateNormal], textColor);
+ XCTAssertEqualObjects([self.chip backgroundColorForState:UIControlStateNormal],
+ self.colorScheme.surfaceColor);
+ XCTAssertEqualObjects([self.chip backgroundColorForState:UIControlStateSelected],
+ selectedBackgroundColor);
+ XCTAssertEqualObjects([self.chip titleColorForState:UIControlStateSelected], selectedTextColor);
+ XCTAssertEqualObjects([self.chip backgroundColorForState:UIControlStateDisabled],
+ [self.colorScheme.surfaceColor colorWithAlphaComponent:0.38f]);
+ XCTAssertEqualObjects([self.chip titleColorForState:UIControlStateDisabled],
+ [textColor colorWithAlphaComponent:0.38f]);
}
@end

original_message:
[chips] Updating chips color Themer. (#3452)

* updating chips color Themer.

* missing new line.

* tests are updated.
define the constant as floating point to avoid build erros.

https://github.com/material-components/material-components-ios/pull/3452


diff:
@interface MDCButtonScheme : NSObject <MDCButtonScheming>
// Redeclare protocol properties as readwrite
-@property(nonnull, readwrite, nonatomic) MDCSemanticColorScheme *colorScheme;
-@property(nonnull, readwrite, nonatomic) MDCTypographyScheme *typographyScheme;
+@property(nonnull, readwrite, nonatomic) id<MDCColorScheming> colorScheme;
+@property(nonnull, readwrite, nonatomic) id<MDCTypographyScheming> typographyScheme;
@property(readwrite, nonatomic) CGFloat cornerRadius;
@property(readwrite, nonatomic) CGFloat minimumHeight;

original_message:
Changing ButtonScheme Header to accept protocols instead of actual class. (#3488)

https://github.com/material-components/material-components-ios/pull/3488


diff:
@@ -30,7 +30,7 @@ class NodeViewTableViewDemoCell: UITableViewCell {
let label = UILabel()
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
- super.init(style: style, reuseIdentifier: reuseIdentifier)
+ super.init(style: .subtitle, reuseIdentifier: reuseIdentifier)
textLabel!.font = MDCTypography.subheadFont()
imageView!.image = UIImage(named: "Demo")
@@ -107,11 +107,13 @@ class NodeViewTableViewPrimaryDemoCell: UITableViewCell {
class MDCNodeListViewController: CBCNodeListViewController {
let appBar = MDCAppBar()
+ var mainSectionHeader : UIView?
+ var additionalExamplesSectionHeader : UIView?
let sectionNames = ["Description", "Additional Examples"]
- let descriptionSectionHeight = CGFloat(100)
- let additionalExamplesSectionHeight = CGFloat(50)
- let demoRowHeight = CGFloat(60)
- let rowHeight = CGFloat(50)
+ let estimadedDescriptionSectionHeight = CGFloat(100)
+ let estimadedAdditionalExamplesSectionHeight = CGFloat(50)
+ let estimadedDemoRowHeight = CGFloat(60)
+ let estimadedRowHeight = CGFloat(50)
let padding = CGFloat(20)
var componentDescription = ""
var selectedNode: CBCNode? = nil
@@ -179,8 +181,12 @@ class MDCNodeListViewController: CBCNodeListViewController {
override func viewDidLoad() {
super.viewDidLoad()
+ mainSectionHeader = MainSectionHeader()
+ additionalExamplesSectionHeader = AdditionalExamplesSectionHeader()
self.tableView.backgroundColor = UIColor.white
self.tableView.separatorStyle = .none
+ self.tableView.rowHeight = UITableViewAutomaticDimension
+ self.tableView.sectionHeaderHeight = UITableViewAutomaticDimension
var charactersCount = 0
#if swift(>=3.2)
@@ -308,69 +314,209 @@ extension MDCNodeListViewController {
titleForHeaderInSection section: Int) -> String? {
return sectionNames[section]
}
+ override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
+ if indexPath.section == Section.description.rawValue {
+ return estimadedDemoRowHeight
+ }
+ return estimadedRowHeight
+ }
+ override func tableView(_ tableView: UITableView, estimatedHeightForHeaderInSection section: Int) -> CGFloat {
+ if section == Section.description.rawValue {
+ return estimadedDescriptionSectionHeight
+ }
+ return estimadedAdditionalExamplesSectionHeight
+ }
// swiftlint:disable function_body_length
override func tableView(_ tableView: UITableView,
viewForHeaderInSection section: Int) -> UIView? {
- var sectionViewFrame = CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 50)
- let sectionView = UIView(frame: sectionViewFrame)
- sectionView.backgroundColor = UIColor.white
+ if section == 0 {
+ return mainSectionHeader
+ }
+ return additionalExamplesSectionHeader
+ }
- if section == 1 {
- let lineDivider =
- UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 1))
+ func AdditionalExamplesSectionHeader() -> UIView {
+
+ let sectionView = UIView()
+ sectionView.backgroundColor = UIColor.white
+ let lineDivider = UIView()
lineDivider.backgroundColor = UIColor(white: 0.85, alpha: 1)
- lineDivider.autoresizingMask = .flexibleWidth
+ lineDivider.translatesAutoresizingMaskIntoConstraints = false
+
+ let sectionTitleLabel = UILabel()
+ sectionTitleLabel.font = MDCTypography.body2Font()
+ sectionTitleLabel.translatesAutoresizingMaskIntoConstraints = false
+ sectionTitleLabel.text = sectionNames[1]
+ sectionTitleLabel.numberOfLines = 0
+ sectionTitleLabel.setContentCompressionResistancePriority(1000, for: .vertical)
+
sectionView.addSubview(lineDivider)
- }
+ sectionView.addSubview(sectionTitleLabel)
- let label = UILabel()
- label.text = sectionNames[section]
- label.frame = CGRect(x: 0,
- y: 0,
- width: tableView.frame.size.width,
- height: additionalExamplesSectionHeight)
- label.font = MDCTypography.body2Font()
- label.translatesAutoresizingMaskIntoConstraints = false
- sectionView.addSubview(label)
- constrainView(view: label,
- containerView: sectionView,
- height: additionalExamplesSectionHeight,
- top: 0)
+ // Line divider constraints
+ NSLayoutConstraint(
+ item: lineDivider,
+ attribute: .height,
+ relatedBy: .equal,
+ toItem: nil,
+ attribute: .notAnAttribute,
+ multiplier: 1.0,
+ constant: 1).isActive = true
- if section == 0 {
- let textView = UITextView()
- textView.text = componentDescription
- textView.font = MDCTypography.captionFont()
- textView.alpha = MDCTypography.captionFontOpacity()
+ // Line divider to section view
+ NSLayoutConstraint(
+ item: sectionView,
+ attribute: .leading,
+ relatedBy: .equal,
+ toItem: lineDivider,
+ attribute: .leading,
+ multiplier: 1.0,
+ constant: 0).isActive = true
+ NSLayoutConstraint(
+ item: sectionView,
+ attribute: .trailing,
+ relatedBy: .equal,
+ toItem: lineDivider,
+ attribute: .trailing,
+ multiplier: 1.0,
+ constant: 0).isActive = true
+ NSLayoutConstraint(
+ item: sectionView,
+ attribute: .top,
+ relatedBy: .equal,
+ toItem: lineDivider,
+ attribute: .top,
+ multiplier: 1.0,
+ constant: 0).isActive = true
- if UIApplication.shared.userInterfaceLayoutDirection == .leftToRight {
- textView.contentInset = UIEdgeInsets(top: -8, left: -5, bottom: -8, right: 5)
- } else {
- textView.contentInset = UIEdgeInsets(top: -8, left: 5, bottom: -8, right: -5)
- }
+ // Line divider to Title Label
+ NSLayoutConstraint(
+ item: lineDivider,
+ attribute: .top,
+ relatedBy: .equal,
+ toItem: sectionTitleLabel,
+ attribute: .top,
+ multiplier: 1.0,
+ constant: -padding).isActive = true
+
+ // Title Label to Section View
+ NSLayoutConstraint(
+ item: sectionView,
+ attribute: .leading,
+ relatedBy: .equal,
+ toItem: sectionTitleLabel,
+ attribute: .leading,
+ multiplier: 1.0,
+ constant: -padding).isActive = true
+ NSLayoutConstraint(
+ item: sectionView,
+ attribute: .trailing,
+ relatedBy: .equal,
+ toItem: sectionTitleLabel,
+ attribute: .trailing,
+ multiplier: 1.0,
+ constant: padding).isActive = true
+ NSLayoutConstraint(
+ item: sectionView,
+ attribute: .bottom,
+ relatedBy: .equal,
+ toItem: sectionTitleLabel,
+ attribute: .bottom,
+ multiplier: 1.0,
+ constant: padding).isActive = true
- textView.isEditable = false
- textView.translatesAutoresizingMaskIntoConstraints = false
- sectionViewFrame =
- CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: descriptionSectionHeight)
- sectionView.frame = sectionViewFrame
- sectionView.addSubview(textView)
- let textViewHeight = ceil(MDCTypography.captionFont().lineHeight * 3)
- constrainView(view: textView, containerView: sectionView, height: textViewHeight, top: 40)
- }
return sectionView
}
- // swiftlint:enable function_body_length
- override func tableView(_ tableView: UITableView,
- heightForHeaderInSection section: Int) -> CGFloat {
- if section == Section.description.rawValue {
- return descriptionSectionHeight
- }
- return additionalExamplesSectionHeight
+ func MainSectionHeader() -> UIView {
+ let sectionView = UIView()
+ sectionView.backgroundColor = UIColor.white
+
+ let sectionTitleLabel = UILabel()
+ sectionTitleLabel.font = MDCTypography.body2Font()
+ sectionTitleLabel.translatesAutoresizingMaskIntoConstraints = false
+ sectionTitleLabel.text = sectionNames[0]
+ sectionTitleLabel.numberOfLines = 0
+ sectionTitleLabel.setContentCompressionResistancePriority(1000, for: .vertical)
+
+ let descriptionLabel = UILabel()
+ descriptionLabel.text = componentDescription
+ descriptionLabel.font = MDCTypography.captionFont()
+ descriptionLabel.alpha = MDCTypography.captionFontOpacity()
+ descriptionLabel.translatesAutoresizingMaskIntoConstraints = false
+ descriptionLabel.numberOfLines = 0
+ descriptionLabel.setContentCompressionResistancePriority(1000, for: .vertical)
+
+ sectionView.addSubview(sectionTitleLabel)
+ sectionView.addSubview(descriptionLabel)
+
+ // sectionTitleLabel to SectionView
+ NSLayoutConstraint(
+ item: sectionView,
+ attribute: .leading,
+ relatedBy: .equal,
+ toItem: sectionTitleLabel,
+ attribute: .leading,
+ multiplier: 1.0,
+ constant: -padding).isActive = true
+ NSLayoutConstraint(
+ item: sectionView,
+ attribute: .trailing,
+ relatedBy: .equal,
+ toItem: sectionTitleLabel,
+ attribute: .trailing,
+ multiplier: 1.0,
+ constant: padding).isActive = true
+ NSLayoutConstraint(
+ item: sectionView,
+ attribute: .top,
+ relatedBy: .equal,
+ toItem: sectionTitleLabel,
+ attribute: .top,
+ multiplier: 1.0,
+ constant: -padding).isActive = true
+
+ // descriptionLabel to sectionTitleLabel
+ NSLayoutConstraint(
+ item: sectionTitleLabel,
+ attribute: .leading,
+ relatedBy: .equal,
+ toItem: descriptionLabel,
+ attribute: .leading,
+ multiplier: 1.0,
+ constant: 0).isActive = true
+ NSLayoutConstraint(
+ item: sectionTitleLabel,
+ attribute: .trailing,
+ relatedBy: .equal,
+ toItem: descriptionLabel,
+ attribute: .trailing,
+ multiplier: 1.0,
+ constant: 0).isActive = true
+ NSLayoutConstraint(
+ item: sectionTitleLabel,
+ attribute: .bottom,
+ relatedBy: .equal,
+ toItem: descriptionLabel,
+ attribute: .top,
+ multiplier: 1.0,
+ constant: -10).isActive = true
+
+ // descriptionLabel to SectionView
+ NSLayoutConstraint(
+ item: sectionView,
+ attribute: .bottom,
+ relatedBy: .equal,
+ toItem: descriptionLabel,
+ attribute: .bottom,
+ multiplier: 1.0,
+ constant: 10).isActive = true
+
+ return sectionView
}
+
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == Section.description.rawValue {
return 1
@@ -416,72 +562,6 @@ extension MDCNodeListViewController {
let indexPath = IndexPath(row: 0, section: Section.description.rawValue)
self.tableView(self.tableView, didSelectRowAt: indexPath)
}
- override func tableView(_ tableView: UITableView,
- heightForRowAt indexPath: IndexPath) -> CGFloat {
- if indexPath.section == Section.description.rawValue {
- return demoRowHeight
- }
- return rowHeight
- }
-
- // MARK: Private
- func constrainView(view: UIView, containerView: UIView, height: CGFloat, top: CGFloat) {
-#if swift(>=3.2)
- if #available(iOS 11.0, *) {
- let safeAreaLayoutGuide = containerView.safeAreaLayoutGuide
- NSLayoutConstraint.activate([
- view.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor,
- constant: padding),
- view.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor,
- constant: -padding),
- view.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor, constant: top),
- view.heightAnchor.constraint(equalToConstant: height)
- ])
- return
- }
-#endif
- if #available(iOS 9.0, *) {
- NSLayoutConstraint.activate([
- view.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: padding),
- view.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: -padding),
- view.topAnchor.constraint(equalTo: containerView.topAnchor, constant: top),
- view.heightAnchor.constraint(equalToConstant: height)
- ])
- } else {
- _ = NSLayoutConstraint(
- item: view,
- attribute: .leading,
- relatedBy: .equal,
- toItem: containerView,
- attribute: .leading,
- multiplier: 1.0,
- constant: padding).isActive = true
- _ = NSLayoutConstraint(
- item: view,
- attribute: .trailing,
- relatedBy: .equal,
- toItem: containerView,
- attribute: .trailing,
- multiplier: 1.0,
- constant: -padding).isActive = true
- _ = NSLayoutConstraint(
- item: view,
- attribute: .top,
- relatedBy: .equal,
- toItem: containerView,
- attribute: .top,
- multiplier: 1.0,
- constant: top).isActive = true
- _ = NSLayoutConstraint(
- item: view,
- attribute: .height,
- relatedBy: .equal,
- toItem: nil,
- attribute: .notAnAttribute,
- multiplier: 1.0,
- constant: height).isActive = true
- }
- }
}
// MARK: UITableViewDelegate

original_message:
dynamic size support for catalog node list view controller. (#3515)

https://github.com/material-components/material-components-ios/pull/3515