Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 4435405

Browse files
author
Bin Liu
committed
Make ASControlState imitate UIControlState
- selected state isn't implicitly controlled by ASControlNode anymore - highlighted state can be overriden by users - Decouple ASButtonNode's state from control events
1 parent fa9668a commit 4435405

3 files changed

Lines changed: 19 additions & 11 deletions

File tree

AsyncDisplayKit/ASButtonNode.mm

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,29 @@ - (instancetype)init
4747

4848
[self addSubnode:_titleNode];
4949
[self addSubnode:_imageNode];
50-
51-
[self addTarget:self action:@selector(controlEventUpdated:) forControlEvents:ASControlNodeEventAllEvents];
5250
}
5351
return self;
5452
}
5553

56-
- (void)controlEventUpdated:(ASControlNode *)node
54+
- (void)setEnabled:(BOOL)enabled
5755
{
58-
[self updateImage];
59-
[self updateTitle];
56+
[super setEnabled:enabled];
57+
[self updateImage];
58+
[self updateTitle];
59+
}
60+
61+
- (void)setHighlighted:(BOOL)highlighted
62+
{
63+
[super setHighlighted:highlighted];
64+
[self updateImage];
65+
[self updateTitle];
66+
}
67+
68+
- (void)setSelected:(BOOL)selected
69+
{
70+
[super setSelected:selected];
71+
[self updateImage];
72+
[self updateTitle];
6073
}
6174

6275
- (void)updateImage

AsyncDisplayKit/ASControlNode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ typedef NS_OPTIONS(NSUInteger, ASControlState) {
6060
@abstract Indicates whether or not the receiver is highlighted.
6161
@discussion This is set automatically when the there is a touch inside the control and removed on exit or touch up. This is different from touchInside in that it includes an area around the control, rather than just for touches inside the control.
6262
*/
63-
@property (nonatomic, readonly, assign, getter=isHighlighted) BOOL highlighted;
63+
@property (nonatomic, assign, getter=isHighlighted) BOOL highlighted;
6464

6565
/**
6666
@abstract Indicates whether or not the receiver is highlighted.

AsyncDisplayKit/ASControlNode.m

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ @interface ASControlNode ()
4646
}
4747

4848
// Read-write overrides.
49-
@property (nonatomic, readwrite, assign, getter=isHighlighted) BOOL highlighted;
5049
@property (nonatomic, readwrite, assign, getter=isTracking) BOOL tracking;
5150
@property (nonatomic, readwrite, assign, getter=isTouchInside) BOOL touchInside;
5251

@@ -186,10 +185,6 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
186185
// Send the appropriate touch-up control event.
187186
CGRect expandedBounds = CGRectInset(self.view.bounds, kASControlNodeExpandedInset, kASControlNodeExpandedInset);
188187
BOOL touchUpIsInsideExpandedBounds = CGRectContainsPoint(expandedBounds, touchLocation);
189-
190-
if (touchUpIsInsideExpandedBounds) {
191-
self.selected = !self.selected;
192-
}
193188

194189
[self sendActionsForControlEvents:(touchUpIsInsideExpandedBounds ? ASControlNodeEventTouchUpInside : ASControlNodeEventTouchUpOutside)
195190
withEvent:event];

0 commit comments

Comments
 (0)