1
我似乎在缓慢加载数据,这会阻止我的映射自定义组件在渲染帧之前进行渲染 - 在相当长的时间内留出空白空间。我简单地使用rss feed数据,解析它,并从json内容制作一个定制的组件。这里是我的代码:在加载React Native后渲染RSS Feed数据
module.exports = React.createClass({
/*
mixins : [
Reflux.listenTo(FeedStore, 'onChange')
],
*/
componentWillMount: function() {
Parse.User.currentAsync()
.then((user) => { this.setState({user: user}); })
//get the latest articles on page load
//this will pre-fill out articles state
FeedStore.getArticles()
.then((data) => {
this.setState({ articles: data });
});
},
getInitialState: function() {
return {
user: null,
username: null,
articles: [],
}
},
render: function() {
var readings = this.state.articles;
return (
<ScrollView>
<ArticleView
category={'Comedy'}
key={1}
heartText={'2.9k'}
categoryPress={this.dummy}
selected={false}
source={require('../img/test_view_1.png')}
text={'These 3 black comedians are finally being honored for the ways they paved & the history they made'}
onPress={this.dummy} />
<ArticleView
category={'City Life'}
key={2}
heartText={'299'}
categoryPress={this.dummy}
selected={false}
source={require('../img/test_view_2.png')}
text={'portland forecast: approaching weekend storm could rival halloween deluge'}
onPress={this.dummy} />
<ArticleView
category={'Music'}
key={3}
heartText={'250k'}
categoryPress={this.dummy}
selected={false}
source={require('../img/test_view_3.png')}
text={'kendrick lamar answers furgeson criticism with new song'}
onPress={this.dummy} />
{this.renderArticleFeed(readings)}
</ScrollView>
);
},
renderArticleFeed: function(readings) {
var that = this;
//call to api to get articles from rss/api var Articles =
return readings.slice(0,4).map(function(article, i) {
console.log("========================");
console.log(article.title);
console.log(article.mediaGroups[0].contents[0].thumbnails[0].url);
return <ArticleView
category={'Music'}
key={i}
heartText={'2.9k'}
categoryPress={that.dummy}
selected={false}
source={{uri: article.mediaGroups[0].contents[0].thumbnails[0].url }}
text={article.title}
onPress={that.dummy} />
});
},
dummy: function() {
},
/*
onChange: function(event, articles) {
this.setState({articles: articles}); //trigers re-render of component
}
*/
});
我很想深入研究方法与数据加载帮助,然后在渲染的结果 - 数据实际上是格式化时间前,而不是立刻呈现。特别是slices.slice(0,4).map(function(article,i)..函数应该处理的不仅仅是rss feed的4个例子 - 我需要它能够处理所有这些,或者至少所有这一切都在我向下滚动的部分