Skip to content

Commit 18cbeae

Browse files
Merge pull request #2 from fohletex/fix-useNativeDriver-warning
Add option to useNativeDriver; defaults to false
2 parents fbc684b + 3cbbd7a commit 18cbeae

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

ActionButton.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
const ActionButton = props => {
2121
const [, setResetToken] = useState(props.resetToken);
2222
const [active, setActive] = useState(props.active);
23+
const useNativeDriver = props.useNativeDriver || false;
2324
const anim = useRef(new Animated.Value(props.active ? 1 : 0));
2425
const timeout = useRef(null);
2526
const mounted = useRef(false);
@@ -35,13 +36,13 @@ const ActionButton = props => {
3536

3637
useEffect(() => {
3738
if (props.active) {
38-
Animated.spring(anim.current, { toValue: 1 }).start();
39+
Animated.spring(anim.current, { toValue: 1, useNativeDriver }).start();
3940
setActive(true);
4041
setResetToken(props.resetToken);
4142
} else {
4243
props.onReset && props.onReset();
4344

44-
Animated.spring(anim.current, { toValue: 0 }).start();
45+
Animated.spring(anim.current, { toValue: 0, useNativeDriver }).start();
4546
timeout.current = setTimeout(() => {
4647
setActive(false);
4748
setResetToken(props.resetToken);
@@ -254,7 +255,7 @@ const ActionButton = props => {
254255
if (active) return reset(animate);
255256

256257
if (animate) {
257-
Animated.spring(anim.current, { toValue: 1 }).start();
258+
Animated.spring(anim.current, { toValue: 1, useNativeDriver }).start();
258259
} else {
259260
anim.current.setValue(1);
260261
}
@@ -266,7 +267,7 @@ const ActionButton = props => {
266267
if (props.onReset) props.onReset();
267268

268269
if (animate) {
269-
Animated.spring(anim.current, { toValue: 0 }).start();
270+
Animated.spring(anim.current, { toValue: 0, useNativeDriver }).start();
270271
} else {
271272
anim.current.setValue(0);
272273
}

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export interface ActionButtonProperties extends ViewProperties {
3636
activeOpacity?: number,
3737

3838
useNativeFeedback?: boolean,
39+
useNativeDriver?: boolean,
3940
fixNativeFeedbackRadius?: boolean,
4041
nativeFeedbackRippleColor?: string
4142
}

0 commit comments

Comments
 (0)