Reputation: 199
I am working on a broadcasting app, rendering the messages using the flatlist. I want to return from the bookmark screen to the flatlist screen, and scroll to the bookmarked index which I am getting from the bookmark scene. But the scroll is happening after few seconds of returning to the screen. I tried using redux but that doesn't help as well.
The below function is triggered on clicking on a bookmark item to find the index of the bookmarked message from the original list.
searchIndex = async (id) => {
let val = this.state.messages.findIndex(x=>x._id === id)
console.log(val)
this.props.navigation.navigate({
name:'BroadCastScreenTwo',
params: {jumpValue:val},
merge:true
})
}
The below function is called for changing the scroll index.
async componentDidMount(){
const unsubscribe = this.props.navigation.addListener('focus', async () => {
var val= this.props.route.params.jumpValue;
if(val !== null){
await this.flatListRef.scrollToIndex({
animated: true,
index: val,
});
}
});
unsubscribe;
}
Upvotes: 0
Views: 514