I try to catch an event that occurs in a UIViewController in the SwiftUI view. the architecture is in SwiftUI with an element in Swift:
The View
struct PlayGame: View {
var body: some View {
if stateProgress.stateOfGame == 0 {
CardsDeckRepresentable()
}
}
}
The UIViewControllerRepresentable
struct CardsDeckRepresentable: UIViewControllerRepresentable {
typealias UIViewControllerType = CardsDeckViewController
func makeUIViewController(context: Context) -> CardsDeckViewController {
let deck = CardsDeckViewController()
return deck
}
func updateUIViewController(_ uiViewController: CardsDeckViewController, context: Context) {
}
}
The UIViewController
class CardsDeckViewController : UIViewController, iCarouselDelegate, iCarouselDataSource{
... some code ...
func moveCardChoosen(number:Int) {
self.view.addSubview(cardMobile)
UIView.animate(withDuration: 0.5, delay: 0.0, options:[], animations: {
self.cardMobile.center.y = self.cardPlace5.center.y
}, completion: { finished in
if finished {
self.cardMobile.isHidden = true
}
})
}
}
At the end of the animation, I want to tel the swiftUIView to do update.
I tried with some ObservableObject or using the updateUIViewController function. I can pass data from the SwiftUI View to the UIViewController through the UIViewControllerRepresentable. But how to revive the change from UIViewController? The updateUIViewController don't seems not be called.