From 4435405cbbedc9e8fb10e826226638d4af180f8f Mon Sep 17 00:00:00 2001 From: Bin Liu Date: Wed, 6 Jan 2016 12:17:38 -0800 Subject: [PATCH 1/2] 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 --- AsyncDisplayKit/ASButtonNode.mm | 23 ++++++++++++++++++----- AsyncDisplayKit/ASControlNode.h | 2 +- AsyncDisplayKit/ASControlNode.m | 5 ----- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/AsyncDisplayKit/ASButtonNode.mm b/AsyncDisplayKit/ASButtonNode.mm index 4e7330c5ba..55ed7d6123 100644 --- a/AsyncDisplayKit/ASButtonNode.mm +++ b/AsyncDisplayKit/ASButtonNode.mm @@ -47,16 +47,29 @@ [self addSubnode:_titleNode]; [self addSubnode:_imageNode]; - - [self addTarget:self action:@selector(controlEventUpdated:) forControlEvents:ASControlNodeEventAllEvents]; } return self; } -- (void)controlEventUpdated:(ASControlNode *)node +- (void)setEnabled:(BOOL)enabled { - [self updateImage]; - [self updateTitle]; + [super setEnabled:enabled]; + [self updateImage]; + [self updateTitle]; +} + +- (void)setHighlighted:(BOOL)highlighted +{ + [super setHighlighted:highlighted]; + [self updateImage]; + [self updateTitle]; +} + +- (void)setSelected:(BOOL)selected +{ + [super setSelected:selected]; + [self updateImage]; + [self updateTitle]; } - (void)updateImage diff --git a/AsyncDisplayKit/ASControlNode.h b/AsyncDisplayKit/ASControlNode.h index 72e1c52802..9f5c37e343 100644 --- a/AsyncDisplayKit/ASControlNode.h +++ b/AsyncDisplayKit/ASControlNode.h @@ -60,7 +60,7 @@ typedef NS_OPTIONS(NSUInteger, ASControlState) { @abstract Indicates whether or not the receiver is highlighted. @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. */ -@property (nonatomic, readonly, assign, getter=isHighlighted) BOOL highlighted; +@property (nonatomic, assign, getter=isHighlighted) BOOL highlighted; /** @abstract Indicates whether or not the receiver is highlighted. diff --git a/AsyncDisplayKit/ASControlNode.m b/AsyncDisplayKit/ASControlNode.m index 6a9c8bd250..66da4e5755 100644 --- a/AsyncDisplayKit/ASControlNode.m +++ b/AsyncDisplayKit/ASControlNode.m @@ -46,7 +46,6 @@ } // Read-write overrides. -@property (nonatomic, readwrite, assign, getter=isHighlighted) BOOL highlighted; @property (nonatomic, readwrite, assign, getter=isTracking) BOOL tracking; @property (nonatomic, readwrite, assign, getter=isTouchInside) BOOL touchInside; @@ -186,10 +185,6 @@ void _ASEnumerateControlEventsIncludedInMaskWithBlock(ASControlNodeEvent mask, v // Send the appropriate touch-up control event. CGRect expandedBounds = CGRectInset(self.view.bounds, kASControlNodeExpandedInset, kASControlNodeExpandedInset); BOOL touchUpIsInsideExpandedBounds = CGRectContainsPoint(expandedBounds, touchLocation); - - if (touchUpIsInsideExpandedBounds) { - self.selected = !self.selected; - } [self sendActionsForControlEvents:(touchUpIsInsideExpandedBounds ? ASControlNodeEventTouchUpInside : ASControlNodeEventTouchUpOutside) withEvent:event]; From a36a955eb06835f7a1774a301c0c7f79b21408e6 Mon Sep 17 00:00:00 2001 From: Bin Liu Date: Wed, 6 Jan 2016 13:09:59 -0800 Subject: [PATCH 2/2] fix indentation --- AsyncDisplayKit/ASButtonNode.mm | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/AsyncDisplayKit/ASButtonNode.mm b/AsyncDisplayKit/ASButtonNode.mm index 55ed7d6123..500d86271d 100644 --- a/AsyncDisplayKit/ASButtonNode.mm +++ b/AsyncDisplayKit/ASButtonNode.mm @@ -53,23 +53,23 @@ - (void)setEnabled:(BOOL)enabled { - [super setEnabled:enabled]; - [self updateImage]; - [self updateTitle]; + [super setEnabled:enabled]; + [self updateImage]; + [self updateTitle]; } - (void)setHighlighted:(BOOL)highlighted { - [super setHighlighted:highlighted]; - [self updateImage]; - [self updateTitle]; + [super setHighlighted:highlighted]; + [self updateImage]; + [self updateTitle]; } - (void)setSelected:(BOOL)selected { - [super setSelected:selected]; - [self updateImage]; - [self updateTitle]; + [super setSelected:selected]; + [self updateImage]; + [self updateTitle]; } - (void)updateImage