|
| 1 | +#if canImport(AndroidSwiftUI) |
| 2 | +import AndroidSwiftUI |
| 3 | +#else |
| 4 | +import SwiftUI |
| 5 | +#endif |
| 6 | + |
| 7 | +struct ControlStylePlayground: View { |
| 8 | + |
| 9 | + @State private var flavor = "Vanilla" |
| 10 | + @State private var notify = true |
| 11 | + @State private var name = "" |
| 12 | + |
| 13 | + private let flavors = ["Vanilla", "Cocoa", "Mint"] |
| 14 | + |
| 15 | + var body: some View { |
| 16 | + ScrollView { |
| 17 | + VStack(alignment: .leading, spacing: 0) { |
| 18 | + Example("buttonStyle") { |
| 19 | + VStack(alignment: .leading, spacing: 10) { |
| 20 | + Button("automatic") {} |
| 21 | + Button("bordered") {}.buttonStyle(.bordered) |
| 22 | + Button("borderedProminent") {}.buttonStyle(.borderedProminent) |
| 23 | + Button("plain") {}.buttonStyle(.plain) |
| 24 | + } |
| 25 | + } |
| 26 | + Example("Inherited by a container") { |
| 27 | + // one style, applied once, styles both buttons |
| 28 | + VStack(alignment: .leading, spacing: 10) { |
| 29 | + Button("Inherited one") {} |
| 30 | + Button("Inherited two") {} |
| 31 | + } |
| 32 | + .buttonStyle(.bordered) |
| 33 | + } |
| 34 | + Example("pickerStyle") { |
| 35 | + VStack(alignment: .leading, spacing: 14) { |
| 36 | + Picker("Menu", selection: $flavor) { |
| 37 | + ForEach(flavors, id: \.self) { Text($0).tag($0) } |
| 38 | + } |
| 39 | + Picker("Segmented", selection: $flavor) { |
| 40 | + ForEach(flavors, id: \.self) { Text($0).tag($0) } |
| 41 | + } |
| 42 | + .pickerStyle(.segmented) |
| 43 | + Picker("Inline", selection: $flavor) { |
| 44 | + ForEach(flavors, id: \.self) { Text($0).tag($0) } |
| 45 | + } |
| 46 | + .pickerStyle(.inline) |
| 47 | + Text("Chosen: \(flavor)") |
| 48 | + } |
| 49 | + } |
| 50 | + Example("toggleStyle") { |
| 51 | + VStack(alignment: .leading, spacing: 10) { |
| 52 | + Toggle("switch", isOn: $notify) |
| 53 | + Toggle("checkbox", isOn: $notify).toggleStyle(.checkbox) |
| 54 | + Toggle("button", isOn: $notify).toggleStyle(.button) |
| 55 | + } |
| 56 | + } |
| 57 | + Example("textFieldStyle") { |
| 58 | + VStack(alignment: .leading, spacing: 10) { |
| 59 | + TextField("rounded border", text: $name) |
| 60 | + TextField("plain", text: $name).textFieldStyle(.plain) |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + .navigationTitle("Control Styles") |
| 66 | + } |
| 67 | +} |
0 commit comments