-
-
Save sturdysturge/957b2918d801bc2dabeb67a07c4a82eb to your computer and use it in GitHub Desktop.
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 DriveView: View { | |
let timer = Timer.publish(every: 0.0166667, on: .main, in: .common).autoconnect() | |
@Binding var moving: Bool | |
@Binding var rotation: Float | |
@Binding var speed: Float | |
let rotationChanged: () -> Void | |
let onTimer: () -> Void | |
var body: some View { | |
Group { | |
Form { | |
Toggle(isOn: $moving) { | |
Text("Moving") | |
} | |
.onReceive(timer) { value in | |
onTimer() | |
} | |
Text("Speed: \(speed) m/s") | |
HStack { | |
Text("Reverse") | |
.frame(maxWidth: .infinity, alignment: .leading) | |
Divider() | |
Text("Forward") | |
.frame(maxWidth: .infinity, alignment: .trailing) | |
} | |
Slider(value: $speed, in: -0.02...0.02) | |
Text("Rotation: \(rotation) degrees") | |
Slider(value: $rotation, in: 0...359) | |
.onChange(of: rotation) { _ in rotationChanged() } | |
} | |
.frame(height: 200) | |
} | |
.frame(maxHeight: .infinity, alignment: .bottom) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment