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

Commit 2f7aae1

Browse files
committed
Merge pull request #1042 from binl/bl_control_state_fix
Make ASControlState imitate UIControlState
2 parents fa9668a + a36a955 commit 2f7aae1

3 files changed

Lines changed: 17 additions & 9 deletions

File tree

AsyncDisplayKit/ASButtonNode.mm

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,27 @@ - (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
55+
{
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
5769
{
70+
[super setSelected:selected];
5871
[self updateImage];
5972
[self updateTitle];
6073
}

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)