Skip to content

Instantly share code, notes, and snippets.

@laevandus
Created January 16, 2023 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laevandus/000d59c4903c768a2ea8092b3aae264a to your computer and use it in GitHub Desktop.
Save laevandus/000d59c4903c768a2ea8092b3aae264a to your computer and use it in GitHub Desktop.
struct ContentView: View {
enum Sheet: String, Identifiable {
case addItem, settings
var id: String { rawValue }
}
@State private var sheet: Sheet?
var body: some View {
VStack {
Button("Add Item", action: { sheet = .addItem })
Button("Settings", action: { sheet = .settings })
}
.sheet(item: $sheet, content: makeSheet)
}
@ViewBuilder
func makeSheet(_ sheet: Sheet) -> some View {
switch sheet {
case .addItem:
AddItemView()
case .settings:
SettingsView()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment