我正在使用呈現新聞帖子的導航器對象。React Native - 導航器更改路由
想法是,您正在查看單個新聞文章,並且您可以左右滑動查看下一篇文章和上一篇文章。例如,當您向右滑動時,會滑入下一篇文章。我想要的是當我滑動到下一篇文章時,我想再次加載該文章的下一篇文章,以便您可以繼續滑動。
我給這些道具:
getInitialState: function() {
return {
post: {},
routes: [this.props.prevPost, this.props.post, this.props.nextPost],
startRoute: this.props.post,
};
}
我的導航功能是這樣的:
render: function() {
var self = this;
return (
<Navigator
debugOverlay={false}
ref={(navigator) => {
this._navigator = navigator;
}}
onDidFocus={this.itemChangedFocus}
initialRoute={this.state.startRoute}
initialRouteStack={this.state.routes}
routeStack={this.state.routes}
renderScene={this.renderNewsItem}
configureScene={() => ({
...Navigator.SceneConfigs.HorizontalSwipeJump,
})} />
);
}
所以我的想法是onDidFocus,我看我現在的職位,我再搶上一和下一個帖子,並以某種方式(這裏是我卡住)觸發重新導航組件?
這是我itemChangedFocus函數的樣子:
// Route gives the current news item which has the focus
itemChangedFocus: function(route) {
// PostStore returns a posts array
// posts[0] = previousPost, posts[1] = currentPost, posts[2] = nextPost
let posts = PostStore.getPrevAndNextPost(route);
// This is probably wrong, but it did replace the nextPost in the route object
this.props.navigator.route.nextPost = posts[2];
// Now I need to trigger a rerender? I tried it with setState but that didn't work
}
所以現在的問題是,我該如何正確看待這一點?我做錯了什麼,我如何確保我可以繼續在列表中滑動?