From e7fccb23631fc49aa53f852d01aa8f13fdb45a4b Mon Sep 17 00:00:00 2001 From: Michael Schneider Date: Fri, 11 Nov 2016 17:32:19 -0800 Subject: [PATCH] Improve ASButtonNode layout invalidation --- AsyncDisplayKit/ASButtonNode.mm | 5 ++--- examples/ASDKLayoutTransition/Sample/ViewController.m | 8 ++------ 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/AsyncDisplayKit/ASButtonNode.mm b/AsyncDisplayKit/ASButtonNode.mm index 0520e66ac3..a8200ce534 100644 --- a/AsyncDisplayKit/ASButtonNode.mm +++ b/AsyncDisplayKit/ASButtonNode.mm @@ -142,6 +142,7 @@ [self updateBackgroundImage]; [self updateImage]; [self updateTitle]; + [self invalidateSize]; } - (void)setDisplaysAsynchronously:(BOOL)displaysAsynchronously @@ -172,7 +173,6 @@ if ((_imageNode != nil || newImage != nil) && newImage != self.imageNode.image) { _imageNode.image = newImage; [self setNeedsLayout]; - [self invalidateSize]; } } @@ -196,7 +196,6 @@ _titleNode.attributedText = newTitle; self.accessibilityLabel = _titleNode.accessibilityLabel; [self setNeedsLayout]; - [self invalidateSize]; } } @@ -220,7 +219,6 @@ if ((_backgroundImageNode != nil || newImage != nil) && newImage != self.backgroundImageNode.image) { _backgroundImageNode.image = newImage; [self setNeedsLayout]; - [self invalidateSize]; } } @@ -532,6 +530,7 @@ - (void)layout { [super layout]; + _backgroundImageNode.hidden = (_backgroundImageNode.image == nil); _imageNode.hidden = (_imageNode.image == nil); _titleNode.hidden = (_titleNode.attributedText.length == 0); diff --git a/examples/ASDKLayoutTransition/Sample/ViewController.m b/examples/ASDKLayoutTransition/Sample/ViewController.m index 28f08b251c..eb15153b63 100644 --- a/examples/ASDKLayoutTransition/Sample/ViewController.m +++ b/examples/ASDKLayoutTransition/Sample/ViewController.m @@ -61,11 +61,7 @@ _buttonNode = [[ASButtonNode alloc] init]; [_buttonNode setTitle:buttonTitle withFont:buttonFont withColor:buttonColor forState:ASControlStateNormal]; - - // Note: Currently we have to set all the button properties to the same one as for ASControlStateNormal. Otherwise - // if the button is involved in the layout transition it would break the transition as it does a layout pass - // while changing the title. This needs and will be fixed in the future! - [_buttonNode setTitle:buttonTitle withFont:buttonFont withColor:buttonColor forState:ASControlStateHighlighted]; + [_buttonNode setTitle:buttonTitle withFont:buttonFont withColor:[buttonColor colorWithAlphaComponent:0.5] forState:ASControlStateHighlighted]; // Some debug colors @@ -80,7 +76,7 @@ { [super didLoad]; - [self.buttonNode addTarget:self action:@selector(buttonPressed:) forControlEvents:ASControlNodeEventTouchDown]; + [self.buttonNode addTarget:self action:@selector(buttonPressed:) forControlEvents:ASControlNodeEventTouchUpInside]; } #pragma mark - Actions