0

I am gonna implement LIKE and DISLIKE function in my FlatList. And in here I want to use lottie animation instead of vector-icons.(heart animation) Then I am not sure how to animate separate animation in FlatList. (Animation by using vector-icon is working well.) All data of separate item comes from backend.(e.g: isLike: 1 or 0)

How to implement it? Following is my code.

const animation = useRef(null);
const likeRestaurant = (item) => {
  // how to ... ?
}

const renderRestaurant = ({ item }) => (
  <View style={styles.resItem}>
    <TouchableOpacity onPress={() => likeRestaurant(item)}>
      {/* <MaterialCommunityIcons 
        color="red" size={20} 
        name={item.isLike === 1 ? "heart" : "heart-outline"}      //    This is working well.
      /> */}
      <LottieView
        ref={animation}
        style={styles.heartLottie}
        source={require("../assets/like.json")}
        autoPlay={false}
        loop={false}
      />
    </TouchableOpacity>
  </View>
)

// render
<FlatList
  data={restaurantList ? restaurantList : []}
  numColumns={2}
  keyExtractor={(item, index) => index.toString()}
  renderItem={renderRestaurant}
/>
SatelBill
  • 533
  • 7
  • 20
  • Take a look at [this](https://stackoverflow.com/questions/54633690/how-can-i-use-multiple-refs-for-an-array-of-elements-with-hooks) – Auticcat Jun 11 '21 at 09:53

0 Answers0