Skip to content

Commit 1de2008

Browse files
authored
Merge branch 'main' into ogp/22135
2 parents 6e8d3c3 + 2ae45e5 commit 1de2008

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

app/components/UI/Rewards/hooks/useRewardsAnimation.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,16 @@ export const useRewardsAnimation = ({
198198
duration: ANIMATION_DURATION.FAST,
199199
});
200200

201+
// Ensure animated value is set to current value when entering Idle state
202+
// This fixes the issue where transitioning from Loading to Idle with the same value
203+
// would leave the display stuck at 0
204+
/* istanbul ignore next - Reanimated shared value mutation not tracked by Istanbul */
205+
if (animatedValue.value !== currentValue) {
206+
animatedValue.value = withTiming(currentValue, {
207+
duration: ANIMATION_DURATION.FAST,
208+
});
209+
}
210+
201211
// Only trigger Rive animation if value changed
202212
if (currentValue !== previousValue) {
203213
const trigger =
@@ -208,7 +218,13 @@ export const useRewardsAnimation = ({
208218
triggerRiveAnimation(trigger);
209219
previousValueRef.current = currentValue;
210220
}
211-
}, [value, rivePosition, triggerRiveAnimation, clearAllTimeouts]);
221+
}, [
222+
value,
223+
rivePosition,
224+
triggerRiveAnimation,
225+
clearAllTimeouts,
226+
animatedValue,
227+
]);
212228

213229
const handleRefreshLoadingState = useCallback(() => {
214230
if (!riveRef.current) return;
@@ -250,8 +266,23 @@ export const useRewardsAnimation = ({
250266
duration: ANIMATION_DURATION.FAST,
251267
});
252268

269+
// Ensure animated value is set to current value when entering RefreshFinished state
270+
// This ensures the display shows the correct value after a refresh
271+
/* istanbul ignore next - Reanimated shared value mutation not tracked by Istanbul */
272+
if (animatedValue.value !== value) {
273+
animatedValue.value = withTiming(value, {
274+
duration: ANIMATION_DURATION.FAST,
275+
});
276+
}
277+
253278
triggerRiveAnimation(RewardsIconTriggers.RefreshLeft);
254-
}, [triggerRiveAnimation, clearAllTimeouts, rivePosition]);
279+
}, [
280+
triggerRiveAnimation,
281+
clearAllTimeouts,
282+
rivePosition,
283+
animatedValue,
284+
value,
285+
]);
255286

256287
// State machine effect - triggers appropriate animation based on state
257288
useEffect(() => {

0 commit comments

Comments
 (0)