Skip to content

Commit

Permalink
Fix slider button rerendering (#3623)
Browse files Browse the repository at this point in the history
  • Loading branch information
wachunei authored Jan 25, 2022
1 parent 4ed6848 commit bcf3212
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app/components/UI/SliderButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ function SliderButton({ incompleteText, completeText, onComplete, disabled, onSw
const pan = useRef(new Animated.ValueXY(0, 0)).current;
const completion = useRef(new Animated.Value(0)).current;

const onCompleteCallback = useRef(onComplete);

const handleIsPressed = useCallback(
(isPressed) => {
onSwipeChange?.(isPressed);
Expand Down Expand Up @@ -128,6 +130,10 @@ function SliderButton({ incompleteText, completeText, onComplete, disabled, onSw
outputRange: [colors.blue600, colors.success],
});

useEffect(() => {
onCompleteCallback.current = onComplete;
}, [onComplete, onCompleteCallback]);

const startCompleteAnimation = useCallback(() => {
if (!hasStartedCompleteAnimation) {
setHasStartedCompleteAnimation(true);
Expand All @@ -139,13 +145,13 @@ function SliderButton({ incompleteText, completeText, onComplete, disabled, onSw
isInteraction: false,
}),
]).start(() => {
if (onComplete && !hasCompletedCalled) {
if (onCompleteCallback.current && !hasCompletedCalled) {
setHasCompletedCalled(true);
onComplete();
onCompleteCallback.current?.();
}
});
}
}, [completion, componentWidth, hasCompletedCalled, hasStartedCompleteAnimation, onComplete, pan]);
}, [completion, componentWidth, hasCompletedCalled, hasStartedCompleteAnimation, onCompleteCallback, pan]);

const panResponder = useMemo(
() =>
Expand Down

0 comments on commit bcf3212

Please sign in to comment.