我想在标签栏页面上显示弹出窗口。我将在子页面中创建弹出视图。我想通过共享类 ObservableObject 发送视图。反正我解决不了。你能帮我解决这个问题吗?
我的股票价值
class sharedValues: ObservableObject {
@Published var showingPopup = false
var sharePopupView ? // i want to use this view for popup
}
我的标签页。它有很多子页面
struct TabPage: View {
@EnvironmentObject var share : sharedValues
var body: some View {
VStack(spacing:0) {
NavigationView{
switch share.selectedItemIndex {
case 0: Shop()
case 1: ConversationsView()
case 2: GameHome()
case 3: GameHome()
default: GameHome()
}
}
Tabbar()
}
.popup(isPresented: $share.showingPopup, type: .`default`,animation: .spring(), closeOnTapOutside: true) {
share.sharePopupView
}
}
}
我要调用 popup 的子页面之一
struct ConversationsView: View {
@ViewBuilder private func popup1View() -> some View {
Button(action:{
print("buton tap")
}){
Text("Placeholder")
}
}
@ViewBuilder private func sunpage1() -> some View {
HStack(){
Button(action: {
share.sharePopupView = popup1View() // i want to use this view for popup
share.showingPopup = true
}) {
Text("delete all")
}
}
}
}