Last active
          February 20, 2019 13:38 
        
      - 
      
- 
        Save davidhellsing/6d5d8fd1a62943e43a6a91f6982e63b8 to your computer and use it in GitHub Desktop. 
Revisions
- 
        davidhellsing renamed this gist Feb 20, 2019 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewingFile renamed without changes.
- 
        davidhellsing created this gist Feb 20, 2019 .There are no files selected for viewingThis file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ import { Easing } from 'react-native' /* * Function that animates a value from 0 - 1 * Uses React Native’s Easing functions * Returns an object that has a stop() function */ interface Args { duration: number, easing?: (value: number) => number, onFrame?: (value: number) => void, onComplete?: () => void, } export type AnimationReturnType = { stop: () => void, } export default ({ duration = 800, easing = Easing.inOut(Easing.quad), onFrame, onComplete }: Args) => { let stopped = false const returnObject: AnimationReturnType = { stop: () => { stopped = true }, } const then = Date.now() function loop() { if (!stopped) { const time = Date.now() - then if (time > duration) { if (onComplete) { onComplete() } } else if (onFrame) { onFrame(easing(time / duration)) requestAnimationFrame(loop) } } } loop() return returnObject }