From a566ef75a3d49b201089a651fd6623661745249a Mon Sep 17 00:00:00 2001 From: Shinpei Date: Mon, 22 Jun 2020 14:30:43 +0900 Subject: [PATCH] Fix: useEffect animation Error --- src/AnimationHooks.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/AnimationHooks.ts b/src/AnimationHooks.ts index 33594cc..e6cb492 100644 --- a/src/AnimationHooks.ts +++ b/src/AnimationHooks.ts @@ -40,13 +40,21 @@ export const useAnimation = (config: UseAnimationConfig): Animated.Value => { const animatedValue = useAnimatedValue(getInitialValue(config)) const animate = () => { - if (config.type === 'timing') { - Animated.timing(animatedValue, config).start() - } else if (config.type === 'spring') { - Animated.spring(animatedValue, config).start() - } else { - // @ts-ignore - throw new Error('unsupported animation type=' + config.type) + let animation = null; + switch(getAnimationType(config)) { + case 'timing': + animation = Animated.timing(animatedValue, config) + break + case 'spring': + animation = spring(animatedValue, config) + break + default: + // @ts-ignore + throw new Error('unsupported animation type=' + config.type) + } + if(animation !== null) animation.start() + return () => { + if(animation !== null) animation.stop() } }