Haz doble clic en una lista plana de React Native.
Estoy intentando recrear el doble toque de Instagram en un elemento y aparece un corazón durante unos segundos. Actualmente estoy renderizando elementos de texto en una flatList (1 elemento por página) y quiero que el usuario pueda realizar doble toque en la sección de texto y aparezca un corazón.
No puedo hacer que tanto la flatList como la animación funcionen juntas. ¿Alguna idea? En mi código actual solo renderizará la flatList y no la Animated.image. Intenté envolver la imagen animada en un contenedor touchable sin retroalimentación, pero aún no tengo suerte.
const onDoubleTap = useCallback(() => {
//console.log("tapped");
scale.value = withSpring(1, undefined, (isFinished) => {
if (isFinished) {
scale.value = withDelay(500, withSpring(0));
console.log("Double Tapped");
}
});
}, []);
return (
<tapgesturehandler numberoftaps="{2}" onactivated="{onDoubleTap}">
<animated.view>
<flatlist horizontal="{false}" decelerationrate="{"fast"}" snaptoalignment="{"center"}" snaptointerval="{Dimensions.get("screen").height}" data="{flatl}" keyextractor="{(item," index)=""> `id_${index}`}
style={styles.fullScreen}
renderItem={({ item }) => (
<view style="{[{" ...styles.fullheight="" }]}="">
<text>{item.name}</text>
</view>
)}
/>
<animatedimage source="{require("../assets/heart.png")}" style="{[" styles.image,="" rstyle,="" ]}="" resizemode="{"center"}"></animatedimage>
</flatlist></animated.view>
</tapgesturehandler>
);
}
davy.ai
Parece que el problema podría ser la forma en que estás envolviendo el componente
Animated.Image
. En lugar de colocarlo dentro del componenteFlatList
, debería colocarse fuera de ella en el mismo contenedor que el componenteFlatList
. De esta manera, se puede renderizar junto con elFlatList
y animarse según sea necesario.Intenta actualizar tu código para que se vea algo como esto:
Aquí, el componente
Animated.Image
está envuelto en un componenteAnimated.View
, al que se le asigna un estilo que incluye los parámetros de animación. Este contenedor luego se coloca fuera del componenteFlatList
en el mismo contenedor que elFlatList
.Además, agregué un contenedor
View
constyles.container
para ayudar con el diseño y el estilo. Es posible que debas ajustar los estilos según tus necesidades.¡Espero que esto ayude! Déjame saber si tienes alguna pregunta adicional.