Skip to content

Instantly share code, notes, and snippets.

@insidegui
Created July 6, 2022 20:00
Show Gist options
  • Save insidegui/091bfc42f59f35148c158e7e7e664a86 to your computer and use it in GitHub Desktop.
Save insidegui/091bfc42f59f35148c158e7e7e664a86 to your computer and use it in GitHub Desktop.
Handy debugging extension on SwiftUI's Animation
import SwiftUI
/// On macOS, modifying an Animation with .currentSpeed(), or using the .current static property
/// allows for easy animation debugging by holding down the Shift key when triggering the animation.
/// When the animation is triggered while the Shift key is pressed, it will be played in slow motion.
/// Using this extension has no effect when targeting other OSes or when building for release.
extension Animation {
static var currentSpeed: Double {
#if DEBUG
#if os(macOS)
if NSEvent.modifierFlags.contains(.shift) {
return 0.1
} else {
return 1
}
#else
return 1
#endif
#else
return 1
#endif
}
static var current: Animation { Animation.default.currentSpeed() }
func currentSpeed() -> Animation {
speed(Self.currentSpeed)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment