【发布时间】:2015-06-30 08:35:05
【问题描述】:
我正在使用呈现新闻帖子的 Navigator 对象。
这个想法是您正在查看单个新闻帖子,您可以左右滑动查看下一个和上一个帖子。例如,当您向右滑动时,它会滑动到下一个帖子。我想要的是当我滑动到下一个帖子时,我想再次加载该帖子的下一个帖子,这样你就可以继续滑动。
我给这些道具:
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
}
所以问题是,我该如何正确处理这个问题?我做错了什么?如何确保我可以继续在列表中滑动?
【问题讨论】:
标签: javascript ios react-native