From 760f4ada9179f19ecc18819b390bb18dc3fe7ea5 Mon Sep 17 00:00:00 2001 From: Michael Schneider Date: Fri, 26 Feb 2016 20:24:19 -0800 Subject: [PATCH] Add API to ASViewController to automatically adjust the range mode of the containing node based on view events --- AsyncDisplayKit/ASViewController.h | 3 +++ AsyncDisplayKit/ASViewController.m | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/AsyncDisplayKit/ASViewController.h b/AsyncDisplayKit/ASViewController.h index d7286272b8..2814965e96 100644 --- a/AsyncDisplayKit/ASViewController.h +++ b/AsyncDisplayKit/ASViewController.h @@ -30,6 +30,9 @@ NS_ASSUME_NONNULL_BEGIN // Refer to examples/SynchronousConcurrency, AsyncViewController.m @property (nonatomic, assign) BOOL neverShowPlaceholders; +/// Automatically adjust the range mode based on view evenets if the containing node confirms to the ASRangeControllerUpdateRangeProtocol +@property (nonatomic, assign) BOOL automaticallyAdjustRangeModeBasedOnViewEvents; + /** * The constrained size used to measure the backing node. diff --git a/AsyncDisplayKit/ASViewController.m b/AsyncDisplayKit/ASViewController.m index 6f052a5c60..faed4b14c2 100644 --- a/AsyncDisplayKit/ASViewController.m +++ b/AsyncDisplayKit/ASViewController.m @@ -11,6 +11,7 @@ #import "ASDimension.h" #import "ASDisplayNode+FrameworkPrivate.h" #import "ASDisplayNode+Beta.h" +#import "ASRangeController.h" @implementation ASViewController { @@ -38,6 +39,8 @@ ASDisplayNodeAssertNotNil(node, @"Node must not be nil"); ASDisplayNodeAssertTrue(!node.layerBacked); _node = node; + + _automaticallyAdjustRangeModeBasedOnViewEvents = NO; return self; } @@ -68,6 +71,26 @@ [super viewWillAppear:animated]; _ensureDisplayed = YES; [_node recursivelyFetchData]; + + [self updateCurrentRangeModeWithModeIfPossible:ASLayoutRangeModeFull]; +} + +- (void)viewDidDisappear:(BOOL)animated +{ + [super viewDidDisappear:animated]; + + [self updateCurrentRangeModeWithModeIfPossible:ASLayoutRangeModeMinimum]; +} + +// MARK: - Update Range Mode + +- (void)updateCurrentRangeModeWithModeIfPossible:(ASLayoutRangeMode)rangeMode +{ + if (!self.automaticallyAdjustRangeModeBasedOnViewEvents) { return; } + if (![_node conformsToProtocol:@protocol(ASRangeControllerUpdateRangeProtocol)]) { return; } + + id updateRangeNode = (id)_node; + [updateRangeNode updateCurrentRangeWithMode:rangeMode]; } // MARK: - Layout Helpers