I have a @Published var showDialog: Bool = false in viewmodel , once it been true , I want to show a dialog , but for some resone it does not show any , and the same code work if I change showDialog in upper Uis
My Main View
@StateObject var viewModel = ViewModel.instance
UploadlingImages( )
.alert(isPresented: $ViewModel.showDialog) {
Alert(title: Text("Content View Alert"),
message: Text("Content View Alert"),
dismissButton: .default(Text("OK")))
}
Code used Inside view , this is as gallery picker
struct ImagePickerSwiftUI: UIViewControllerRepresentable {
@SwiftUI.Environment(\.presentationMode) private var presentationMode
@StateObject var viewModel = ViewModel.instance
func makeUIViewController(context: UIViewControllerRepresentableContext<ImagePickerSwiftUI>) -> UIImagePickerController {
let imagePicker = UIImagePickerController()
imagePicker.allowsEditing = false
imagePicker.sourceType = sourceType
imagePicker.delegate = context.coordinator
return imagePicker
}
func updateUIViewController(_ uiViewController: UIImagePickerController, context: UIViewControllerRepresentableContext<ImagePickerSwiftUI>) {
}
func makeCoordinator() -> Coordinator {
return Coordinator(self)
}
final class Coordinator: NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
var parent: ImagePickerSwiftUI
init(_ parent: ImagePickerSwiftUI) {
self.parent = parent
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
parent.presentationMode.wrappedValue.dismiss()
viewModel.showDialog = true // this line in not updateing ui
}
}
}