I get an error when I pull down to refresh.
The code is something like this-
loadData: function(){
var _this = this;
this.API();
//check if data is loaded
setTimeout(function(){
if(_this.isMounted()){
if(_this.state.loaded===false){
_this.setState({
isReloadRequired: true
})
}
}
}, 10000);
},
API: function(){
var _this = this;
this.setState({ rawData: [], isReloadRequired: false, loaded: false, isRefreshing: true });
Parse.Cloud.run('fetchBookingListForUserCloudFunction', {
user_id: Parse.User.current().getUsername()
}).then(
function(result){
var cleanData = [];
for(var i=0;i<result.length;i++){
cleanData.push(result[i].toJSON());
}
_this.setState({
rawData: _this.state.rawData.concat(cleanData),
dataSource: _this.state.dataSource.cloneWithRows(cleanData),
loaded: true,
isReloadRequired: false,
isRefreshing: false,
});
},
function(error){
_this.setState({ isReloadRequired: true, loaded: false, isRefreshing: false })
console.log("[HOME API] Error: "+ JSON.stringify(error, null, 2));
}
);
},
render: function(){
return(
{this.state.loaded ? this.renderListView() : this.renderLoadingView()}
)
},
renderListView: function(){
if(this.state.rawData.length === 0){
return(
<View style={styles.container}>
<Text>Tap to book.</Text>
</View>
);
}
return(
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderReservation}
style={styles.listView}
refreshControl={
<RefreshControl
refreshing={this.state.isRefreshing}
onRefresh={this.loadData}
/>
}
/>
);
},
renderLoadingView: function(){
return(
<View style={styles.container}>
<LoadingView />
</View>
)
},
What is going wrong? I'm not able to find anything on github either. What is going wrong? I'm not able to find anything on github either.
UPDATED
Hi. Thanks for creating a sample on rnplay. But I have narrowed down the cause of the problem to this- Whenever I use RefreshControl
and ListView
inside render()
it works as expected. But when I return ListView
with RefreshControl
from some other function like renderlistView()
, it throws the aforementioned error. I even tried this.loadData().bind(this)
but that does not help either.