My idea is something similar to the "instagram like", when you click it, it should render a heart animation
My code: when you click in the heart button, it calls the "changeFavorite" function, which will set 'favorite = true' in the API and also renders the animation. It updates the API, but doesn't return the JSX with Lottie Animation
//Like Button
<TouchableOpacity onPress={changeFavorite} style={{borderRadius: 50, marginRight: 16, marginTop: 16}}>
<MaterialIcons name="favorite" size={30} color={favorito == 1 ? 'red' : '#fff'}/></TouchableOpacity>
//changeFavorite
async function changeFavorite() {
try {
await api.put(`favoritos/${local.id}`, {
local_id: local.id
}).then(res => {
setFavorito(res.data)
if(favorito === 0) {
console.log("like")
return (
<View style={{flex: 1, height: 300, width: 300, position:"absolute"}}>
<LottieView
source={require('../../assets/heart.json')}
resizeMode="cover"
autoPlay
/>
</View>
)
}
else {
console.log("deslike")
}
})
} catch (error) {
console.log(error)
}
}