REF: Use new helpers for animation. RemoveonPressout

This commit is contained in:
Marcos Rodriguez Velez 2025-02-24 02:41:00 -04:00
parent c3f7d5b184
commit 599b5d3b60

View file

@ -1,4 +1,4 @@
import React, { forwardRef, useCallback, useImperativeHandle, useRef } from 'react';
import React, { forwardRef, useCallback, useImperativeHandle, useMemo, useRef } from 'react';
import {
Animated,
FlatList,
@ -187,32 +187,31 @@ export const WalletCarouselItem: React.FC<WalletCarouselItemProps> = React.memo(
const itemWidth = width * 0.82 > 375 ? 375 : width * 0.82;
const { isLargeScreen } = useIsLargeScreen();
const springConfig = useMemo(() => ({ useNativeDriver: true, tension: 100 }), []);
const animateScale = useCallback(
(toValue: number, callback?: () => void) => {
Animated.spring(scaleValue, { toValue, ...springConfig }).start(callback);
},
[scaleValue, springConfig],
);
const onPressedIn = useCallback(() => {
if (animationsEnabled) {
Animated.spring(scaleValue, {
toValue: 0.95,
useNativeDriver: true,
tension: 100,
}).start();
animateScale(0.95);
}
if (onPressIn) onPressIn();
}, [scaleValue, animationsEnabled, onPressIn]);
}, [animateScale, animationsEnabled, onPressIn]);
const onPressedOut = useCallback(() => {
if (animationsEnabled) {
Animated.spring(scaleValue, {
toValue: 1.0,
useNativeDriver: true,
tension: 100,
}).start();
animateScale(1.0);
}
if (onPressOut) onPressOut();
}, [scaleValue, animationsEnabled, onPressOut]);
}, [animateScale, animationsEnabled, onPressOut]);
const handlePress = useCallback(() => {
onPressedOut();
onPress(item);
}, [item, onPress, onPressedOut]);
}, [item, onPress]);
const opacity = isSelectedWallet === false ? 0.5 : 1.0;
let image;
@ -254,6 +253,8 @@ export const WalletCarouselItem: React.FC<WalletCarouselItemProps> = React.memo(
if (handleLongPress) handleLongPress();
}}
onPress={handlePress}
delayHoverIn={0}
delayHoverOut={0}
>
<View style={[iStyles.shadowContainer, { backgroundColor: colors.background, shadowColor: colors.shadowColor }]}>
<LinearGradient colors={WalletGradient.gradientsFor(item.type)} style={iStyles.grad}>
@ -421,6 +422,7 @@ const WalletsCarousel = forwardRef<FlatListRefType, WalletsCarouselProps>((props
showsHorizontalScrollIndicator={false}
initialNumToRender={10}
scrollEnabled={scrollEnabled}
keyboardShouldPersistTaps="handled"
ListHeaderComponent={ListHeaderComponent}
style={{ minHeight: sliderHeight + 12 }}
onScrollToIndexFailed={onScrollToIndexFailed}