Looking for a way to append an activity indicator to the end of a ListView when the user has reached the end and the app is querying for more data from a server. I can add the indicator after the ListView but then it always show up.
Set the foreground color of the spinner (default is gray). It provides an option to show or hide the indicator when there is no animating (true by default).
renderItem({ item, index, separators }); Takes an item from data and renders it into the list.
React Native ActivityIndicator is a component for displaying loading action. It is the same as the circular loader/Progress Bar. It is used to show the progress of long-running task so that the user can understand something is in progress.
You should be able to achieve that by using the onEndReached
prop for A ListView. When you reach the end you can render the loader. In my case I used renderFooter
to render the loader at the bottom of the list. In my scenario
You can set in the component state an attribute called messagesLoading
that you set to true when you start fetching new data and to false when done. Based on that, you can display or not the loading indicator in the footer.
This example partial implementation should give you an idea of how you can do it:
class ThreadDetail extends React.Component {
constructor () {
super()
this.state = {
loading: false
}
}
loadMoreMessages () {
this.setState({ loading: true })
fetchMessagesFromApi()
.then(() => {
this.setState({ loading: false })
})
.catch(() => {
this.setState({ loading: false })
})
}
renderFooter () {
return this.state.loading ? <View><Text>Loading...</Text></View> : null
}
render () {
return <ListView
renderRow={message => <Message message={message}/>}
dataSource={this.state.dataSource}
renderFooter={this.renderFooter.bind(this)}
onEndReached={this.loadMoreMessages.bind(this)}
onEndReachedThreshold={10}
scrollEventThrottle={150} />
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With