Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inserting a sublayer in an index of NSNotFound #80

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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