|
| 1 | +#if canImport(AndroidSwiftUI) |
| 2 | +import AndroidSwiftUI |
| 3 | +#else |
| 4 | +import SwiftUI |
| 5 | +#endif |
| 6 | + |
| 7 | +struct NavigationPlayground: View { |
| 8 | + var body: some View { |
| 9 | + ScrollView { |
| 10 | + VStack(alignment: .leading, spacing: 16) { |
| 11 | + Text("Value-based navigation").padding() |
| 12 | + NavigationLink("Push value 1", value: 1) |
| 13 | + NavigationLink("Push value 2", value: 2) |
| 14 | + Divider() |
| 15 | + Text("Classic navigation").padding() |
| 16 | + NavigationLink("Push a destination view", destination: NavDetail(label: "Pushed directly")) |
| 17 | + } |
| 18 | + } |
| 19 | + .navigationDestination(for: Int.self) { value in |
| 20 | + NavDetail(label: "Value \(value)", next: value + 1) |
| 21 | + } |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +struct NavDetail: View { |
| 26 | + let label: String |
| 27 | + var next: Int? = nil |
| 28 | + @Environment(\.dismiss) private var dismiss |
| 29 | + var body: some View { |
| 30 | + VStack(spacing: 16) { |
| 31 | + Text(label) |
| 32 | + if let next, next <= 4 { |
| 33 | + NavigationLink("Push value \(next)", value: next) |
| 34 | + } |
| 35 | + Button("Pop with dismiss") { dismiss() } |
| 36 | + } |
| 37 | + .padding() |
| 38 | + .navigationTitle(label) |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +struct TabViewPlayground: View { |
| 43 | + @State private var selection = 0 |
| 44 | + var body: some View { |
| 45 | + TabView(selection: $selection) { |
| 46 | + VStack(spacing: 16) { |
| 47 | + Text("First tab content") |
| 48 | + Button("Jump to third tab") { selection = 2 } |
| 49 | + } |
| 50 | + .tabItem { Text("One") }.tag(0) |
| 51 | + Text("Second tab content").tabItem { Text("Two") }.tag(1) |
| 52 | + Text("Third tab content").tabItem { Text("Three") }.tag(2) |
| 53 | + } |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +struct SheetPlayground: View { |
| 58 | + @State private var full = false |
| 59 | + @State private var medium = false |
| 60 | + var body: some View { |
| 61 | + ScrollView { |
| 62 | + VStack(spacing: 16) { |
| 63 | + Button("Present full-size sheet") { full = true } |
| 64 | + Button("Present medium detent sheet") { medium = true } |
| 65 | + } |
| 66 | + .padding() |
| 67 | + } |
| 68 | + .sheet(isPresented: $full) { |
| 69 | + SheetBody(title: "Full-size sheet") |
| 70 | + } |
| 71 | + .sheet(isPresented: $medium) { |
| 72 | + SheetBody(title: "Medium sheet").presentationDetents([.medium]) |
| 73 | + } |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +struct SheetBody: View { |
| 78 | + let title: String |
| 79 | + @Environment(\.dismiss) private var dismiss |
| 80 | + var body: some View { |
| 81 | + VStack(spacing: 16) { |
| 82 | + Text(title) |
| 83 | + Button("Dismiss") { dismiss() } |
| 84 | + } |
| 85 | + .padding() |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +struct AlertPlayground: View { |
| 90 | + @State private var simple = false |
| 91 | + @State private var confirm = false |
| 92 | + @State private var result = "No choice yet" |
| 93 | + var body: some View { |
| 94 | + ScrollView { |
| 95 | + VStack(spacing: 16) { |
| 96 | + Button("Show simple alert") { simple = true } |
| 97 | + Button("Show confirmation") { confirm = true } |
| 98 | + Text(result) |
| 99 | + } |
| 100 | + .padding() |
| 101 | + } |
| 102 | + .alert("A simple alert", isPresented: $simple, message: "This is the message body.") |
| 103 | + .alert("Delete item?", isPresented: $confirm, message: "This cannot be undone.", buttons: [ |
| 104 | + AlertButton("Cancel", role: .cancel) { result = "Cancelled" }, |
| 105 | + AlertButton("Delete", role: .destructive) { result = "Deleted" }, |
| 106 | + ]) |
| 107 | + } |
| 108 | +} |
0 commit comments