This repository has been archived by the owner on Feb 17, 2021. It is now read-only.
Allow embedding layouts in a view hierarchy created from another layout #245
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I ended up getting two approaches for this working:
The first marks whichever view is hosting the layout as a layout kit root, and blocks the view recycler from examining the subviews of any view marked similarly. The code for this is much simpler, but there's no way to clean up an
isLayoutKitRoot
property from the root view, and this would have no effect on view hierarchies created frommakeViews
with a nil view. (Theoretically, a view hierarchy created without a parent then added to a parent view should still allow view recycling ifmakeViews
is called again with the new parent).The second, implemented here, would be to mark the top level views a layout generates as roots. This should resolve the issues the first approach had at the cost of some additional complexity. It makes the assumption that all direct subviews marked as root of a parent view passed in to
makeViews
belong to that layout or should be removed, but that should be consistent with the existing behavior of ViewRecycler. I'm at a loss as to what the automatically created container view for a parentless layout with multiple views should be marked as, but I think leaving it as is will match the current behavior.There's also a small bug fix for associated objects - namely, they should be stored as copy, nonatomic.