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.

Revisions

  1. insidegui created this gist Jul 6, 2022.
    31 changes: 31 additions & 0 deletions Animation+Slow.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    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)
    }

    }