darkmoon_uk
02/25/2025, 5:48 AMBinding<>
and a Kotlin MutableStateFlow
,
for example, swift:
someView
.sheet(isPresented: isShowLoginSheet) { // <-- Super common usage of bottom sheet in SwiftUI
...
...sheet
takes a Binding<Bool>
that opens a bottom sheet when it becomes true
.
In the other direction; SwiftUI writes false
into this binding, when the sheet is dismissed.
Now, if you want to fully bind that to a MutableStateFlow
, you'd need some code to detect the Binding
change and set it back to the flow's .value
.
I set out to make a FlowBinding
utility to achieve this.
Due to synchronisation issues, it wasn't as straightforward as anticipated, so I ended up with the code in thread.
This works but I think it can probably be improved - code in 🧵 in case this problem piques any interests!darkmoon_uk
02/25/2025, 5:49 AMdarkmoon_uk
02/25/2025, 5:50 AMvar body: some View {
return FlowBinding(
mutableStateFlow: globalState.isShowLoginSheet, // <-- Don't hurt me, this part is inherited
transformOut: { kotlinBool in kotlinBool.boolValue },
transformIn: { bool in bool.asKotlin() }
) { (isShowLoginSheetKotlinBinding: Binding<Bool>) in
...
François
02/25/2025, 9:17 AMFrançois
02/25/2025, 9:19 AMFrançois
02/25/2025, 4:41 PM