Created
August 5, 2022 16:29
-
-
Save BigZaphod/e55d41af3e1c6c3dd08f7a20cbc51b67 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
// 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