Skip to content

Commit 0bda7ee

Browse files
author
Adlai Holler
authored
Repeal and replace ASControlState (facebookarchive#3005)
1 parent a13b36d commit 0bda7ee

File tree

6 files changed

+75
-69
lines changed

6 files changed

+75
-69
lines changed

AsyncDisplayKit/ASButtonNode.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,19 @@ typedef NS_ENUM(NSInteger, ASButtonNodeImageAlignment) {
6666
/**
6767
* Returns the styled title associated with the specified state.
6868
*
69-
* @param state The state that uses the styled title. The possible values are described in ASControlState.
69+
* @param state The control state that uses the styled title.
7070
*
7171
* @return The title for the specified state.
7272
*/
73-
- (NSAttributedString * _Nullable)attributedTitleForState:(ASControlState)state AS_WARN_UNUSED_RESULT;
73+
- (nullable NSAttributedString *)attributedTitleForState:(UIControlState)state AS_WARN_UNUSED_RESULT;
7474

7575
/**
7676
* Sets the styled title to use for the specified state. This will reset styled title previously set with -setTitle:withFont:withColor:forState.
7777
*
7878
* @param title The styled text string to use for the title.
79-
* @param state The state that uses the specified title. The possible values are described in ASControlState.
79+
* @param state The control state that uses the specified title.
8080
*/
81-
- (void)setAttributedTitle:(nullable NSAttributedString *)title forState:(ASControlState)state;
81+
- (void)setAttributedTitle:(nullable NSAttributedString *)title forState:(UIControlState)state;
8282

8383
#if TARGET_OS_IOS
8484
/**
@@ -87,44 +87,44 @@ typedef NS_ENUM(NSInteger, ASButtonNodeImageAlignment) {
8787
* @param title The styled text string to use for the title.
8888
* @param font The font to use for the title.
8989
* @param color The color to use for the title.
90-
* @param state The state that uses the specified title. The possible values are described in ASControlState.
90+
* @param state The control state that uses the specified title.
9191
*/
92-
- (void)setTitle:(NSString *)title withFont:(nullable UIFont *)font withColor:(nullable UIColor *)color forState:(ASControlState)state;
92+
- (void)setTitle:(NSString *)title withFont:(nullable UIFont *)font withColor:(nullable UIColor *)color forState:(UIControlState)state;
9393
#endif
9494
/**
9595
* Returns the image used for a button state.
9696
*
97-
* @param state The state that uses the image. Possible values are described in ASControlState.
97+
* @param state The control state that uses the image.
9898
*
9999
* @return The image used for the specified state.
100100
*/
101-
- (nullable UIImage *)imageForState:(ASControlState)state AS_WARN_UNUSED_RESULT;
101+
- (nullable UIImage *)imageForState:(UIControlState)state AS_WARN_UNUSED_RESULT;
102102

103103
/**
104104
* Sets the image to use for the specified state.
105105
*
106106
* @param image The image to use for the specified state.
107-
* @param state The state that uses the specified title. The values are described in ASControlState.
107+
* @param state The control state that uses the specified title.
108108
*/
109-
- (void)setImage:(nullable UIImage *)image forState:(ASControlState)state;
109+
- (void)setImage:(nullable UIImage *)image forState:(UIControlState)state;
110110

111111
/**
112112
* Sets the background image to use for the specified state.
113113
*
114114
* @param image The image to use for the specified state.
115-
* @param state The state that uses the specified title. The values are described in ASControlState.
115+
* @param state The control state that uses the specified title.
116116
*/
117-
- (void)setBackgroundImage:(nullable UIImage *)image forState:(ASControlState)state;
117+
- (void)setBackgroundImage:(nullable UIImage *)image forState:(UIControlState)state;
118118

119119

120120
/**
121121
* Returns the background image used for a button state.
122122
*
123-
* @param state The state that uses the image. Possible values are described in ASControlState.
123+
* @param state The control state that uses the image.
124124
*
125125
* @return The background image used for the specified state.
126126
*/
127-
- (nullable UIImage *)backgroundImageForState:(ASControlState)state AS_WARN_UNUSED_RESULT;
127+
- (nullable UIImage *)backgroundImageForState:(UIControlState)state AS_WARN_UNUSED_RESULT;
128128

129129
@end
130130

AsyncDisplayKit/ASButtonNode.mm

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ - (void)setImageAlignment:(ASButtonNodeImageAlignment)imageAlignment
303303

304304

305305
#if TARGET_OS_IOS
306-
- (void)setTitle:(NSString *)title withFont:(UIFont *)font withColor:(UIColor *)color forState:(ASControlState)state
306+
- (void)setTitle:(NSString *)title withFont:(UIFont *)font withColor:(UIColor *)color forState:(UIControlState)state
307307
{
308308
NSDictionary *attributes = @{
309309
NSFontAttributeName: font ? : [UIFont systemFontOfSize:[UIFont buttonFontSize]],
@@ -316,51 +316,51 @@ - (void)setTitle:(NSString *)title withFont:(UIFont *)font withColor:(UIColor *)
316316
}
317317
#endif
318318

319-
- (NSAttributedString *)attributedTitleForState:(ASControlState)state
319+
- (NSAttributedString *)attributedTitleForState:(UIControlState)state
320320
{
321321
ASDN::MutexLocker l(__instanceLock__);
322322
switch (state) {
323-
case ASControlStateNormal:
323+
case UIControlStateNormal:
324324
return _normalAttributedTitle;
325325

326-
case ASControlStateHighlighted:
326+
case UIControlStateHighlighted:
327327
return _highlightedAttributedTitle;
328328

329-
case ASControlStateSelected:
329+
case UIControlStateSelected:
330330
return _selectedAttributedTitle;
331331

332-
case ASControlStateSelected | ASControlStateHighlighted:
332+
case UIControlStateSelected | UIControlStateHighlighted:
333333
return _selectedHighlightedAttributedTitle;
334334

335-
case ASControlStateDisabled:
335+
case UIControlStateDisabled:
336336
return _disabledAttributedTitle;
337337

338338
default:
339339
return _normalAttributedTitle;
340340
}
341341
}
342342

343-
- (void)setAttributedTitle:(NSAttributedString *)title forState:(ASControlState)state
343+
- (void)setAttributedTitle:(NSAttributedString *)title forState:(UIControlState)state
344344
{
345345
ASDN::MutexLocker l(__instanceLock__);
346346
switch (state) {
347-
case ASControlStateNormal:
347+
case UIControlStateNormal:
348348
_normalAttributedTitle = [title copy];
349349
break;
350350

351-
case ASControlStateHighlighted:
351+
case UIControlStateHighlighted:
352352
_highlightedAttributedTitle = [title copy];
353353
break;
354354

355-
case ASControlStateSelected:
355+
case UIControlStateSelected:
356356
_selectedAttributedTitle = [title copy];
357357
break;
358358

359-
case ASControlStateSelected | ASControlStateHighlighted:
359+
case UIControlStateSelected | UIControlStateHighlighted:
360360
_selectedHighlightedAttributedTitle = [title copy];
361361
break;
362362

363-
case ASControlStateDisabled:
363+
case UIControlStateDisabled:
364364
_disabledAttributedTitle = [title copy];
365365
break;
366366

@@ -371,51 +371,51 @@ - (void)setAttributedTitle:(NSAttributedString *)title forState:(ASControlState)
371371
[self updateTitle];
372372
}
373373

374-
- (UIImage *)imageForState:(ASControlState)state
374+
- (UIImage *)imageForState:(UIControlState)state
375375
{
376376
ASDN::MutexLocker l(__instanceLock__);
377377
switch (state) {
378-
case ASControlStateNormal:
378+
case UIControlStateNormal:
379379
return _normalImage;
380380

381-
case ASControlStateHighlighted:
381+
case UIControlStateHighlighted:
382382
return _highlightedImage;
383383

384-
case ASControlStateSelected:
384+
case UIControlStateSelected:
385385
return _selectedImage;
386386

387-
case ASControlStateSelected | ASControlStateHighlighted:
387+
case UIControlStateSelected | UIControlStateHighlighted:
388388
return _selectedHighlightedImage;
389389

390-
case ASControlStateDisabled:
390+
case UIControlStateDisabled:
391391
return _disabledImage;
392392

393393
default:
394394
return _normalImage;
395395
}
396396
}
397397

398-
- (void)setImage:(UIImage *)image forState:(ASControlState)state
398+
- (void)setImage:(UIImage *)image forState:(UIControlState)state
399399
{
400400
ASDN::MutexLocker l(__instanceLock__);
401401
switch (state) {
402-
case ASControlStateNormal:
402+
case UIControlStateNormal:
403403
_normalImage = image;
404404
break;
405405

406-
case ASControlStateHighlighted:
406+
case UIControlStateHighlighted:
407407
_highlightedImage = image;
408408
break;
409409

410-
case ASControlStateSelected:
410+
case UIControlStateSelected:
411411
_selectedImage = image;
412412
break;
413413

414-
case ASControlStateSelected | ASControlStateHighlighted:
414+
case UIControlStateSelected | UIControlStateHighlighted:
415415
_selectedHighlightedImage = image;
416416
break;
417417

418-
case ASControlStateDisabled:
418+
case UIControlStateDisabled:
419419
_disabledImage = image;
420420
break;
421421

@@ -425,51 +425,51 @@ - (void)setImage:(UIImage *)image forState:(ASControlState)state
425425
[self updateImage];
426426
}
427427

428-
- (UIImage *)backgroundImageForState:(ASControlState)state
428+
- (UIImage *)backgroundImageForState:(UIControlState)state
429429
{
430430
ASDN::MutexLocker l(__instanceLock__);
431431
switch (state) {
432-
case ASControlStateNormal:
432+
case UIControlStateNormal:
433433
return _normalBackgroundImage;
434434

435-
case ASControlStateHighlighted:
435+
case UIControlStateHighlighted:
436436
return _highlightedBackgroundImage;
437437

438-
case ASControlStateSelected:
438+
case UIControlStateSelected:
439439
return _selectedBackgroundImage;
440440

441-
case ASControlStateSelected | ASControlStateHighlighted:
441+
case UIControlStateSelected | UIControlStateHighlighted:
442442
return _selectedHighlightedBackgroundImage;
443443

444-
case ASControlStateDisabled:
444+
case UIControlStateDisabled:
445445
return _disabledBackgroundImage;
446446

447447
default:
448448
return _normalBackgroundImage;
449449
}
450450
}
451451

452-
- (void)setBackgroundImage:(UIImage *)image forState:(ASControlState)state
452+
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state
453453
{
454454
ASDN::MutexLocker l(__instanceLock__);
455455
switch (state) {
456-
case ASControlStateNormal:
456+
case UIControlStateNormal:
457457
_normalBackgroundImage = image;
458458
break;
459459

460-
case ASControlStateHighlighted:
460+
case UIControlStateHighlighted:
461461
_highlightedBackgroundImage = image;
462462
break;
463463

464-
case ASControlStateSelected:
464+
case UIControlStateSelected:
465465
_selectedBackgroundImage = image;
466466
break;
467467

468-
case ASControlStateSelected | ASControlStateHighlighted:
468+
case UIControlStateSelected | UIControlStateHighlighted:
469469
_selectedHighlightedBackgroundImage = image;
470470
break;
471471

472-
case ASControlStateDisabled:
472+
case UIControlStateDisabled:
473473
_disabledBackgroundImage = image;
474474
break;
475475

AsyncDisplayKit/ASControlNode.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,19 @@ typedef NS_OPTIONS(NSUInteger, ASControlNodeEvent)
4343
ASControlNodeEventAllEvents = 0xFFFFFFFF
4444
};
4545

46-
typedef NS_OPTIONS(NSUInteger, ASControlState) {
47-
ASControlStateNormal = 0,
48-
ASControlStateHighlighted = 1 << 0, // used when ASControlNode isHighlighted is set
49-
ASControlStateDisabled = 1 << 1,
50-
ASControlStateSelected = 1 << 2, // used when ASControlNode isSelected is set
51-
ASControlStateReserved = 0xFF000000 // flags reserved for internal framework use
52-
};
46+
/**
47+
* Compatibility aliases for @c ASControlState enum.
48+
* We previously provided our own enum, but when it was imported
49+
* into Swift, the @c normal (0) option disappeared.
50+
*
51+
* Apple's UIControlState enum gets special treatment here, and
52+
* UIControlStateNormal is available in Swift.
53+
*/
54+
typedef UIControlState ASControlState ASDISPLAYNODE_DEPRECATED_MSG("Use UIControlState.");
55+
static UIControlState const ASControlStateNormal ASDISPLAYNODE_DEPRECATED_MSG("Use UIControlStateNormal.") = UIControlStateNormal;
56+
static UIControlState const ASControlStateDisabled ASDISPLAYNODE_DEPRECATED_MSG("Use UIControlStateDisabled.") = UIControlStateDisabled;
57+
static UIControlState const ASControlStateHighlighted ASDISPLAYNODE_DEPRECATED_MSG("Use UIControlStateHighlighted.") = UIControlStateHighlighted;
58+
static UIControlState const ASControlStateSelected ASDISPLAYNODE_DEPRECATED_MSG("Use UIControlStateSelected.") = UIControlStateSelected;
5359

5460
/**
5561
@abstract ASControlNode is the base class for control nodes (such as buttons), or nodes that track touches to invoke targets with action messages.

AsyncDisplayKit/ASVideoPlayerNode.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ - (void)createFullScreenButton
363363
_fullScreenButtonNode.style.preferredSize = CGSizeMake(16.0, 22.0);
364364

365365
if (_delegateFlags.delegateFullScreenButtonImage) {
366-
[_fullScreenButtonNode setImage:[_delegate videoPlayerNodeFullScreenButtonImage:self] forState:ASControlStateNormal];
366+
[_fullScreenButtonNode setImage:[_delegate videoPlayerNodeFullScreenButtonImage:self] forState:UIControlStateNormal];
367367
}
368368

369369
[_fullScreenButtonNode addTarget:self action:@selector(didTapFullScreenButton:) forControlEvents:ASControlNodeEventTouchUpInside];

AsyncDisplayKit/Debug/ASLayoutElementInspectorCell.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,11 @@ - (ASButtonNode *)makeBtnNodeWithTitle:(NSString *)title
431431
borderWidth:3];
432432
ASButtonNode *btn = [[ASButtonNode alloc] init];
433433
btn.contentEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 5);
434-
[btn setAttributedTitle:[ASLayoutElementInspectorCell attributedStringFromString:title] forState:ASControlStateNormal];
435-
[btn setAttributedTitle:[ASLayoutElementInspectorCell attributedStringFromString:title withTextColor:[UIColor lightGrayColor]] forState:ASControlStateDisabled];
436-
[btn setBackgroundImage:clearStretchBtnImg forState:ASControlStateNormal];
437-
[btn setBackgroundImage:orangeStretchBtnImg forState:ASControlStateSelected];
438-
[btn setBackgroundImage:greyStretchBtnImg forState:ASControlStateDisabled];
434+
[btn setAttributedTitle:[ASLayoutElementInspectorCell attributedStringFromString:title] forState:UIControlStateNormal];
435+
[btn setAttributedTitle:[ASLayoutElementInspectorCell attributedStringFromString:title withTextColor:[UIColor lightGrayColor]] forState:UIControlStateDisabled];
436+
[btn setBackgroundImage:clearStretchBtnImg forState:UIControlStateNormal];
437+
[btn setBackgroundImage:orangeStretchBtnImg forState:UIControlStateSelected];
438+
[btn setBackgroundImage:greyStretchBtnImg forState:UIControlStateDisabled];
439439

440440
return btn;
441441
}
@@ -485,9 +485,9 @@ - (instancetype)initWithEnumOptions:(BOOL)yes enumStrings:(NSArray<NSString *> *
485485
int index = 0;
486486
for (NSString *optionStr in options) {
487487
ASButtonNode *btn = [[ASButtonNode alloc] init];
488-
[btn setAttributedTitle:[ASLayoutElementInspectorCell attributedStringFromString:optionStr] forState:ASControlStateNormal];
488+
[btn setAttributedTitle:[ASLayoutElementInspectorCell attributedStringFromString:optionStr] forState:UIControlStateNormal];
489489
[btn setAttributedTitle:[ASLayoutElementInspectorCell attributedStringFromString:optionStr withTextColor:[UIColor redColor]]
490-
forState:ASControlStateSelected];
490+
forState:UIControlStateSelected];
491491
[btn addTarget:self action:@selector(enumOptionSelected:) forControlEvents:ASControlNodeEventTouchUpInside];
492492
btn.selected = (index == currentOption) ? YES : NO;
493493
[_textNodes addObject:btn];

AsyncDisplayKit/Debug/ASLayoutElementInspectorNode.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ - (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(
192192
// UIImage *colorBtnImg = [ASLayoutElementInspectorNode imageForButtonWithBackgroundColor:nodeBackgroundColor
193193
// borderColor:[UIColor whiteColor]
194194
// borderWidth:3];
195-
// [_itemBackgroundColorBtn setBackgroundImage:colorBtnImg forState:ASControlStateNormal];
195+
// [_itemBackgroundColorBtn setBackgroundImage:colorBtnImg forState:UIControlStateNormal];
196196
// } else {
197197
// _itemBackgroundColorBtn.enabled = NO;
198198
// }
@@ -209,13 +209,13 @@ - (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(
209209
//
210210
// NSUInteger alignSelfValue = [self.layoutElementToEdit alignSelf];
211211
// NSString *newTitle = [@"alignSelf:" stringByAppendingString:[self alignSelfName:alignSelfValue]];
212-
// [_alignSelfBtn setAttributedTitle:[self attributedStringFromString:newTitle] forState:ASControlStateNormal];
212+
// [_alignSelfBtn setAttributedTitle:[self attributedStringFromString:newTitle] forState:UIControlStateNormal];
213213
//
214214
// if ([self layoutSpec]) {
215215
// _alignItemsBtn.enabled = YES;
216216
//// NSUInteger alignItemsValue = [[self layoutSpec] alignItems];
217217
//// newTitle = [@"alignItems:" stringByAppendingString:[self alignSelfName:alignItemsValue]];
218-
//// [_alignItemsBtn setAttributedTitle:[self attributedStringFromString:newTitle] forState:ASControlStateNormal];
218+
//// [_alignItemsBtn setAttributedTitle:[self attributedStringFromString:newTitle] forState:UIControlStateNormal];
219219
// }
220220
//
221221
// [self setNeedsLayout];

0 commit comments

Comments
 (0)