Skip to content

Commit

Permalink
Fix inserting a sublayer in an index of NSNotFound
Browse files Browse the repository at this point in the history
  • Loading branch information
maicki committed Apr 27, 2017
1 parent 6f82d0f commit f3badff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
- Add support for IGListKit post-removal-of-IGListSectionType, in preparation for IGListKit 3.0.0 release. (Adlai-Holler)[https://github.com/Adlai-Holler] (#49)[https://github.com/TextureGroup/Texture/pull/49]
- Fix `__has_include` check in ASLog.h [Philipp Smorygo](Philipp.Smorygo@jetbrains.com)
- Fix potential deadlock in ASControlNode [Garrett Moon](https://github.com/garrettmoon)
- [Yoga Beta] Improvements to the experimental support for Yoga layout [Scott Goodson](appleguy)
- [Yoga Beta] Improvements to the experimental support for Yoga layout [Scott Goodson](appleguy)
- Fix inserting a sublayer in an index of NSNotFound (Michael Schneider)[https://github.com/maicki] (#80)(https://github.com/TextureGroup/Texture/pull/80)
18 changes: 18 additions & 0 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2767,6 +2767,8 @@ - (void)_insertSubnode:(ASDisplayNode *)subnode atSubnodeIndex:(NSInteger)subnod
_subnodes = [[NSMutableArray alloc] init];
}
[_subnodes insertObject:subnode atIndex:subnodeIndex];

BOOL nodeWasLoaded = [self _locked_isNodeLoaded];
__instanceLock__.unlock();

// This call will apply our .hierarchyState to the new subnode.
Expand All @@ -2786,6 +2788,22 @@ - (void)_insertSubnode:(ASDisplayNode *)subnode atSubnodeIndex:(NSInteger)subnod
}
} else if (self.nodeLoaded) {
// If not rasterizing, and node is loaded insert the subview/sublayer now.

if (nodeWasLoaded == NO && sublayerIndex == NSNotFound) {
// In this case the node was loaded while setting the _setSupernode. We have to grab the sublayer index again
__instanceLock__.lock();
NSInteger idx = [_subnodes indexOfObjectIdenticalTo:subnode];
if (_layer && idx == 0) {
sublayerIndex = 0;
} else if (_layer) {
ASDisplayNode *positionInRelationTo = (_subnodes.count > 0 && idx > 0) ? _subnodes[idx - 1] : nil;
if (positionInRelationTo) {
sublayerIndex = incrementIfFound([_layer.sublayers indexOfObjectIdenticalTo:positionInRelationTo.layer]);
}
}
__instanceLock__.unlock();
}

[self _insertSubnodeSubviewOrSublayer:subnode atIndex:sublayerIndex];
} // Otherwise we will insert subview/sublayer when we get loaded

Expand Down

0 comments on commit f3badff

Please sign in to comment.