今天做一个多个 sheet
的效果,点击下面三个按钮打开不同的 sheet
。
Show me the code
import SwiftUI
enum CurrentActiveSheet: Identifiable {
case add, edit, delete
var id: Int {
hashValue
}
}
struct MoreSheet: View {
@State var currentActiveSheet: CurrentActiveSheet?
var body: some View {
HStack(spacing: 20) {
Text("add")
.padding()
.background(Color.red)
.onTapGesture {
currentActiveSheet = .add
}
Text("edit")
.padding()
.background(Color.green)
.onTapGesture {
currentActiveSheet = .edit
}
Text("delete")
.padding()
.background(Color.blue)
.onTapGesture {
currentActiveSheet = .delete
}
}
.foregroundColor(Color.white)
.sheet(item: $currentActiveSheet) { item in
switch item {
case .add:
Text("add")
case .edit:
Text("edit")
case .delete:
Text("delete")
}
}
}
}
struct MoreSheet_Previews: PreviewProvider {
static var previews: some View {
MoreSheet()
}
}