From c7ea15a5e483a9388ebcca108dc3fb375467c3b9 Mon Sep 17 00:00:00 2001 From: Michael Schneider Date: Thu, 1 Dec 2016 09:56:41 -0800 Subject: [PATCH] Misc improvements to ASViewController (#2653) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove layoutThatFit: call in viewWillAppear: - Deprecate nodeConstrainedSize - Use the view’s bounds to layout the node --- AsyncDisplayKit/ASViewController.h | 23 +++++----- AsyncDisplayKit/ASViewController.mm | 70 +++++------------------------ 2 files changed, 24 insertions(+), 69 deletions(-) diff --git a/AsyncDisplayKit/ASViewController.h b/AsyncDisplayKit/ASViewController.h index 28d77399c0..dddf7784ef 100644 --- a/AsyncDisplayKit/ASViewController.h +++ b/AsyncDisplayKit/ASViewController.h @@ -64,16 +64,6 @@ typedef ASTraitCollection * _Nonnull (^ASDisplayTraitsForTraitWindowSizeBlock)(C // Refer to examples/SynchronousConcurrency, AsyncViewController.m @property (nonatomic, assign) BOOL neverShowPlaceholders; - -/** - * The constrained size used to measure the backing node. - * - * @discussion Defaults to providing a size range that uses the view controller view's bounds as - * both the min and max definitions. Override this method to provide a custom size range to the - * backing node. - */ -- (ASSizeRange)nodeConstrainedSize AS_WARN_UNUSED_RESULT; - @end @interface ASViewController (ASRangeControllerUpdateRangeProtocol) @@ -88,6 +78,19 @@ typedef ASTraitCollection * _Nonnull (^ASDisplayTraitsForTraitWindowSizeBlock)(C @end +@interface ASViewController (Deprecated) + +/** + * The constrained size used to measure the backing node. + * + * @discussion Defaults to providing a size range that uses the view controller view's bounds as + * both the min and max definitions. Override this method to provide a custom size range to the + * backing node. + */ +- (ASSizeRange)nodeConstrainedSize AS_WARN_UNUSED_RESULT ASDISPLAYNODE_DEPRECATED_MSG("Set the size directly to the view's frame"); + +@end + @interface ASViewController (Unavailable) - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil AS_UNAVAILABLE("ASViewController requires using -initWithNode:"); diff --git a/AsyncDisplayKit/ASViewController.mm b/AsyncDisplayKit/ASViewController.mm index 1c8d7c1ff6..4cf58d166e 100644 --- a/AsyncDisplayKit/ASViewController.mm +++ b/AsyncDisplayKit/ASViewController.mm @@ -132,11 +132,12 @@ [self progagateNewEnvironmentTraitCollection:environmentTraitCollection]; }]; } else { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + // Call layoutThatFits: to let the node prepare for a layout that will happen shortly in the layout pass of the view. + // If the node's constrained size didn't change between the last layout pass it's a no-op [_node layoutThatFits:[self nodeConstrainedSize]]; - } - - if (!AS_AT_LEAST_IOS9) { - [self _legacyHandleViewDidLayoutSubviews]; +#pragma clang diagnostic pop } } @@ -156,10 +157,9 @@ ASVisibilityDidMoveToParentViewController; [super viewWillAppear:animated]; _ensureDisplayed = YES; - // A measure as well as layout pass is forced this early to get nodes like ASCollectionNode, ASTableNode etc. + // A layout pass is forced this early to get nodes like ASCollectionNode, ASTableNode etc. // into the hierarchy before UIKit applies the scroll view inset adjustments, if automatic subnode management // is enabled. Otherwise the insets would not be applied. - [_node layoutThatFits:[self nodeConstrainedSize]]; [_node.view layoutIfNeeded]; if (_parentManagesVisibilityDepth == NO) { @@ -239,12 +239,7 @@ ASVisibilityDepthImplementation; - (ASSizeRange)nodeConstrainedSize { - if (AS_AT_LEAST_IOS9) { - CGSize viewSize = self.view.bounds.size; - return ASSizeRangeMake(viewSize); - } else { - return [self _legacyConstrainedSize]; - } + return ASSizeRangeMake(self.view.bounds.size); } - (ASInterfaceState)interfaceState @@ -252,51 +247,6 @@ ASVisibilityDepthImplementation; return _node.interfaceState; } -#pragma mark - Legacy Layout Handling - -- (BOOL)_shouldLayoutTheLegacyWay -{ - BOOL isModalViewController = (self.presentingViewController != nil && self.presentedViewController == nil); - BOOL hasNavigationController = (self.navigationController != nil); - BOOL hasParentViewController = (self.parentViewController != nil); - if (isModalViewController && !hasNavigationController && !hasParentViewController) { - return YES; - } - - // Check if the view controller is a root view controller - BOOL isRootViewController = self.view.window.rootViewController == self; - if (isRootViewController) { - return YES; - } - - return NO; -} - -- (ASSizeRange)_legacyConstrainedSize -{ - // In modal presentation the view does not have the right bounds in iOS7 and iOS8. As workaround using the superviews - // view bounds - UIView *view = self.view; - CGSize viewSize = view.bounds.size; - if ([self _shouldLayoutTheLegacyWay]) { - UIView *superview = view.superview; - if (superview != nil) { - viewSize = superview.bounds.size; - } - } - return ASSizeRangeMake(viewSize, viewSize); -} - -- (void)_legacyHandleViewDidLayoutSubviews -{ - // In modal presentation or as root viw controller the view does not automatic resize in iOS7 and iOS8. - // As workaround we adjust the frame of the view manually - if ([self _shouldLayoutTheLegacyWay]) { - CGSize maxConstrainedSize = [self nodeConstrainedSize].max; - _node.frame = (CGRect){.origin = CGPointZero, .size = maxConstrainedSize}; - } -} - #pragma mark - ASEnvironmentTraitCollection - (ASEnvironmentTraitCollection)environmentTraitCollectionForUITraitCollection:(UITraitCollection *)traitCollection @@ -325,10 +275,12 @@ ASVisibilityDepthImplementation; for (id child in children) { ASEnvironmentStatePropagateDown(child, environmentState.environmentTraitCollection); } - - // once we've propagated all the traits, layout this node. +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + // Once we've propagated all the traits, layout this node. // Remeasure the node with the latest constrained size – old constrained size may be incorrect. [self.node layoutThatFits:[self nodeConstrainedSize]]; +#pragma clang diagnostic pop } }