Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created January 31, 2021 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sturdysturge/957b2918d801bc2dabeb67a07c4a82eb to your computer and use it in GitHub Desktop.
Save sturdysturge/957b2918d801bc2dabeb67a07c4a82eb to your computer and use it in GitHub Desktop.
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