From 3cbbd7a2a3617b17c1b128979505f171c882ad0d Mon Sep 17 00:00:00 2001 From: fohletex Date: Wed, 11 Nov 2020 14:07:10 +0100 Subject: [PATCH] Add option to useNativeDriver; defaults to false --- ActionButton.js | 9 +++++---- index.d.ts | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ActionButton.js b/ActionButton.js index ec1b9e3..5ee6888 100644 --- a/ActionButton.js +++ b/ActionButton.js @@ -20,6 +20,7 @@ import { const ActionButton = props => { const [, setResetToken] = useState(props.resetToken); const [active, setActive] = useState(props.active); + const useNativeDriver = props.useNativeDriver || false; const anim = useRef(new Animated.Value(props.active ? 1 : 0)); const timeout = useRef(null); const mounted = useRef(false); @@ -35,13 +36,13 @@ const ActionButton = props => { useEffect(() => { if (props.active) { - Animated.spring(anim.current, { toValue: 1 }).start(); + Animated.spring(anim.current, { toValue: 1, useNativeDriver }).start(); setActive(true); setResetToken(props.resetToken); } else { props.onReset && props.onReset(); - Animated.spring(anim.current, { toValue: 0 }).start(); + Animated.spring(anim.current, { toValue: 0, useNativeDriver }).start(); timeout.current = setTimeout(() => { setActive(false); setResetToken(props.resetToken); @@ -254,7 +255,7 @@ const ActionButton = props => { if (active) return reset(animate); if (animate) { - Animated.spring(anim.current, { toValue: 1 }).start(); + Animated.spring(anim.current, { toValue: 1, useNativeDriver }).start(); } else { anim.current.setValue(1); } @@ -266,7 +267,7 @@ const ActionButton = props => { if (props.onReset) props.onReset(); if (animate) { - Animated.spring(anim.current, { toValue: 0 }).start(); + Animated.spring(anim.current, { toValue: 0, useNativeDriver }).start(); } else { anim.current.setValue(0); } diff --git a/index.d.ts b/index.d.ts index 2ba74e9..d787a32 100644 --- a/index.d.ts +++ b/index.d.ts @@ -36,6 +36,7 @@ export interface ActionButtonProperties extends ViewProperties { activeOpacity?: number, useNativeFeedback?: boolean, + useNativeDriver?: boolean, fixNativeFeedbackRadius?: boolean, nativeFeedbackRippleColor?: string }