This repository was 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
Open
crleona wants to merge 1 commit intoLinkedInAttic:masterfrom
Open
Allow embedding layouts in a view hierarchy created from another layout#245crleona wants to merge 1 commit intoLinkedInAttic:masterfrom
crleona wants to merge 1 commit intoLinkedInAttic:masterfrom
Conversation
Biinngg
reviewed
Jan 16, 2019
| func walkSubviews(visitor: (View) -> Void) { | ||
| for subview in subviews { | ||
| func walkNonRootSubviews(visitor: (View) -> Void) { | ||
| for subview in subviews where subview.type != .root { |
There was a problem hiding this comment.
Is it necessary to walk unmanaged subviews? Won't the subviews of the subview be either unmanaged or root ones?
Contributor
There was a problem hiding this comment.
This is a good point. Let's tackle it as a separate change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
isLayoutKitRootproperty from the root view, and this would have no effect on view hierarchies created frommakeViewswith a nil view. (Theoretically, a view hierarchy created without a parent then added to a parent view should still allow view recycling ifmakeViewsis 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
makeViewsbelong 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.