First pass of comments

* make variable naming reflect ASEnvironmentTraitCollection vs ASTraitCollection
* move trait propagation to cell allocation instead of via a nested block
* move trait propagation when setting a displaynode's supernode instead of when adding a subnode
* fixed misspelling of "colection"
This commit is contained in:
ricky
2016-06-03 09:59:24 -07:00
parent 501fed16aa
commit 01dbc86778
12 changed files with 84 additions and 70 deletions

View File

@@ -580,8 +580,8 @@
E55D86331CA8A14000A0C26F /* ASLayoutable.mm in Sources */ = {isa = PBXBuildFile; fileRef = E55D86311CA8A14000A0C26F /* ASLayoutable.mm */; }; E55D86331CA8A14000A0C26F /* ASLayoutable.mm in Sources */ = {isa = PBXBuildFile; fileRef = E55D86311CA8A14000A0C26F /* ASLayoutable.mm */; };
E5711A2B1C840C81009619D4 /* ASIndexedNodeContext.h in Headers */ = {isa = PBXBuildFile; fileRef = E5711A2A1C840C81009619D4 /* ASIndexedNodeContext.h */; settings = {ATTRIBUTES = (Public, ); }; }; E5711A2B1C840C81009619D4 /* ASIndexedNodeContext.h in Headers */ = {isa = PBXBuildFile; fileRef = E5711A2A1C840C81009619D4 /* ASIndexedNodeContext.h */; settings = {ATTRIBUTES = (Public, ); }; };
E5711A2C1C840C81009619D4 /* ASIndexedNodeContext.h in Headers */ = {isa = PBXBuildFile; fileRef = E5711A2A1C840C81009619D4 /* ASIndexedNodeContext.h */; }; E5711A2C1C840C81009619D4 /* ASIndexedNodeContext.h in Headers */ = {isa = PBXBuildFile; fileRef = E5711A2A1C840C81009619D4 /* ASIndexedNodeContext.h */; };
E5711A2E1C840C96009619D4 /* ASIndexedNodeContext.m in Sources */ = {isa = PBXBuildFile; fileRef = E5711A2D1C840C96009619D4 /* ASIndexedNodeContext.m */; }; E5711A2E1C840C96009619D4 /* ASIndexedNodeContext.mm in Sources */ = {isa = PBXBuildFile; fileRef = E5711A2D1C840C96009619D4 /* ASIndexedNodeContext.mm */; };
E5711A301C840C96009619D4 /* ASIndexedNodeContext.m in Sources */ = {isa = PBXBuildFile; fileRef = E5711A2D1C840C96009619D4 /* ASIndexedNodeContext.m */; }; E5711A301C840C96009619D4 /* ASIndexedNodeContext.mm in Sources */ = {isa = PBXBuildFile; fileRef = E5711A2D1C840C96009619D4 /* ASIndexedNodeContext.mm */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */ /* Begin PBXContainerItemProxy section */
@@ -940,7 +940,7 @@
E52405B41C8FEF16004DC8E7 /* ASDisplayNodeLayoutContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASDisplayNodeLayoutContext.h; sourceTree = "<group>"; }; E52405B41C8FEF16004DC8E7 /* ASDisplayNodeLayoutContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASDisplayNodeLayoutContext.h; sourceTree = "<group>"; };
E55D86311CA8A14000A0C26F /* ASLayoutable.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = ASLayoutable.mm; path = AsyncDisplayKit/Layout/ASLayoutable.mm; sourceTree = "<group>"; }; E55D86311CA8A14000A0C26F /* ASLayoutable.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = ASLayoutable.mm; path = AsyncDisplayKit/Layout/ASLayoutable.mm; sourceTree = "<group>"; };
E5711A2A1C840C81009619D4 /* ASIndexedNodeContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASIndexedNodeContext.h; sourceTree = "<group>"; }; E5711A2A1C840C81009619D4 /* ASIndexedNodeContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASIndexedNodeContext.h; sourceTree = "<group>"; };
E5711A2D1C840C96009619D4 /* ASIndexedNodeContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASIndexedNodeContext.m; sourceTree = "<group>"; }; E5711A2D1C840C96009619D4 /* ASIndexedNodeContext.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASIndexedNodeContext.mm; sourceTree = "<group>"; };
EFA731F0396842FF8AB635EE /* libPods-AsyncDisplayKitTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-AsyncDisplayKitTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; EFA731F0396842FF8AB635EE /* libPods-AsyncDisplayKitTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-AsyncDisplayKitTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
FB07EABBCF28656C6297BC2D /* Pods-AsyncDisplayKitTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AsyncDisplayKitTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-AsyncDisplayKitTests/Pods-AsyncDisplayKitTests.debug.xcconfig"; sourceTree = "<group>"; }; FB07EABBCF28656C6297BC2D /* Pods-AsyncDisplayKitTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AsyncDisplayKitTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-AsyncDisplayKitTests/Pods-AsyncDisplayKitTests.debug.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
@@ -1397,7 +1397,7 @@
AC026B671BD57D6F00BBC17E /* ASChangeSetDataController.h */, AC026B671BD57D6F00BBC17E /* ASChangeSetDataController.h */,
AC026B681BD57D6F00BBC17E /* ASChangeSetDataController.m */, AC026B681BD57D6F00BBC17E /* ASChangeSetDataController.m */,
E5711A2A1C840C81009619D4 /* ASIndexedNodeContext.h */, E5711A2A1C840C81009619D4 /* ASIndexedNodeContext.h */,
E5711A2D1C840C96009619D4 /* ASIndexedNodeContext.m */, E5711A2D1C840C96009619D4 /* ASIndexedNodeContext.mm */,
); );
name = "Data Controller"; name = "Data Controller";
sourceTree = "<group>"; sourceTree = "<group>";
@@ -2088,7 +2088,7 @@
205F0E121B371BD7007741D0 /* ASScrollDirection.m in Sources */, 205F0E121B371BD7007741D0 /* ASScrollDirection.m in Sources */,
9C8898BB1C738B9800D6B02E /* ASTextKitFontSizeAdjuster.mm in Sources */, 9C8898BB1C738B9800D6B02E /* ASTextKitFontSizeAdjuster.mm in Sources */,
D785F6631A74327E00291744 /* ASScrollNode.m in Sources */, D785F6631A74327E00291744 /* ASScrollNode.m in Sources */,
E5711A2E1C840C96009619D4 /* ASIndexedNodeContext.m in Sources */, E5711A2E1C840C96009619D4 /* ASIndexedNodeContext.mm in Sources */,
058D0A2C195D050800B7D73C /* ASSentinel.m in Sources */, 058D0A2C195D050800B7D73C /* ASSentinel.m in Sources */,
9C8221971BA237B80037F19A /* ASStackBaselinePositionedLayout.mm in Sources */, 9C8221971BA237B80037F19A /* ASStackBaselinePositionedLayout.mm in Sources */,
251B8EF81BBB3D690087C538 /* ASCollectionDataController.mm in Sources */, 251B8EF81BBB3D690087C538 /* ASCollectionDataController.mm in Sources */,
@@ -2213,7 +2213,7 @@
69E100701CA89CB600D88C1B /* ASEnvironmentInternal.mm in Sources */, 69E100701CA89CB600D88C1B /* ASEnvironmentInternal.mm in Sources */,
254C6B891BF94F8A003EC431 /* ASTextKitRenderer+Positioning.mm in Sources */, 254C6B891BF94F8A003EC431 /* ASTextKitRenderer+Positioning.mm in Sources */,
68355B341CB579B9001D4E68 /* ASImageNode+AnimatedImage.mm in Sources */, 68355B341CB579B9001D4E68 /* ASImageNode+AnimatedImage.mm in Sources */,
E5711A301C840C96009619D4 /* ASIndexedNodeContext.m in Sources */, E5711A301C840C96009619D4 /* ASIndexedNodeContext.mm in Sources */,
B35062511B010EFD0018CF92 /* ASDisplayNode+UIViewBridge.mm in Sources */, B35062511B010EFD0018CF92 /* ASDisplayNode+UIViewBridge.mm in Sources */,
B35061FC1B010EFD0018CF92 /* ASDisplayNode.mm in Sources */, B35061FC1B010EFD0018CF92 /* ASDisplayNode.mm in Sources */,
B35061FF1B010EFD0018CF92 /* ASDisplayNodeExtras.mm in Sources */, B35061FF1B010EFD0018CF92 /* ASDisplayNodeExtras.mm in Sources */,

View File

@@ -1248,9 +1248,6 @@ static bool disableNotificationsForMovingBetweenParents(ASDisplayNode *from, ASD
// This call will apply our .hierarchyState to the new subnode. // This call will apply our .hierarchyState to the new subnode.
// If we are a managed hierarchy, as in ASCellNode trees, it will also apply our .interfaceState. // If we are a managed hierarchy, as in ASCellNode trees, it will also apply our .interfaceState.
[subnode __setSupernode:self]; [subnode __setSupernode:self];
// propagate our traits to the child we are about to add.
ASEnvironmentStatePropagateDown(subnode, [self environmentTraitCollection]);
if (self.nodeLoaded) { if (self.nodeLoaded) {
// If this node has a view or layer, force the subnode to also create its view or layer and add it to the hierarchy here. // If this node has a view or layer, force the subnode to also create its view or layer and add it to the hierarchy here.
@@ -1298,9 +1295,6 @@ static bool disableNotificationsForMovingBetweenParents(ASDisplayNode *from, ASD
[_subnodes insertObject:subnode atIndex:subnodeIndex]; [_subnodes insertObject:subnode atIndex:subnodeIndex];
[subnode __setSupernode:self]; [subnode __setSupernode:self];
// propagate our traits to the child we are about to add.
ASEnvironmentStatePropagateDown(subnode, [self environmentTraitCollection]);
// Don't bother inserting the view/layer if in a rasterized subtree, because there are no layers in the hierarchy and none of this could possibly work. // Don't bother inserting the view/layer if in a rasterized subtree, because there are no layers in the hierarchy and none of this could possibly work.
if (!_flags.shouldRasterizeDescendants && [self __shouldLoadViewOrLayer]) { if (!_flags.shouldRasterizeDescendants && [self __shouldLoadViewOrLayer]) {
if (_layer) { if (_layer) {
@@ -1742,6 +1736,9 @@ static NSInteger incrementIfFound(NSInteger i) {
[self exitHierarchyState:stateToEnterOrExit]; [self exitHierarchyState:stateToEnterOrExit];
} }
// now that we have a supernode, propagate its traits to self.
ASEnvironmentStatePropagateDown(self, [newSupernode environmentTraitCollection]);
} }
} }
@@ -2725,12 +2722,12 @@ static const char *ASDisplayNodeDrawingPriorityKey = "ASDrawingPriority";
- (ASEnvironmentTraitCollection)environmentTraitCollection - (ASEnvironmentTraitCollection)environmentTraitCollection
{ {
return _environmentState.traitCollection; return _environmentState.environmentTraitCollection;
} }
- (void)setEnvironmentTraitCollection:(ASEnvironmentTraitCollection)environmentTraitCollection - (void)setEnvironmentTraitCollection:(ASEnvironmentTraitCollection)environmentTraitCollection
{ {
_environmentState.traitCollection = environmentTraitCollection; _environmentState.environmentTraitCollection = environmentTraitCollection;
} }
ASEnvironmentLayoutOptionsForwarding ASEnvironmentLayoutOptionsForwarding
@@ -2739,7 +2736,7 @@ ASEnvironmentLayoutExtensibilityForwarding
- (ASTraitCollection *)asyncTraitCollection - (ASTraitCollection *)asyncTraitCollection
{ {
ASDN::MutexLocker l(_propertyLock); ASDN::MutexLocker l(_propertyLock);
return [ASTraitCollection traitCollectionWithASEnvironmentTraitCollection:_environmentState.traitCollection]; return [ASTraitCollection traitCollectionWithASEnvironmentTraitCollection:self.environmentTraitCollection];
} }
#if TARGET_OS_TV #if TARGET_OS_TV

View File

@@ -61,7 +61,7 @@
// Since the VC holds the only strong reference to this context and we are in the process of destroying // Since the VC holds the only strong reference to this context and we are in the process of destroying
// the VC, all the references in the subnodes will be unsafe unless we nil them out. More than likely all the subnodes will be dealloc'ed // the VC, all the references in the subnodes will be unsafe unless we nil them out. More than likely all the subnodes will be dealloc'ed
// as part of the VC being dealloc'ed, but this is just to make extra sure. // as part of the VC being dealloc'ed, but this is just to make extra sure.
self.traitColectionContext = nil; self.traitCollectionContext = nil;
} }
} }
@@ -87,8 +87,8 @@
// ensure that self.node has a valid trait collection before a subclass's implementation of viewDidLoad. // ensure that self.node has a valid trait collection before a subclass's implementation of viewDidLoad.
// Any subnodes added in viewDidLoad will then inherit the proper environment. // Any subnodes added in viewDidLoad will then inherit the proper environment.
if (AS_AT_LEAST_IOS8) { if (AS_AT_LEAST_IOS8) {
ASEnvironmentTraitCollection traitCollection = [self displayTraitsForTraitCollection:self.traitCollection]; ASEnvironmentTraitCollection traitCollection = [self environmentTraitCollectionForUITraitCollection:self.traitCollection];
[self progagateNewDisplayTraits:traitCollection]; [self progagateNewEnvironmentTraitCollection:traitCollection];
} }
} }
@@ -195,7 +195,7 @@ ASVisibilityDepthImplementation;
#pragma mark - ASEnvironmentTraitCollection #pragma mark - ASEnvironmentTraitCollection
- (void)setTraitColectionContext:(id)traitCollectionContext - (void)setTraitCollectionContext:(id)traitCollectionContext
{ {
if (_traitCollectionContext != traitCollectionContext) { if (_traitCollectionContext != traitCollectionContext) {
// nil out the displayContext in the subnodes so they aren't hanging around with a dealloc'ed pointer don't set // nil out the displayContext in the subnodes so they aren't hanging around with a dealloc'ed pointer don't set
@@ -206,11 +206,11 @@ ASVisibilityDepthImplementation;
} }
} }
- (ASEnvironmentTraitCollection)displayTraitsForTraitCollection:(UITraitCollection *)traitCollection - (ASEnvironmentTraitCollection)environmentTraitCollectionForUITraitCollection:(UITraitCollection *)traitCollection
{ {
if (self.overrideDisplayTraitsWithTraitCollection) { if (self.overrideDisplayTraitsWithTraitCollection) {
ASTraitCollection *asyncTraitCollection = self.overrideDisplayTraitsWithTraitCollection(traitCollection); ASTraitCollection *asyncTraitCollection = self.overrideDisplayTraitsWithTraitCollection(traitCollection);
self.traitColectionContext = asyncTraitCollection.traitCollectionContext; self.traitCollectionContext = asyncTraitCollection.traitCollectionContext;
return [asyncTraitCollection environmentTraitCollection]; return [asyncTraitCollection environmentTraitCollection];
} }
@@ -219,29 +219,29 @@ ASVisibilityDepthImplementation;
return asyncTraitCollection; return asyncTraitCollection;
} }
- (ASEnvironmentTraitCollection)displayTraitsForWindowSize:(CGSize)windowSize - (ASEnvironmentTraitCollection)environmentTraitCollectionForWindowSize:(CGSize)windowSize
{ {
if (self.overrideDisplayTraitsWithWindowSize) { if (self.overrideDisplayTraitsWithWindowSize) {
ASTraitCollection *traitCollection = self.overrideDisplayTraitsWithWindowSize(windowSize); ASTraitCollection *traitCollection = self.overrideDisplayTraitsWithWindowSize(windowSize);
self.traitColectionContext = traitCollection.traitCollectionContext; self.traitCollectionContext = traitCollection.traitCollectionContext;
return [traitCollection environmentTraitCollection]; return [traitCollection environmentTraitCollection];
} }
return self.node.environmentTraitCollection; return self.node.environmentTraitCollection;
} }
- (void)progagateNewDisplayTraits:(ASEnvironmentTraitCollection)traitCollection - (void)progagateNewEnvironmentTraitCollection:(ASEnvironmentTraitCollection)environmentTraitCollection
{ {
ASEnvironmentState environmentState = self.node.environmentState; ASEnvironmentState environmentState = self.node.environmentState;
ASEnvironmentTraitCollection oldTraitCollection = environmentState.traitCollection; ASEnvironmentTraitCollection oldEnvironmentTraitCollection = environmentState.environmentTraitCollection;
if (ASEnvironmentTraitCollectionIsEqualToASEnvironmentTraitCollection(traitCollection, oldTraitCollection) == NO) { if (ASEnvironmentTraitCollectionIsEqualToASEnvironmentTraitCollection(environmentTraitCollection, oldEnvironmentTraitCollection) == NO) {
environmentState.traitCollection = traitCollection; environmentState.environmentTraitCollection = environmentTraitCollection;
self.node.environmentState = environmentState; self.node.environmentState = environmentState;
[self.node setNeedsLayout]; [self.node setNeedsLayout];
NSArray<id<ASEnvironment>> *children = [self.node children]; NSArray<id<ASEnvironment>> *children = [self.node children];
for (id<ASEnvironment> child in children) { for (id<ASEnvironment> child in children) {
ASEnvironmentStatePropagateDown(child, environmentState.traitCollection); ASEnvironmentStatePropagateDown(child, environmentState.environmentTraitCollection);
} }
} }
} }
@@ -250,24 +250,24 @@ ASVisibilityDepthImplementation;
{ {
[super traitCollectionDidChange:previousTraitCollection]; [super traitCollectionDidChange:previousTraitCollection];
ASEnvironmentTraitCollection traitCollection = [self displayTraitsForTraitCollection:self.traitCollection]; ASEnvironmentTraitCollection environmentTraitCollection = [self environmentTraitCollectionForUITraitCollection:self.traitCollection];
[self progagateNewDisplayTraits:traitCollection]; [self progagateNewEnvironmentTraitCollection:environmentTraitCollection];
} }
- (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator - (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{ {
[super willTransitionToTraitCollection:newCollection withTransitionCoordinator:coordinator]; [super willTransitionToTraitCollection:newCollection withTransitionCoordinator:coordinator];
ASEnvironmentTraitCollection traitCollection = [self displayTraitsForTraitCollection:newCollection]; ASEnvironmentTraitCollection environmentTraitCollection = [self environmentTraitCollectionForUITraitCollection:newCollection];
[self progagateNewDisplayTraits:traitCollection]; [self progagateNewEnvironmentTraitCollection:environmentTraitCollection];
} }
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{ {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
ASEnvironmentTraitCollection traitCollection = [self displayTraitsForWindowSize:size]; ASEnvironmentTraitCollection environmentTraitCollection = [self environmentTraitCollectionForWindowSize:size];
[self progagateNewDisplayTraits:traitCollection]; [self progagateNewEnvironmentTraitCollection:environmentTraitCollection];
} }
@end @end

View File

@@ -158,6 +158,9 @@
- (void)_populateSupplementaryNodesOfKind:(NSString *)kind withMutableContexts:(NSMutableArray<ASIndexedNodeContext *> *)contexts - (void)_populateSupplementaryNodesOfKind:(NSString *)kind withMutableContexts:(NSMutableArray<ASIndexedNodeContext *> *)contexts
{ {
id<ASEnvironment> environment = [self.environmentDelegate dataControllerEnvironment];
ASEnvironmentTraitCollection environmentTraitCollection = environment.environmentTraitCollection;
NSUInteger sectionCount = [self.collectionDataSource dataController:self numberOfSectionsForSupplementaryNodeOfKind:kind]; NSUInteger sectionCount = [self.collectionDataSource dataController:self numberOfSectionsForSupplementaryNodeOfKind:kind];
for (NSUInteger i = 0; i < sectionCount; i++) { for (NSUInteger i = 0; i < sectionCount; i++) {
NSIndexPath *sectionIndexPath = [[NSIndexPath alloc] initWithIndex:i]; NSIndexPath *sectionIndexPath = [[NSIndexPath alloc] initWithIndex:i];
@@ -176,7 +179,8 @@
ASSizeRange constrainedSize = [self constrainedSizeForNodeOfKind:kind atIndexPath:indexPath]; ASSizeRange constrainedSize = [self constrainedSizeForNodeOfKind:kind atIndexPath:indexPath];
ASIndexedNodeContext *context = [[ASIndexedNodeContext alloc] initWithNodeBlock:supplementaryCellBlock ASIndexedNodeContext *context = [[ASIndexedNodeContext alloc] initWithNodeBlock:supplementaryCellBlock
indexPath:indexPath indexPath:indexPath
constrainedSize:constrainedSize]; constrainedSize:constrainedSize
environmentTraitCollection:environmentTraitCollection];
[contexts addObject:context]; [contexts addObject:context];
} }
} }
@@ -184,6 +188,9 @@
- (void)_populateSupplementaryNodesOfKind:(NSString *)kind withSections:(NSIndexSet *)sections mutableContexts:(NSMutableArray<ASIndexedNodeContext *> *)contexts - (void)_populateSupplementaryNodesOfKind:(NSString *)kind withSections:(NSIndexSet *)sections mutableContexts:(NSMutableArray<ASIndexedNodeContext *> *)contexts
{ {
id<ASEnvironment> environment = [self.environmentDelegate dataControllerEnvironment];
ASEnvironmentTraitCollection environmentTraitCollection = environment.environmentTraitCollection;
[sections enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) { [sections enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
NSUInteger rowNum = [self.collectionDataSource dataController:self supplementaryNodesOfKind:kind inSection:idx]; NSUInteger rowNum = [self.collectionDataSource dataController:self supplementaryNodesOfKind:kind inSection:idx];
NSIndexPath *sectionIndex = [[NSIndexPath alloc] initWithIndex:idx]; NSIndexPath *sectionIndex = [[NSIndexPath alloc] initWithIndex:idx];
@@ -201,7 +208,8 @@
ASSizeRange constrainedSize = [self constrainedSizeForNodeOfKind:kind atIndexPath:indexPath]; ASSizeRange constrainedSize = [self constrainedSizeForNodeOfKind:kind atIndexPath:indexPath];
ASIndexedNodeContext *context = [[ASIndexedNodeContext alloc] initWithNodeBlock:supplementaryCellBlock ASIndexedNodeContext *context = [[ASIndexedNodeContext alloc] initWithNodeBlock:supplementaryCellBlock
indexPath:indexPath indexPath:indexPath
constrainedSize:constrainedSize]; constrainedSize:constrainedSize
environmentTraitCollection:environmentTraitCollection];
[contexts addObject:context]; [contexts addObject:context];
} }
}]; }];

View File

@@ -514,22 +514,14 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
} }
} }
- (ASCellNodeBlock)nodeBlockPropagatingTraitCollectionFromNodeBlock:(ASCellNodeBlock)nodeBlock
{
// When creating a node, make sure to pass along the current display traits so it will be laid out properly
return ^{
ASCellNode *cellNode = nodeBlock();
id<ASEnvironment> environment = [self.environmentDelegate dataControllerEnvironment];
ASEnvironmentStatePropagateDown(cellNode, [environment environmentTraitCollection]);
return cellNode;
};
}
/** /**
* Fetches row contexts for the provided sections from the data source. * Fetches row contexts for the provided sections from the data source.
*/ */
- (NSArray<ASIndexedNodeContext *> *)_populateFromDataSourceWithSectionIndexSet:(NSIndexSet *)indexSet - (NSArray<ASIndexedNodeContext *> *)_populateFromDataSourceWithSectionIndexSet:(NSIndexSet *)indexSet
{ {
id<ASEnvironment> environment = [self.environmentDelegate dataControllerEnvironment];
ASEnvironmentTraitCollection environmentTraitCollection = environment.environmentTraitCollection;
NSMutableArray<ASIndexedNodeContext *> *contexts = [NSMutableArray array]; NSMutableArray<ASIndexedNodeContext *> *contexts = [NSMutableArray array];
[indexSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) { [indexSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
NSUInteger rowNum = [_dataSource dataController:self rowsInSection:idx]; NSUInteger rowNum = [_dataSource dataController:self rowsInSection:idx];
@@ -539,9 +531,10 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
ASCellNodeBlock nodeBlock = [_dataSource dataController:self nodeBlockAtIndexPath:indexPath]; ASCellNodeBlock nodeBlock = [_dataSource dataController:self nodeBlockAtIndexPath:indexPath];
ASSizeRange constrainedSize = [self constrainedSizeForNodeOfKind:ASDataControllerRowNodeKind atIndexPath:indexPath]; ASSizeRange constrainedSize = [self constrainedSizeForNodeOfKind:ASDataControllerRowNodeKind atIndexPath:indexPath];
[contexts addObject:[[ASIndexedNodeContext alloc] initWithNodeBlock:[self nodeBlockPropagatingTraitCollectionFromNodeBlock:nodeBlock] [contexts addObject:[[ASIndexedNodeContext alloc] initWithNodeBlock:nodeBlock
indexPath:indexPath indexPath:indexPath
constrainedSize:constrainedSize]]; constrainedSize:constrainedSize
environmentTraitCollection:environmentTraitCollection]];
} }
}]; }];
return contexts; return contexts;
@@ -794,12 +787,16 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
NSMutableArray<ASIndexedNodeContext *> *contexts = [[NSMutableArray alloc] initWithCapacity:indexPaths.count]; NSMutableArray<ASIndexedNodeContext *> *contexts = [[NSMutableArray alloc] initWithCapacity:indexPaths.count];
[self accessDataSourceWithBlock:^{ [self accessDataSourceWithBlock:^{
id<ASEnvironment> environment = [self.environmentDelegate dataControllerEnvironment];
ASEnvironmentTraitCollection environmentTraitCollection = environment.environmentTraitCollection;
for (NSIndexPath *indexPath in sortedIndexPaths) { for (NSIndexPath *indexPath in sortedIndexPaths) {
ASCellNodeBlock nodeBlock = [_dataSource dataController:self nodeBlockAtIndexPath:indexPath]; ASCellNodeBlock nodeBlock = [_dataSource dataController:self nodeBlockAtIndexPath:indexPath];
ASSizeRange constrainedSize = [self constrainedSizeForNodeOfKind:ASDataControllerRowNodeKind atIndexPath:indexPath]; ASSizeRange constrainedSize = [self constrainedSizeForNodeOfKind:ASDataControllerRowNodeKind atIndexPath:indexPath];
[contexts addObject:[[ASIndexedNodeContext alloc] initWithNodeBlock:[self nodeBlockPropagatingTraitCollectionFromNodeBlock:nodeBlock] [contexts addObject:[[ASIndexedNodeContext alloc] initWithNodeBlock:nodeBlock
indexPath:indexPath indexPath:indexPath
constrainedSize:constrainedSize]]; constrainedSize:constrainedSize
environmentTraitCollection:environmentTraitCollection]];
} }
[_editingTransactionQueue addOperationWithBlock:^{ [_editingTransactionQueue addOperationWithBlock:^{
@@ -845,12 +842,16 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
// FIXME: Shouldn't deletes be sorted in descending order? // FIXME: Shouldn't deletes be sorted in descending order?
[indexPaths sortedArrayUsingSelector:@selector(compare:)]; [indexPaths sortedArrayUsingSelector:@selector(compare:)];
id<ASEnvironment> environment = [self.environmentDelegate dataControllerEnvironment];
ASEnvironmentTraitCollection environmentTraitCollection = environment.environmentTraitCollection;
for (NSIndexPath *indexPath in indexPaths) { for (NSIndexPath *indexPath in indexPaths) {
ASCellNodeBlock nodeBlock = [_dataSource dataController:self nodeBlockAtIndexPath:indexPath]; ASCellNodeBlock nodeBlock = [_dataSource dataController:self nodeBlockAtIndexPath:indexPath];
ASSizeRange constrainedSize = [self constrainedSizeForNodeOfKind:ASDataControllerRowNodeKind atIndexPath:indexPath]; ASSizeRange constrainedSize = [self constrainedSizeForNodeOfKind:ASDataControllerRowNodeKind atIndexPath:indexPath];
[contexts addObject:[[ASIndexedNodeContext alloc] initWithNodeBlock:[self nodeBlockPropagatingTraitCollectionFromNodeBlock:nodeBlock] [contexts addObject:[[ASIndexedNodeContext alloc] initWithNodeBlock:nodeBlock
indexPath:indexPath indexPath:indexPath
constrainedSize:constrainedSize]]; constrainedSize:constrainedSize
environmentTraitCollection:environmentTraitCollection]];
} }
[_editingTransactionQueue addOperationWithBlock:^{ [_editingTransactionQueue addOperationWithBlock:^{

View File

@@ -97,7 +97,7 @@ extern BOOL ASEnvironmentTraitCollectionIsEqualToASEnvironmentTraitCollection(AS
typedef struct ASEnvironmentState { typedef struct ASEnvironmentState {
struct ASEnvironmentHierarchyState hierarchyState; struct ASEnvironmentHierarchyState hierarchyState;
struct ASEnvironmentLayoutOptionsState layoutOptionsState; struct ASEnvironmentLayoutOptionsState layoutOptionsState;
struct ASEnvironmentTraitCollection traitCollection; struct ASEnvironmentTraitCollection environmentTraitCollection;
} ASEnvironmentState; } ASEnvironmentState;
extern ASEnvironmentState ASEnvironmentStateMakeDefault(); extern ASEnvironmentState ASEnvironmentStateMakeDefault();
@@ -152,9 +152,9 @@ ASDISPLAYNODE_EXTERN_C_END
- (void)setEnvironmentState:(ASEnvironmentState)environmentState\ - (void)setEnvironmentState:(ASEnvironmentState)environmentState\
{\ {\
ASDN::MutexLocker l(lock);\ ASDN::MutexLocker l(lock);\
ASEnvironmentTraitCollection oldTraits = self.environmentState.traitCollection;\ ASEnvironmentTraitCollection oldTraits = self.environmentState.environmentTraitCollection;\
[super setEnvironmentState:environmentState];\ [super setEnvironmentState:environmentState];\
ASEnvironmentTraitCollection currentTraits = environmentState.traitCollection;\ ASEnvironmentTraitCollection currentTraits = environmentState.environmentTraitCollection;\
if (ASEnvironmentTraitCollectionIsEqualToASEnvironmentTraitCollection(currentTraits, oldTraits) == NO) {\ if (ASEnvironmentTraitCollectionIsEqualToASEnvironmentTraitCollection(currentTraits, oldTraits) == NO) {\
dispatch_async(dispatch_get_main_queue(), ^{\ dispatch_async(dispatch_get_main_queue(), ^{\
NSArray<NSArray <ASCellNode *> *> *completedNodes = [self.view.dataController completedNodes];\ NSArray<NSArray <ASCellNode *> *> *completedNodes = [self.view.dataController completedNodes];\

View File

@@ -29,13 +29,13 @@ ASEnvironmentHierarchyState _ASEnvironmentHierarchyStateMakeDefault()
extern void ASEnvironmentTraitCollectionUpdateDisplayContext(id<ASEnvironment> rootEnvironment, id context) extern void ASEnvironmentTraitCollectionUpdateDisplayContext(id<ASEnvironment> rootEnvironment, id context)
{ {
ASEnvironmentState envState = [rootEnvironment environmentState]; ASEnvironmentState envState = [rootEnvironment environmentState];
ASEnvironmentTraitCollection displayTraits = envState.traitCollection; ASEnvironmentTraitCollection environmentTraitCollection = envState.environmentTraitCollection;
displayTraits.displayContext = context; environmentTraitCollection.displayContext = context;
envState.traitCollection = displayTraits; envState.environmentTraitCollection = environmentTraitCollection;
[rootEnvironment setEnvironmentState:envState]; [rootEnvironment setEnvironmentState:envState];
for (id<ASEnvironment> child in [rootEnvironment children]) { for (id<ASEnvironment> child in [rootEnvironment children]) {
ASEnvironmentStatePropagateDown(child, displayTraits); ASEnvironmentStatePropagateDown(child, environmentTraitCollection);
} }
} }
@@ -77,7 +77,7 @@ ASEnvironmentState ASEnvironmentStateMakeDefault()
return (ASEnvironmentState) { return (ASEnvironmentState) {
.layoutOptionsState = _ASEnvironmentLayoutOptionsStateMakeDefault(), .layoutOptionsState = _ASEnvironmentLayoutOptionsStateMakeDefault(),
.hierarchyState = _ASEnvironmentHierarchyStateMakeDefault(), .hierarchyState = _ASEnvironmentHierarchyStateMakeDefault(),
.traitCollection = _ASEnvironmentTraitCollectionMakeDefault() .environmentTraitCollection = _ASEnvironmentTraitCollectionMakeDefault()
}; };
} }

View File

@@ -7,15 +7,18 @@
// //
#import <AsyncDisplayKit/ASDataController.h> #import <AsyncDisplayKit/ASDataController.h>
#import <AsyncDisplayKit/ASEnvironment.h>
@interface ASIndexedNodeContext : NSObject @interface ASIndexedNodeContext : NSObject
@property (nonatomic, readonly, strong) NSIndexPath *indexPath; @property (nonatomic, readonly, strong) NSIndexPath *indexPath;
@property (nonatomic, readonly, assign) ASSizeRange constrainedSize; @property (nonatomic, readonly, assign) ASSizeRange constrainedSize;
@property (nonatomic, readonly, assign) ASEnvironmentTraitCollection environmentTraitCollection;
- (instancetype)initWithNodeBlock:(ASCellNodeBlock)nodeBlock - (instancetype)initWithNodeBlock:(ASCellNodeBlock)nodeBlock
indexPath:(NSIndexPath *)indexPath indexPath:(NSIndexPath *)indexPath
constrainedSize:(ASSizeRange)constrainedSize; constrainedSize:(ASSizeRange)constrainedSize
environmentTraitCollection:(ASEnvironmentTraitCollection)environmentTraitCollection;
/** /**
* Returns a node allocated by executing node block. Node block will be nil out immediately. * Returns a node allocated by executing node block. Node block will be nil out immediately.

View File

@@ -7,6 +7,8 @@
// //
#import "ASIndexedNodeContext.h" #import "ASIndexedNodeContext.h"
#import "ASEnvironmentInternal.h"
#import "ASCellNode.h"
@interface ASIndexedNodeContext () @interface ASIndexedNodeContext ()
@@ -19,7 +21,8 @@
- (instancetype)initWithNodeBlock:(ASCellNodeBlock)nodeBlock - (instancetype)initWithNodeBlock:(ASCellNodeBlock)nodeBlock
indexPath:(NSIndexPath *)indexPath indexPath:(NSIndexPath *)indexPath
constrainedSize:(ASSizeRange)constrainedSize; constrainedSize:(ASSizeRange)constrainedSize
environmentTraitCollection:(ASEnvironmentTraitCollection)environmentTraitCollection
{ {
NSAssert(nodeBlock != nil && indexPath != nil, @"Node block and index path must not be nil"); NSAssert(nodeBlock != nil && indexPath != nil, @"Node block and index path must not be nil");
self = [super init]; self = [super init];
@@ -27,6 +30,7 @@
_nodeBlock = nodeBlock; _nodeBlock = nodeBlock;
_indexPath = indexPath; _indexPath = indexPath;
_constrainedSize = constrainedSize; _constrainedSize = constrainedSize;
_environmentTraitCollection = environmentTraitCollection;
} }
return self; return self;
} }
@@ -36,6 +40,7 @@
NSAssert(_nodeBlock != nil, @"Node block is gone. Should not execute it more than once"); NSAssert(_nodeBlock != nil, @"Node block is gone. Should not execute it more than once");
ASCellNode *node = _nodeBlock(); ASCellNode *node = _nodeBlock();
_nodeBlock = nil; _nodeBlock = nil;
ASEnvironmentStatePropagateDown(node, _environmentTraitCollection);
return node; return node;
} }

View File

@@ -28,7 +28,7 @@
* Be aware that internally this context is held by a C struct which cannot retain the pointer. * Be aware that internally this context is held by a C struct which cannot retain the pointer.
* ASTraitCollection is generally a very short-lived class, existing only to provide a non-struct API * ASTraitCollection is generally a very short-lived class, existing only to provide a non-struct API
* to trait collections. When an ASTraitCollection is returned via one of ASViewController's 2 * to trait collections. When an ASTraitCollection is returned via one of ASViewController's 2
* custom trait collection creation blocks, traitColectionContext is assigned to the VC's traitColectionContext. * custom trait collection creation blocks, traitCollectionContext is assigned to the VC's traitCollectionContext.
* This makes sure that the VC is the owner of the context and ASEnvironmentTraitCollections will not * This makes sure that the VC is the owner of the context and ASEnvironmentTraitCollections will not
* have a reference to a dangling pointer. * have a reference to a dangling pointer.
*/ */

View File

@@ -214,12 +214,12 @@
- (ASEnvironmentTraitCollection)environmentTraitCollection - (ASEnvironmentTraitCollection)environmentTraitCollection
{ {
return _environmentState.traitCollection; return _environmentState.environmentTraitCollection;
} }
- (void)setEnvironmentTraitCollection:(ASEnvironmentTraitCollection)traitCollection - (void)setEnvironmentTraitCollection:(ASEnvironmentTraitCollection)environmentTraitCollection
{ {
_environmentState.traitCollection = traitCollection; _environmentState.environmentTraitCollection = environmentTraitCollection;
} }
ASEnvironmentLayoutOptionsForwarding ASEnvironmentLayoutOptionsForwarding
@@ -228,7 +228,7 @@ ASEnvironmentLayoutExtensibilityForwarding
- (ASTraitCollection *)asyncTraitCollection - (ASTraitCollection *)asyncTraitCollection
{ {
ASDN::MutexLocker l(_propertyLock); ASDN::MutexLocker l(_propertyLock);
return [ASTraitCollection traitCollectionWithASEnvironmentTraitCollection:_environmentState.traitCollection]; return [ASTraitCollection traitCollectionWithASEnvironmentTraitCollection:self.environmentTraitCollection];
} }
@end @end

View File

@@ -201,14 +201,14 @@ ASEnvironmentState ASEnvironmentMergeObjectAndState(ASEnvironmentState childEnvi
// Support propagate down // Support propagate down
if (propagation == ASEnvironmentStatePropagation::DOWN) { if (propagation == ASEnvironmentStatePropagation::DOWN) {
ASEnvironmentTraitCollection childTraitCollection = childEnvironmentState.traitCollection; ASEnvironmentTraitCollection childTraitCollection = childEnvironmentState.environmentTraitCollection;
childTraitCollection.horizontalSizeClass = parentTraitCollection.horizontalSizeClass; childTraitCollection.horizontalSizeClass = parentTraitCollection.horizontalSizeClass;
childTraitCollection.verticalSizeClass = parentTraitCollection.verticalSizeClass; childTraitCollection.verticalSizeClass = parentTraitCollection.verticalSizeClass;
childTraitCollection.userInterfaceIdiom = parentTraitCollection.userInterfaceIdiom; childTraitCollection.userInterfaceIdiom = parentTraitCollection.userInterfaceIdiom;
childTraitCollection.forceTouchCapability = parentTraitCollection.forceTouchCapability; childTraitCollection.forceTouchCapability = parentTraitCollection.forceTouchCapability;
childTraitCollection.displayScale = parentTraitCollection.displayScale; childTraitCollection.displayScale = parentTraitCollection.displayScale;
childTraitCollection.displayContext = parentTraitCollection.displayContext; childTraitCollection.displayContext = parentTraitCollection.displayContext;
childEnvironmentState.traitCollection = childTraitCollection; childEnvironmentState.environmentTraitCollection = childTraitCollection;
} }
return childEnvironmentState; return childEnvironmentState;