I'm trying to follow this example (code here) and employ LayoutAnimation inside my RN project (the difference from that example being that I just want to render my circles with no button that'll be pressed).
But when I've added LayoutAnimation, it's the whole view/screen/component that does the animation of 'springing in', not just the circles as I desire. Where do I have to move LayoutAnimation to in order to achieve just the circle objects being animated?
UPDATED AGAIN: Heeded bennygenel
's advice to make a separate Circles component and then on Favorites, have a componentDidMount
that would add each Cricle component one by one, resulting in individual animation as the state gets updated with a time delay. But I'm still not getting the desired effect of the circles rendering/animating one by one...
class Circle extends Component {
componentWillMount() {
LayoutAnimation.configureNext(LayoutAnimation.Presets.spring);
}
render() {
return (
<View>
{ this.props.children }
</View>
);
}
}
class Favorites extends React.Component {
constructor(props) {
super(props);
this.state = {
circleCount: 0
}
}
componentDidMount() {
for(let i = 0; i <= this.props.screenProps.appstate.length; i++) {
setTimeout(() => {
this.addCircle();
}, (i*500));
}
}
addCircle = () => {
this.setState((prevState) => ({circleCount: prevState.circleCount + 1}));
}
render() {
var favoritesList = this.props.screenProps.appstate;
circles = favoritesList.map((item) => {
return (
<Circle key={item.url} style={styles.testcontainer}>
<TouchableOpacity onPress={() => {
Alert.alert( "Add to cart and checkout?",
item.item_name + "? Yum!",
[
{text: 'Yes', onPress: () => console.log(item.cust_id)},
{text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'}
]
)}}>
<Image source={{uri: item.url}} />
</TouchableOpacity>
</Circle>
)});
return (
<ScrollView}>
<View>
<View>
{circles}
</View>
</View>
</ScrollView>
);
}
}