From e3091737cad01b2966785a1d01a5b3d4fb86b51a Mon Sep 17 00:00:00 2001 From: Garrett Moon Date: Thu, 25 Aug 2016 21:18:04 -0700 Subject: [PATCH] Enable ASRangeControllerUpdateRangeProtocol by default if view controller or node support it. (#2133) --- AsyncDisplayKit/ASViewController.h | 2 +- AsyncDisplayKit/ASViewController.mm | 21 +++++++++------------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/AsyncDisplayKit/ASViewController.h b/AsyncDisplayKit/ASViewController.h index 84bd14d604..5a620e24c8 100644 --- a/AsyncDisplayKit/ASViewController.h +++ b/AsyncDisplayKit/ASViewController.h @@ -68,7 +68,7 @@ typedef ASTraitCollection * _Nonnull (^ASDisplayTraitsForTraitWindowSizeBlock)(C * Automatically adjust range mode based on view events. If you set this to YES, the view controller or its node * must conform to the ASRangeControllerUpdateRangeProtocol. * - * Default value is NO. + * Default value is YES *if* node or view controller conform to ASRangeControllerUpdateRangeProtocol otherwise it is NO. */ @property (nonatomic, assign) BOOL automaticallyAdjustRangeModeBasedOnViewEvents; diff --git a/AsyncDisplayKit/ASViewController.mm b/AsyncDisplayKit/ASViewController.mm index dd29f17de4..af50c36283 100644 --- a/AsyncDisplayKit/ASViewController.mm +++ b/AsyncDisplayKit/ASViewController.mm @@ -29,7 +29,6 @@ NSInteger _visibilityDepth; BOOL _selfConformsToRangeModeProtocol; BOOL _nodeConformsToRangeModeProtocol; - BOOL _didCheckRangeModeProtocolConformance; } - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil @@ -54,7 +53,9 @@ ASDisplayNodeAssertTrue(!node.layerBacked); _node = node; - _automaticallyAdjustRangeModeBasedOnViewEvents = NO; + _selfConformsToRangeModeProtocol = [self conformsToProtocol:@protocol(ASRangeControllerUpdateRangeProtocol)]; + _nodeConformsToRangeModeProtocol = [_node conformsToProtocol:@protocol(ASRangeControllerUpdateRangeProtocol)]; + _automaticallyAdjustRangeModeBasedOnViewEvents = _selfConformsToRangeModeProtocol || _nodeConformsToRangeModeProtocol; return self; } @@ -168,22 +169,18 @@ ASVisibilityDepthImplementation; - (void)setAutomaticallyAdjustRangeModeBasedOnViewEvents:(BOOL)automaticallyAdjustRangeModeBasedOnViewEvents { - _automaticallyAdjustRangeModeBasedOnViewEvents = automaticallyAdjustRangeModeBasedOnViewEvents; + if (automaticallyAdjustRangeModeBasedOnViewEvents != _automaticallyAdjustRangeModeBasedOnViewEvents) { + if (automaticallyAdjustRangeModeBasedOnViewEvents && _selfConformsToRangeModeProtocol == NO && _nodeConformsToRangeModeProtocol == NO) { + NSLog(@"Warning: automaticallyAdjustRangeModeBasedOnViewEvents set to YES in %@, but range mode updating is not possible because neither view controller nor node %@ conform to ASRangeControllerUpdateRangeProtocol.", self, _node); + } + _automaticallyAdjustRangeModeBasedOnViewEvents = automaticallyAdjustRangeModeBasedOnViewEvents; + } } - (void)updateCurrentRangeModeWithModeIfPossible:(ASLayoutRangeMode)rangeMode { if (!_automaticallyAdjustRangeModeBasedOnViewEvents) { return; } - if (!_didCheckRangeModeProtocolConformance) { - _selfConformsToRangeModeProtocol = [self conformsToProtocol:@protocol(ASRangeControllerUpdateRangeProtocol)]; - _nodeConformsToRangeModeProtocol = [_node conformsToProtocol:@protocol(ASRangeControllerUpdateRangeProtocol)]; - _didCheckRangeModeProtocolConformance = YES; - if (!_selfConformsToRangeModeProtocol && !_nodeConformsToRangeModeProtocol) { - NSLog(@"Warning: automaticallyAdjustRangeModeBasedOnViewEvents set to YES in %@, but range mode updating is not possible because neither view controller nor node %@ conform to ASRangeControllerUpdateRangeProtocol.", self, _node); - } - } - if (_selfConformsToRangeModeProtocol) { id rangeUpdater = (id)self; [rangeUpdater updateCurrentRangeWithMode:rangeMode];