Removal of AnyView from SwiftUI implementation #76
Unanswered
Tyler-Keith-Thompson
asked this question in
Ideas
Replies: 1 comment 3 replies
-
|
👏 👏 👏 Great post, @Tyler-Keith-Thompson . This is way more detailed than I was hoping for and every bit of it is appreciated.
I don't think you are working too hard to avoid it. I personally dislike the idea of adding a
This is also fine. If things are not clear from the code and commits, we'll be sure to ask lots of questions in the PR. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
AnyView(started a branch calleddie-anyview-dieEmptyViewas a necessityonLoadto a more appropriate place so that SwiftUI does not even try to render a view unless it's the correct viewMotivation
Apple has spoken before (most recently at WWDC2021) about how
AnyViewstops some of the SwiftUI optimizations they put in place. It can hinder animations and it generally gets in the way of performance. By removing our requirement for it we're getting a lot closer to a pure SwiftUI experience that follows best practices and acts very similarly to what a user would create without the library.A note on SwiftUI:
Changing the state of a view while that view is rendering causes issues and is not a supported approach, for example:
Design Approach
WorkflowViewModelso that it's published body is simply anAny?ModifiedContentand make aModfiedWorkflowView<Args, Wrapped: View, Content: View>thenProceed(with: WorkflowItem(FR1.self))it returns aModifiedWorkflowView<FR1.WorkflowInput, Never, FR1>thenProceed(with: WorkflowItem(FR2.self))it returnsModifiedWorkflowView<FR2.WorkflowInput, ModifiedWorkflowView<FR1.WorkflowInput, Never, FR1>, FR2>thenProceed(with: WorkflowItem(FR3.self).applyModifiers { $0.frame(width: 100) })it creates aModifiedWorkflowView<FR3.WorkflowInput, ModifiedWorkflowView<FR2.WorkflowInput, ModifiedWorkflowView<FR1.WorkflowInput, Never, FR1>, FR2>, ModifiedContent<_FrameLayout, FR3>>model.bodychanges, the views update.Things that went funny during the initial spike
Workflowhad 2 of the same item, then they both displayedonLoadis not preferable for a whole host of reasons, most of which are recursive...as in recursion is the problem AND as in solving part of the problem recurses and gets you more problems.Affect on Public API
.launch()that told it expressly to get started by I'm working very hard to avoid that (possibly too hard?)Affect on animations
ifstatement, so you don't need to wrapif truearound everything. I think theAnyViewwas actually causing weirdness there.Potential Affect on Future Direction
ViewInspectorbecause you don't have to trigger lifecycle events, that's quite nice.Notes:
Beta Was this translation helpful? Give feedback.
All reactions