/SwiftUISheets.swift Secret
Created
January 16, 2023 16:18
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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