import { Animated } from 'react-native' ; export const DEFAULT_CONFIG = { cycles : 1 , useNativeDriver : true } ; property export interface AnimationConfig extends Animated . AnimationConfig { cycles ? : number ; } /**
 * Base animation class. Creates `Animated.Value` and maps it to props of `Animated.View`
 */ export abstract class Animation < C extends AnimationConfig , R > { protected abstract animation : Animated . CompositeAnimation ; protected counter : number = 0 ; protected endCallback : Animated . EndCallback ; protected running : boolean = false ; protected config : C ; public abstract toProps ( ) ; constructor ( config ? ) { this . config = { ... DEFAULT_CONFIG , ... config } ; } param callback { Animated . EndCallback } public start ( callback ? ) { this . endCallback = callback ; this . running = true ; this . animation . start ( this . onAnimationEnd ) ; } /**
     * Stops the animation
     */ public stop ( ) { this . running = false ; this . animation . stop ( ) ; } returns public isAnimating ( ) { return this . running ; } public release ( ) { this . stop ( ) ; } /**
     * Default animation completion callback.
     * Will run animation again if it is not stopped or it should stop regarding to `cycles` property
     */ protected onAnimationEnd = ( result ) : void => { this . counter += 1 ; if ( this . counter === this . config . cycles ) { this . stop ( ) ; } if ( this . running ) { this . start ( this . endCallback ) ; } if ( ! this . running ) { this . counter = 0 ; this . endCallback && this . endCallback ( result ) ; this . endCallback = null ; } } ; }