我正在尝试创建一个actionSheet
来打开一个模式以保存到视图。当前,我只能获得actionSheet
中的按钮之一才能打开模式。如何重写.sheet
代码以执行此操作?谢谢。
@State var showActionSheet = false
@State var showAddActivityPopup = false
@State var showAddDayPopup = false
var body: some View {
Button(action: {
self.showActionSheet = true
}) {
Text("Show Action Sheet")
}
.actionSheet(isPresented: $showActionSheet, content: actionSheet)
.sheet(isPresented: $showAddDayPopup, onDismiss: {
print(self.showActionSheet)
}) {
AddDayPopup(message: "Add Day")
}
.sheet(isPresented: $showAddActivityPopup, onDismiss: {
print(self.showActionSheet)
}) {
AddActivityPopup(message: "Add Activity")
}
}
private func actionSheet() -> ActionSheet {
let button1 = ActionSheet.Button.default(Text("Add Day")) {
self.showActionSheet = false
self.showAddDayPopup = true
}
let button2 = ActionSheet.Button.default(Text("Add Activity")) {
self.showActionSheet = false
self.showAddActivityPopup = true
}
let actionSheet = ActionSheet(title: Text("What would you like to add?"),
message: nil,
buttons: [button1, button2, .cancel()])
return actionSheet
}
}