https://kotlinlang.org logo
#compose
Title
# compose
j

John O'Reilly

12/20/2020, 10:38 AM
What , if anything right now, would be considered Compose's equivalent of SwiftUI's
@Binding
?
k

kenkyee

12/20/2020, 12:49 PM
Why would you use that instead of a state class for the entire screen? That seems like a shared ambient variable aka a global from the description of it.. https://www.hackingwithswift.com/quick-start/swiftui/what-is-the-binding-property-wrapper
j

John O'Reilly

12/20/2020, 12:53 PM
Hmm, I guess the way @State is managed in SwiftUI vs Compose's concept of state may mean @Binding isn't needed/applicable in Compose
r

robnik

12/20/2020, 3:00 PM
I'd say the equivalent to Binding in SwiftUI is MutableState. Swift is different here because they are using value types for so much. Because SwiftUI's
State
is a value type they, can't just pass a reference to it, so
Binding
is effectively that reference. While in Compose you just pass the MutableState down to nested Composables, either directly, or as the get/set pair.
👍 2
j

John O'Reilly

12/20/2020, 3:33 PM
I also wonder to what extent proper use of "state hoisting" avoids need for this approach as well
2