【发布时间】:2015-12-11 12:38:35
【问题描述】:
我似乎在我的代码中缓慢加载数据时绊倒了,这阻止了我的映射自定义组件在渲染帧之前渲染 - 留下相当长的空白时间。我只是获取 rss 提要数据,对其进行解析,并根据其 json 内容制作自定义组件。这是我的代码:
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
}
*/
});
我很想深入研究有助于加载数据然后渲染结果的方法,而不是在数据真正及时格式化之前立即渲染。特别是 slice readings.slice(0,4).map(function(article, i).. 函数应该处理的 rss 提要不止 4 个案例 - 我需要它能够处理所有这些,或者至少当我向下滚动时,所有这些都是部分的。
【问题讨论】:
标签: javascript rss loading react-native custom-component