Skip to content

Commit

Permalink
[Snackbar] bring back buttonTextColor and deprecate it (#3104)
Browse files Browse the repository at this point in the history
  • Loading branch information
yarneo committed Mar 15, 2018
1 parent f5fbc71 commit 85c5351
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
9 changes: 9 additions & 0 deletions components/Snackbar/src/MDCSnackbarMessage.h
Expand Up @@ -99,6 +99,15 @@ extern NSString * __nonnull const MDCSnackbarMessageBoldAttributeName;
*/
@property(nonatomic, strong, nullable) MDCSnackbarMessageAction *action;

/**
The color used for button text on the snackbar in normal state.
Default is nil, but MDCRGBAColor(0xFF, 0xFF, 0xFF, 0.6f) will be set as the default color
and is taken from MDCSnackbarMessageView's buttonTitleColorForState:
*/
@property(nonatomic, strong, nullable) UIColor *buttonTextColor
__deprecated_msg("Use MDCSnackbarMessageView's buttonTitleColorForState: instead.");

/**
How long the message should be displayed.
Expand Down
1 change: 1 addition & 0 deletions components/Snackbar/src/MDCSnackbarMessage.m
Expand Up @@ -66,6 +66,7 @@ - (instancetype)copyWithZone:(__unused NSZone *)zone {
copy.duration = self.duration;
copy.category = self.category;
copy.accessibilityLabel = self.accessibilityLabel;
copy.buttonTextColor = self.buttonTextColor;

// Unfortunately there's not really a concept of 'copying' a block (in the same way you would copy
// a string, for example). A block's pointer is immutable once it is created and copied to the
Expand Down
4 changes: 2 additions & 2 deletions components/Snackbar/src/MDCSnackbarMessageView.h
Expand Up @@ -57,8 +57,8 @@
/**
Returns the button title color for a particular control state.
Default for UIControlStateNormal is white.
Default for UIControlStatehighlighted is MDCRGBAColor(0xFF, 0xFF, 0xFF, 0.6f).
Default for UIControlStateNormal is MDCRGBAColor(0xFF, 0xFF, 0xFF, 0.6f).
Default for UIControlStatehighlighted is white.
@param state The control state.
@return The button title color for the requested state.
Expand Down
9 changes: 7 additions & 2 deletions components/Snackbar/src/MDCSnackbarMessageView.m
Expand Up @@ -190,8 +190,6 @@ - (instancetype)initWithFrame:(CGRect)frame {
_snackbarMessageViewShadowColor = UIColor.blackColor;
_snackbarMessageViewBackgroundColor = MDCRGBAColor(0x32, 0x32, 0x32, 1);
_messageTextColor = UIColor.whiteColor;
// _buttonTextColor = MDCRGBAColor(0xFF, 0xFF, 0xFF, 0.6f);
// _highlightedButtonTextColor = UIColor.whiteColor;
_buttonTitleColors = [NSMutableDictionary dictionary];
_buttonTitleColors[@(UIControlStateNormal)] = MDCRGBAColor(0xFF, 0xFF, 0xFF, 0.6f);
_buttonTitleColors[@(UIControlStateHighlighted)] = UIColor.whiteColor;
Expand Down Expand Up @@ -362,10 +360,17 @@ - (void)initializeMDCSnackbarMessageViewButtons:(MDCSnackbarMessage *)message {
[button setTitleFont:_buttonFont forState:UIControlStateNormal];
[button setTitleFont:_buttonFont forState:UIControlStateHighlighted];
}

[button setTitleColor:_buttonTitleColors[@(UIControlStateNormal)]
forState:UIControlStateNormal];
[button setTitleColor:_buttonTitleColors[@(UIControlStateHighlighted)]
forState:UIControlStateHighlighted];

// TODO: Eventually remove this if statement, buttonTextColor is deprecated.
if (message.buttonTextColor) {
[button setTitleColor:message.buttonTextColor forState:UIControlStateNormal];
}

[button setTranslatesAutoresizingMaskIntoConstraints:NO];
button.tag = kButtonTagStart;
[buttonView addSubview:button];
Expand Down

0 comments on commit 85c5351

Please sign in to comment.