I see that neither <Corbind> nor <FlowBinding> exp...
# android
g
I see that neither Corbind nor FlowBinding expose View's state as
StateFlow
. Does it make sense to do so? Is there another library that is doing that?
a
I don't think it makes much sense. State should flow into the views and events should flow out. You shouldn't need to observe view state since you put the state there in the first place. Text fields can be a bit of a special case for that but it's not an example that generalizes well.
☝️ 2
g
Does this currently apply so well outside of a Compose-world? In the Android UI toolkit there's a lot of state that I want to observe that is out of my control. E.g. button pressed state, switch checked state, edittext input/focus .
a
yes, even in those examples the data ownership/source of truth is muddled and leads to generalized designs in frameworks like the above that magnify the ownership confusion
button press state? sure, events dispatched by the button where the user is more or less the data source. Switch checked state? Really non-obvious, which tends to lead to strange workarounds to figure out whether a view state change was a request from the user or the app synchronizing its own state with the view
At that point, you no longer have just a checked state, you have events that may include why it changed to that state. Once those events are stale and replayed they no longer have meaning
a replayed user-checked-the-checkbox event generally shouldn't be acted upon (persisting a new setting value, for example) since presumably that action should have been taken when the event originally occurred, and not again later when an observer gets an initial value event from a StateFlow
modeling most view state as StateFlows makes determining all of these things definitively that much harder. Even button pressed state suffers from the same core problem: what should an observer do with an initial value and why? is there special casing required for correctness in processing user intent? when it comes to user input usually the answer is yes, which makes events rather than state the better tool.
g
Thank you for your input Adam