-
Notifications
You must be signed in to change notification settings - Fork 0
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
Musings on how to make it easier to control the flow of data for updating your UI #39
Comments
Ignoring settings colors and non views/constraints, one possible direction is to build if statements into the layout: ViewLayout(view: self.view) { (com) in
com.stackView { (com) in
com.if(/*some condition*/) { (com) in
com.arrangedView(self.myView) { (com) in
...
}
}.elseif(/*some condition*/) { (com) in
...
}.else(/*some condition*/) { (com) in
...
}
}
} One part of this is that you'd no longer be explicitly calling to update your layout. You're describing it here. This function that describes the layout gets executed once. So how could this work? The condition statements inside of the One of the tricks already to this framework is that at the call site, no constraints have been activated and no constraints. It also stores all of the decisions about view hierarchy and constraints in a tree of components. The if statements would mark components under it to be active or inactive. This could be used to get the active constraints and current view layout that could be re-run through the diffing algorithm. The next thing to solve is how to know when to re-evaluate the layout to make adjustments. The simplest implementation of this is to have each view layout store a single "ViewState" or "ViewModel" object. Require that for this framework to work, the functions inside of |
What I see as the pros of this:
|
Some cons:
|
There are also a couple concerns:
|
to handle the other UI stuff, we can probably make some kind of bindings interface: https://www.swiftbysundell.com/posts/bindable-values-in-swift This doesn't work for all UIKit things because a lot has to be done with closures because UIKit sometimes relies on method calls. But a closure API could be tacked onto that. I think this would work really well for UI configuration, but can it also work for deciding what path to go down for constraints/subviews being on screen? It's similar to the |
I think that if I go down this route I should remove the component returns from the APIs. The library will have strong enough opinions that making an opinionated library around it won't be easily possible. |
There are also going to be times when you want to bind on multiple properties on a view state and we can't really do variadic generics in that way so you'd need some other type of API. |
I think that going with a purely functional approach as I mocked up elsewhere with enums/structs, and using something like |
originally brought up in #31
The text was updated successfully, but these errors were encountered: