Just started a journey with SwiftUI and realised that for some reason there're a lot of components from UIKit which must be wrapped in UIViewControllerRepresentable to be working in SwiftUI code. One of them should react to change of the @State/@Binding param which is changed in a separate component. The issue is I need somehow to subscribe to that state param and handle its updates in wrapper struct. But I could not find any Binding<> props which could allow doing that.
There's a simple example
struct SwiftUIView: View {
@State private var state:Bool = false
var body: some View {
Foo(state: self.$state)
}
}
struct Foo<Content: View>: UIViewControllerRepresentable {
var state: Binding<Bool>
init(state: Binding<Bool>) {
self.state = state
// how to watch this param and handle every change by calling bar function?
}
func bar(newState: Bool) {
print(newState)
}
func makeUIViewController() {}
func updateUIViewController() {}
}
Probably there should be another approach?