diff --git a/AsyncDisplayKit/ASDisplayNode.mm b/AsyncDisplayKit/ASDisplayNode.mm index 3bfe80760c..850d0a46aa 100644 --- a/AsyncDisplayKit/ASDisplayNode.mm +++ b/AsyncDisplayKit/ASDisplayNode.mm @@ -1704,7 +1704,7 @@ static NSInteger incrementIfFound(NSInteger i) { } if ([newSupernode supportsUpwardPropagation]) { - ASEnvironmentStatePropagateUp(newSupernode, self.environmentState.layoutOptionsState); + ASEnvironmentStatePropagateUp(newSupernode, _environmentState.layoutOptionsState); } } diff --git a/AsyncDisplayKit/Details/ASEnvironment.h b/AsyncDisplayKit/Details/ASEnvironment.h index 43e21bda09..62e352fb52 100644 --- a/AsyncDisplayKit/Details/ASEnvironment.h +++ b/AsyncDisplayKit/Details/ASEnvironment.h @@ -48,7 +48,6 @@ typedef struct ASEnvironmentLayoutOptionsState { ASEnvironmentStateExtensions _extensions; } ASEnvironmentLayoutOptionsState; -extern ASEnvironmentLayoutOptionsState ASEnvironmentLayoutOptionsStateCreate(); #pragma mark - ASEnvironmentHierarchyState @@ -59,7 +58,6 @@ typedef struct ASEnvironmentHierarchyState { unsigned transitioningSupernodes:1; // = NO unsigned layoutPending:1; // = NO } ASEnvironmentHierarchyState; -extern ASEnvironmentHierarchyState ASEnvironmentHierarchyStateCreate(); #pragma mark - ASEnvironmentState @@ -92,6 +90,7 @@ ASDISPLAYNODE_EXTERN_C_END /// Returns all children of an object which class conforms to the ASEnvironment protocol - (NSArray> *)children; +/// Classes should implement this method and return YES / NO dependent if upward propagation is enabled or not - (BOOL)supportsUpwardPropagation; @end diff --git a/AsyncDisplayKit/Details/ASEnvironment.m b/AsyncDisplayKit/Details/ASEnvironment.m index 5cbe4d95c1..01006405d4 100644 --- a/AsyncDisplayKit/Details/ASEnvironment.m +++ b/AsyncDisplayKit/Details/ASEnvironment.m @@ -10,32 +10,24 @@ #import "ASEnvironment.h" -ASEnvironmentLayoutOptionsState ASEnvironmentLayoutOptionsStateCreate() +ASEnvironmentLayoutOptionsState _ASEnvironmentLayoutOptionsStateCreate() { return (ASEnvironmentLayoutOptionsState) { - .spacingBefore = 0, - .flexBasis = ASRelativeDimensionUnconstrained, - .alignSelf = ASStackLayoutAlignSelfAuto, - - .sizeRange = ASRelativeSizeRangeMake(ASRelativeSizeMakeWithCGSize(CGSizeZero), ASRelativeSizeMakeWithCGSize(CGSizeZero)), - .layoutPosition = CGPointZero + // Default values can be defined in here }; } -ASEnvironmentHierarchyState ASEnvironmentHierarchyStateCreate() +ASEnvironmentHierarchyState _ASEnvironmentHierarchyStateCreate() { return (ASEnvironmentHierarchyState) { - .rasterized = NO, - .rangeManaged = NO, - .transitioningSupernodes = NO, - .layoutPending = NO + // Default values can be defined in here }; } ASEnvironmentState ASEnvironmentStateCreate() { return (ASEnvironmentState) { - .hierarchyState = ASEnvironmentHierarchyStateCreate(), - .layoutOptionsState = ASEnvironmentLayoutOptionsStateCreate() + .layoutOptionsState = _ASEnvironmentLayoutOptionsStateCreate(), + .hierarchyState = _ASEnvironmentHierarchyStateCreate() }; } \ No newline at end of file diff --git a/AsyncDisplayKit/Layout/ASLayoutSpec.mm b/AsyncDisplayKit/Layout/ASLayoutSpec.mm index 7c7598b90a..94e7e0a1a9 100644 --- a/AsyncDisplayKit/Layout/ASLayoutSpec.mm +++ b/AsyncDisplayKit/Layout/ASLayoutSpec.mm @@ -81,10 +81,8 @@ static NSString * const kDefaultChildrenKey = @"kDefaultChildrenKey"; id finalLayoutable = [child finalLayoutable]; if (finalLayoutable != child) { - // Copy layout options - ASEnvironmentState environmentState = finalLayoutable.environmentState; - environmentState.layoutOptionsState = child.environmentState.layoutOptionsState; - finalLayoutable.environmentState = environmentState; + // Layout options state of child needs to be copied to final layoutable + finalLayoutable.environmentState.layoutOptionsState = child.environmentState.layoutOptionsState; return finalLayoutable; } } @@ -159,6 +157,9 @@ static NSString * const kDefaultChildrenKey = @"kDefaultChildrenKey"; _environmentState = environmentState; } +// Subclasses can override this method to return NO, because upward propagation is not enabled if a layout +// specification has more than one child. Currently ASStackLayoutSpec and ASStaticLayoutSpec are currently +// the specifications that are known to have more than one. - (BOOL)supportsUpwardPropagation { return YES; diff --git a/AsyncDisplayKit/Layout/ASLayoutableExtensibility.h b/AsyncDisplayKit/Layout/ASLayoutableExtensibility.h index 1451368d27..c35d04f046 100644 --- a/AsyncDisplayKit/Layout/ASLayoutableExtensibility.h +++ b/AsyncDisplayKit/Layout/ASLayoutableExtensibility.h @@ -6,7 +6,7 @@ // Copyright © 2016 Facebook. All rights reserved. // -#import +#import @protocol ASLayoutableExtensibility diff --git a/AsyncDisplayKit/Layout/ASLayoutablePrivate.h b/AsyncDisplayKit/Layout/ASLayoutablePrivate.h index d18d0b7419..ce2de20f6d 100644 --- a/AsyncDisplayKit/Layout/ASLayoutablePrivate.h +++ b/AsyncDisplayKit/Layout/ASLayoutablePrivate.h @@ -231,30 +231,39 @@ extern void ASLayoutableClearCurrentContext(); #define ASEnvironmentLayoutExtensibilityForwarding \ - (void)setLayoutOptionExtensionBool:(BOOL)value atIndex:(int)idx\ {\ + _propertyLock.lock();\ _ASEnvironmentLayoutOptionsExtensionSetBoolAtIndex(self, idx, value);\ + _propertyLock.unlock();\ }\ \ - (BOOL)layoutOptionExtensionBoolAtIndex:(int)idx\ {\ + ASDN::MutexLocker l(_propertyLock);\ return _ASEnvironmentLayoutOptionsExtensionGetBoolAtIndex(self, idx);\ }\ \ - (void)setLayoutOptionExtensionInteger:(NSInteger)value atIndex:(int)idx\ {\ + _propertyLock.lock();\ _ASEnvironmentLayoutOptionsExtensionSetIntegerAtIndex(self, idx, value);\ + _propertyLock.unlock();\ }\ \ - (NSInteger)layoutOptionExtensionIntegerAtIndex:(int)idx\ {\ + ASDN::MutexLocker l(_propertyLock);\ return _ASEnvironmentLayoutOptionsExtensionGetIntegerAtIndex(self, idx);\ }\ \ - (void)setLayoutOptionExtensionEdgeInsets:(UIEdgeInsets)value atIndex:(int)idx\ {\ + _propertyLock.lock();\ _ASEnvironmentLayoutOptionsExtensionSetEdgeInsetsAtIndex(self, idx, value);\ + _propertyLock.unlock();\ }\ \ - (UIEdgeInsets)layoutOptionExtensionEdgeInsetsAtIndex:(int)idx\ {\ + ASDN::MutexLocker l(_propertyLock);\ return _ASEnvironmentLayoutOptionsExtensionGetEdgeInsetsAtIndex(self, idx);\ }\