I have a BaseView something like this and I want to add alert mechanism to all my subviews
struct BaseView<Content: View>: View {
@State var isAlertPresented = false
let content: Content
init(@ViewBuilder content: () -> Content) {
self.content = content()
}
var body : some View {
content.alert(isPresented: $isAlertPresented) {
Alert(title: Text("title"))
}
}
}
And here is my SubView.
struct SubView: View {
BaseView {
Text("")
}.onReceive(vm.publisher) { (output) in
// here I want to trigger BaseView isAlertPresented property
// BaseView.isAlertPresented = true
}
}
Can I do something like this? If yes how can I?