Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@BigZaphod
Created August 5, 2022 16:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BigZaphod/e55d41af3e1c6c3dd08f7a20cbc51b67 to your computer and use it in GitHub Desktop.
Save BigZaphod/e55d41af3e1c6c3dd08f7a20cbc51b67 to your computer and use it in GitHub Desktop.
// It is absolutely insane that velocity isn't public.
// INSANE.
// I don't get it.
// So anyway, this works but is kind of horrible.
// It's probably pretty safe to use and it should fallback to 0 if something goes wrong.
// Maybe.
extension DragGesture.Value {
var secretVelocity: CGSize {
let mirror = Mirror(reflecting: self)
guard let velocity = mirror.children.first(where: { $0.label == "velocity" }) else {
return .zero
}
let velocityMirror = Mirror(reflecting: velocity.value)
guard let valuePerSecond = velocityMirror.children.first(where: { $0.label == "valuePerSecond" }) else {
return .zero
}
guard let secretVelocity = valuePerSecond.value as? CGSize else {
return .zero
}
return secretVelocity
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment