Skip to content

Instantly share code, notes, and snippets.

@hitrik
Last active March 14, 2020 14:27
Show Gist options
  • Save hitrik/4039b73ebb0f8dce12d904930fa76094 to your computer and use it in GitHub Desktop.
Save hitrik/4039b73ebb0f8dce12d904930fa76094 to your computer and use it in GitHub Desktop.
const useAnimationUnmount = (duration = 300, useNativeDriver = true) => {
const [animation] = useState(() => new Animated.Value(1));
const [unmount, setUnmount] = useState(false);
const start = useCallback(
() =>
Animated.timing(animation, {
toValue: 0,
useNativeDriver,
duration,
}).start(function onFinish() {
setUnmount(true);
}),
[]
);
return [start, unmount, animation];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment