Thank you for the post. So I am following this example on my code, but my animation is not being triggered for some reason. The array from the useRef is being changed, but the animation is not working, any ideas of what could be the issue, here is my code. I am trying to expand my card to make the height bigger whenever the user press the View Information button. Thank you!
const animateCardAll = useRef([]);
{markersArr.map((marker, index) => {
animateCardAll.current[index] = new Animated.Value(CARD_HEIGHT);
marker.isExpanded = false;
(marker.imageFetched = false), console.log(marker);
return (
<>
<Animated.View
key={marker._id}
style={[
styles.card,
{
height: animateCardAll.current[index],
},
]}
>
{marker.imageId ? (
<LazyImage
index={index}
//visibleImages={visibleImages}
imageId={marker.imageId}
userToken={userToken}
ref={(cardRefs.current[index] = marker)}
/>
) : null}
<View style={styles.textContent}>
<Text style={styles.cardTitle} numberOfLines={1}>
Address: {marker.address}
</Text>
<Text style={styles.cardDescription} numberOfLines={1}>
{marker.city}, {marker.zip_code} {marker.uSstate}
</Text>
{cardRefs.current[index] &&
cardRefs.current[index].isExpanded ? (
<ReviewsComponent
index={index}
addressId={marker._id}
userToken={userToken}
/>
) : null}
</View>
<View style={styles.button}>
<TouchableOpacity
onPress={() => {
expandCardAll(index);
}}
style={[
styles.signIn,
{
borderColor: "#398984",
borderWidth: 1,
},
]}
>
<Text
style={[
styles.textSign,
{
color: "#398984",
},
]}
>
VIEW INFORMATION
</Text>
</TouchableOpacity>
</View>
</Animated.View>
</>
);
})}
</Animated.ScrollView>
) : null}
const expandCardAll = (index) => {
cardRefs.current[index].isExpanded = !cardRefs.current[index].isExpanded; // Toggle the expanded state
const upadtedHeight = cardRefs.current[index].isExpanded
? SCREEN_HEIGHT * 0.65
: CARD_HEIGHT;
console.log(
"Expanded",
cardRefs.current[index],
animateCardAll.current[index],
animateCardAll,
upadtedHeight
);
Animated.timing(animateCardAll.current[index], {
toValue: upadtedHeight,
duration: 500,
useNativeDriver: false,
}).start(); };
As I mentioned, the value in my animateCardAll.current[index] is being updated properly, but no animation is being triggered.