|
| 1 | +#if canImport(AndroidSwiftUI) |
| 2 | +import AndroidSwiftUI |
| 3 | +#else |
| 4 | +import SwiftUI |
| 5 | +#endif |
| 6 | + |
| 7 | +struct GesturePlayground: View { |
| 8 | + |
| 9 | + @State private var dragX = 0.0 |
| 10 | + @State private var dragY = 0.0 |
| 11 | + @State private var dropped = "not yet" |
| 12 | + @State private var presses = 0 |
| 13 | + @State private var taps = 0 |
| 14 | + |
| 15 | + var body: some View { |
| 16 | + ScrollView { |
| 17 | + VStack(alignment: .leading, spacing: 0) { |
| 18 | + Example("DragGesture") { |
| 19 | + VStack(alignment: .leading, spacing: 8) { |
| 20 | + Text("Offset: \(Int(dragX)), \(Int(dragY))") |
| 21 | + Text("Last drop: \(dropped)") |
| 22 | + RoundedRectangle(cornerRadius: 12) |
| 23 | + .fill(.blue) |
| 24 | + .frame(width: 90, height: 90) |
| 25 | + .offset(x: dragX, y: dragY) |
| 26 | + .gesture( |
| 27 | + DragGesture() |
| 28 | + .onChanged { value in |
| 29 | + dragX = value.translation.width |
| 30 | + dragY = value.translation.height |
| 31 | + } |
| 32 | + .onEnded { value in |
| 33 | + dropped = "\(Int(value.translation.width)), \(Int(value.translation.height))" |
| 34 | + } |
| 35 | + ) |
| 36 | + Button("Reset") { |
| 37 | + dragX = 0 |
| 38 | + dragY = 0 |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + Example("onLongPressGesture") { |
| 43 | + VStack(alignment: .leading, spacing: 8) { |
| 44 | + Text("Taps: \(taps) Long presses: \(presses)") |
| 45 | + Text("Tap or press and hold") |
| 46 | + .foregroundColor(.white) |
| 47 | + .padding() |
| 48 | + .background(Color.purple) |
| 49 | + .cornerRadius(8) |
| 50 | + .onTapGesture { taps += 1 } |
| 51 | + .onLongPressGesture { presses += 1 } |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | +} |
0 commit comments