Skip to content

Commit 322eb6c

Browse files
committed
Moved initWithCoder and friend to be with other init methods.
1 parent 87b1d69 commit 322eb6c

File tree

1 file changed

+60
-62
lines changed

1 file changed

+60
-62
lines changed

components/Buttons/src/MDCButton.m

Lines changed: 60 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,62 @@ - (instancetype)initWithFrame:(CGRect)frame {
8989
return self;
9090
}
9191

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+
92148
- (void)commonInit {
93149
_disabledAlpha = MDCButtonDisabledAlpha;
94150
_shouldRaiseOnTouch = YES;
@@ -162,64 +218,6 @@ - (void)setDisabledAlpha:(CGFloat)disabledAlpha {
162218
[self updateAlphaAndBackgroundColorAnimated:NO];
163219
}
164220

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-
223221
#pragma mark - UIView
224222

225223
- (void)layoutSubviews {
@@ -260,7 +258,7 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
260258
if (inside) {
261259
[_inkView evaporateWithCompletion:nil];
262260
if (_shouldRaiseOnTouch) {
263-
[self moveButtonToHeightForState:UIControlStateNormal];
261+
[self animateButtonToHeightForState:UIControlStateNormal];
264262
}
265263
} else {
266264
[self evaporateInkToPoint:location];
@@ -417,7 +415,7 @@ - (MDCShadowLayer *)shadowLayer {
417415
return (MDCShadowLayer *)self.layer;
418416
}
419417

420-
- (void)moveButtonToHeightForState:(UIControlState)state {
418+
- (void)animateButtonToHeightForState:(UIControlState)state {
421419
[CATransaction begin];
422420
[CATransaction setAnimationDuration:MDCButtonAnimationDuration];
423421
[self shadowLayer].elevation = [self elevationForState:state];
@@ -504,7 +502,7 @@ - (void)touchDragExit:(MDCButton *)button forEvent:(UIEvent *)event {
504502
- (void)handleBeginTouches:(NSSet *)touches {
505503
[_inkView spreadFromPoint:[self locationFromTouches:touches] completion:nil];
506504
if (_shouldRaiseOnTouch) {
507-
[self moveButtonToHeightForState:UIControlStateSelected];
505+
[self animateButtonToHeightForState:UIControlStateSelected];
508506
}
509507
}
510508

@@ -516,7 +514,7 @@ - (CGPoint)locationFromTouches:(NSSet *)touches {
516514
- (void)evaporateInkToPoint:(CGPoint)toPoint {
517515
[_inkView evaporateToPoint:toPoint completion:nil];
518516
if (_shouldRaiseOnTouch) {
519-
[self moveButtonToHeightForState:UIControlStateNormal];
517+
[self animateButtonToHeightForState:UIControlStateNormal];
520518
}
521519
}
522520

0 commit comments

Comments
 (0)