@@ -89,6 +89,62 @@ - (instancetype)initWithFrame:(CGRect)frame {
89
89
return self;
90
90
}
91
91
92
+ - (instancetype )initWithCoder : (NSCoder *)aDecoder {
93
+ self = [super initWithCoder: aDecoder];
94
+ if (self) {
95
+ [self commonInit ];
96
+
97
+ // TODO(randallli): Add backward compatibility to background colors
98
+ // if ([aDecoder containsValueForKey:MDCButtonEnabledBackgroundColorKey]) {
99
+ // self.enabledBackgroundColor =
100
+ // [aDecoder decodeObjectForKey:MDCButtonEnabledBackgroundColorKey];
101
+ // }
102
+ // if ([aDecoder containsValueForKey:MDCButtonDisabledBackgroundColorLightKey]) {
103
+ // self.disabledBackgroundColorLight =
104
+ // [aDecoder decodeObjectForKey:MDCButtonDisabledBackgroundColorLightKey];
105
+ // }
106
+ // if ([aDecoder containsValueForKey:MDCButtonDisabledBackgroundColorDarkKey]) {
107
+ // self.disabledBackgroundColorDark =
108
+ // [aDecoder decodeObjectForKey:MDCButtonDisabledBackgroundColorDarkKey];
109
+ // }
110
+ if ([aDecoder containsValueForKey: MDCButtonInkViewInkColorKey]) {
111
+ self.inkView .inkColor = [aDecoder decodeObjectForKey: MDCButtonInkViewInkColorKey];
112
+ }
113
+
114
+ if ([aDecoder containsValueForKey: MDCButtonShouldRaiseOnTouchKey]) {
115
+ self.shouldRaiseOnTouch = [aDecoder decodeBoolForKey: MDCButtonShouldRaiseOnTouchKey];
116
+ }
117
+
118
+ if ([aDecoder containsValueForKey: MDCButtonShouldCapitalizeTitleKey]) {
119
+ self.shouldCapitalizeTitle = [aDecoder decodeBoolForKey: MDCButtonShouldCapitalizeTitleKey];
120
+ }
121
+
122
+ if ([aDecoder containsValueForKey: MDCButtonUnderlyingColorKey]) {
123
+ self.underlyingColor = [aDecoder decodeObjectForKey: MDCButtonUnderlyingColorKey];
124
+ }
125
+
126
+ if ([aDecoder containsValueForKey: MDCButtonUserElevationsKey]) {
127
+ _userElevations = [aDecoder decodeObjectForKey: MDCButtonUserElevationsKey];
128
+ }
129
+ }
130
+ return self;
131
+ }
132
+
133
+ - (void )encodeWithCoder : (NSCoder *)aCoder {
134
+ [super encodeWithCoder: aCoder];
135
+
136
+ if (_inkView.inkColor ) {
137
+ [aCoder encodeObject: _inkView.inkColor forKey: MDCButtonInkViewInkColorKey];
138
+ }
139
+
140
+ [aCoder encodeBool: _shouldRaiseOnTouch forKey: MDCButtonShouldRaiseOnTouchKey];
141
+ [aCoder encodeBool: _shouldCapitalizeTitle forKey: MDCButtonShouldCapitalizeTitleKey];
142
+ if (_underlyingColor) {
143
+ [aCoder encodeObject: _underlyingColor forKey: MDCButtonUnderlyingColorKey];
144
+ }
145
+ [aCoder encodeObject: _userElevations forKey: MDCButtonUserElevationsKey];
146
+ }
147
+
92
148
- (void )commonInit {
93
149
_disabledAlpha = MDCButtonDisabledAlpha;
94
150
_shouldRaiseOnTouch = YES ;
@@ -162,64 +218,6 @@ - (void)setDisabledAlpha:(CGFloat)disabledAlpha {
162
218
[self updateAlphaAndBackgroundColorAnimated: NO ];
163
219
}
164
220
165
- #pragma mark - NSCoding
166
-
167
- - (instancetype )initWithCoder : (NSCoder *)aDecoder {
168
- self = [super initWithCoder: aDecoder];
169
- if (self) {
170
- [self commonInit ];
171
-
172
- // TODO(randallli): Add backward compatibility to background colors
173
- // if ([aDecoder containsValueForKey:MDCButtonEnabledBackgroundColorKey]) {
174
- // self.enabledBackgroundColor =
175
- // [aDecoder decodeObjectForKey:MDCButtonEnabledBackgroundColorKey];
176
- // }
177
- // if ([aDecoder containsValueForKey:MDCButtonDisabledBackgroundColorLightKey]) {
178
- // self.disabledBackgroundColorLight =
179
- // [aDecoder decodeObjectForKey:MDCButtonDisabledBackgroundColorLightKey];
180
- // }
181
- // if ([aDecoder containsValueForKey:MDCButtonDisabledBackgroundColorDarkKey]) {
182
- // self.disabledBackgroundColorDark =
183
- // [aDecoder decodeObjectForKey:MDCButtonDisabledBackgroundColorDarkKey];
184
- // }
185
- if ([aDecoder containsValueForKey: MDCButtonInkViewInkColorKey]) {
186
- self.inkView .inkColor = [aDecoder decodeObjectForKey: MDCButtonInkViewInkColorKey];
187
- }
188
-
189
- if ([aDecoder containsValueForKey: MDCButtonShouldRaiseOnTouchKey]) {
190
- self.shouldRaiseOnTouch = [aDecoder decodeBoolForKey: MDCButtonShouldRaiseOnTouchKey];
191
- }
192
-
193
- if ([aDecoder containsValueForKey: MDCButtonShouldCapitalizeTitleKey]) {
194
- self.shouldCapitalizeTitle = [aDecoder decodeBoolForKey: MDCButtonShouldCapitalizeTitleKey];
195
- }
196
-
197
- if ([aDecoder containsValueForKey: MDCButtonUnderlyingColorKey]) {
198
- self.underlyingColor = [aDecoder decodeObjectForKey: MDCButtonUnderlyingColorKey];
199
- }
200
-
201
- if ([aDecoder containsValueForKey: MDCButtonUserElevationsKey]) {
202
- _userElevations = [aDecoder decodeObjectForKey: MDCButtonUserElevationsKey];
203
- }
204
- }
205
- return self;
206
- }
207
-
208
- - (void )encodeWithCoder : (NSCoder *)aCoder {
209
- [super encodeWithCoder: aCoder];
210
-
211
- if (_inkView.inkColor ) {
212
- [aCoder encodeObject: _inkView.inkColor forKey: MDCButtonInkViewInkColorKey];
213
- }
214
-
215
- [aCoder encodeBool: _shouldRaiseOnTouch forKey: MDCButtonShouldRaiseOnTouchKey];
216
- [aCoder encodeBool: _shouldCapitalizeTitle forKey: MDCButtonShouldCapitalizeTitleKey];
217
- if (_underlyingColor) {
218
- [aCoder encodeObject: _underlyingColor forKey: MDCButtonUnderlyingColorKey];
219
- }
220
- [aCoder encodeObject: _userElevations forKey: MDCButtonUserElevationsKey];
221
- }
222
-
223
221
#pragma mark - UIView
224
222
225
223
- (void )layoutSubviews {
@@ -260,7 +258,7 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
260
258
if (inside) {
261
259
[_inkView evaporateWithCompletion: nil ];
262
260
if (_shouldRaiseOnTouch) {
263
- [self moveButtonToHeightForState : UIControlStateNormal];
261
+ [self animateButtonToHeightForState : UIControlStateNormal];
264
262
}
265
263
} else {
266
264
[self evaporateInkToPoint: location];
@@ -417,7 +415,7 @@ - (MDCShadowLayer *)shadowLayer {
417
415
return (MDCShadowLayer *)self.layer ;
418
416
}
419
417
420
- - (void )moveButtonToHeightForState : (UIControlState)state {
418
+ - (void )animateButtonToHeightForState : (UIControlState)state {
421
419
[CATransaction begin ];
422
420
[CATransaction setAnimationDuration: MDCButtonAnimationDuration];
423
421
[self shadowLayer ].elevation = [self elevationForState: state];
@@ -504,7 +502,7 @@ - (void)touchDragExit:(MDCButton *)button forEvent:(UIEvent *)event {
504
502
- (void )handleBeginTouches : (NSSet *)touches {
505
503
[_inkView spreadFromPoint: [self locationFromTouches: touches] completion: nil ];
506
504
if (_shouldRaiseOnTouch) {
507
- [self moveButtonToHeightForState : UIControlStateSelected];
505
+ [self animateButtonToHeightForState : UIControlStateSelected];
508
506
}
509
507
}
510
508
@@ -516,7 +514,7 @@ - (CGPoint)locationFromTouches:(NSSet *)touches {
516
514
- (void )evaporateInkToPoint : (CGPoint)toPoint {
517
515
[_inkView evaporateToPoint: toPoint completion: nil ];
518
516
if (_shouldRaiseOnTouch) {
519
- [self moveButtonToHeightForState : UIControlStateNormal];
517
+ [self animateButtonToHeightForState : UIControlStateNormal];
520
518
}
521
519
}
522
520
0 commit comments