Maybe one for <#CTJB58X7X|>, but I encountered a u...
# ios
d
Maybe one for #CTJB58X7X, but I encountered a use case that I don't think is yet well catered for by SKIE Flow/SwiftUI interop. Say you're transitioning a native iOS App to Kotlin Multiplatform and during the migration you need to create a bi-directional binding between a SwiftUI
Binding<>
and a Kotlin
MutableStateFlow
, for example, swift:
Copy code
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!
👀 1
FlowBinding.cpp
Usage:
Copy code
var 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
            ...
f
Hi, I have thought about that issue after writer my macro who manage only unidirectional binding with kotlin type. To add the bidirectional, I need to rewrite my macro declaration. Thanks to remember me to think about it.
🔥 1
👍 1
The swift macro way could reduce the boilerplate of creating a bidirectional binding.
I just add the features, yeah 😄 --- About you’re context, Yeah, it seems too much complex. Currently, there is no (never?) guideline about how to really use KMP on iOS. So, I think you should stick to what you can do and avoid overthinking this. 😄
👍 1