मैंने अनंत स्क्रॉल का एक न्यूनतम उदाहरण प्राप्त करने का प्रयास किया है।प्रतिक्रिया मूल अनंत स्क्रॉल
var React = require('react-native');
var {
StyleSheet,
View,
Image,
ListView,
} = React;
var data = [
{
"id": 1,
"profile_picture": {
"href": "//like1.r.worldssl.net/ui_big/1305634.jpg"
}
},
{
"id": 2,
"profile_picture": {
"href": "//like1.r.worldssl.net/ui_big/1305634.jpg"
}
},
{
"id": 3,
"profile_picture": {
"href": "//like1.r.worldssl.net/ui_big/1305634.jpg"
}
},
{
"id": 4,
"profile_picture": {
"href": "//like1.r.worldssl.net/ui_big/1305634.jpg"
}
},
{
"id": 5,
"profile_picture": {
"href": "//like1.r.worldssl.net/ui_big/1305634.jpg"
}
},
{
"id": 6,
"profile_picture": {
"href": "//like1.r.worldssl.net/ui_big/1305634.jpg"
}
}
];
var InfiniteScreen = React.createClass({
getInitialState: function() {
return {
isLoadingTail: false,
dataSource: new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 !== row2,
})
};
},
componentDidMount: function() {
this.setState({
dataSource: this.getDataSource(data)
});
},
renderRow: function (item) {
return (
<View>
<Image style={{width: 80, height: 80}} source={{uri: 'http:' + item.profile_picture.href}}/>
</View>
);
},
onEndReached: function() {
console.log('onEndReached', this.state.isLoadingTail);
if (this.state.isLoadingTail) {
// We're already fetching
return;
}
this.setState({
isLoadingTail: true
});
this.setState({
isLoadingTail: false,
dataSource: this.getDataSource(data)
});
},
getDataSource: function (users):ListView.DataSource {
return this.state.dataSource.cloneWithRows(users);
},
render: function() {
return (
<View>
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderRow}
onEndReached={this.onEndReached}
/>
</View>);
}
});
अगर मैं बहुत नीचे तक स्क्रॉल करें, onEndReached() निकाल दिया जाता है, लेकिन नए डेटा प्रकट नहीं होता है: तो मैं इस किया है। कोई विचार?
उत्तर बेहतर है और यह निश्चित रूप से समस्या का हल। लेकिन, वैसे भी, जिस कोड पर मैंने इशारा किया था वह टूटा हुआ है। प्रत्येक सेटस्टेट –
के बाद घटक फिर से प्रस्तुत नहीं करेगा, यह प्रश्न का उत्तर कैसे दे सकता है? –
ऐसा नहीं है, मुझे लगता है कि उस समय मेरे पास टिप्पणियां पोस्ट करने के लिए पर्याप्त कर्म नहीं था, इसलिए मैंने एक उत्तर पोस्ट किया। –