Skip to content

Commit

Permalink
Merge pull request #2 from fohletex/fix-useNativeDriver-warning
Browse files Browse the repository at this point in the history
Add option to useNativeDriver; defaults to false
  • Loading branch information
shobhitsinghal624 authored Sep 21, 2022
2 parents fbc684b + 3cbbd7a commit 18cbeae
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 5 additions & 4 deletions ActionButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface ActionButtonProperties extends ViewProperties {
activeOpacity?: number,

useNativeFeedback?: boolean,
useNativeDriver?: boolean,
fixNativeFeedbackRadius?: boolean,
nativeFeedbackRippleColor?: string
}
Expand Down

0 comments on commit 18cbeae

Please sign in to comment.