NavigatorIOS onRightButtonPress访问查看数据
问题描述:
我有一个视图,我希望用户能够选择多个项目。选择项目后,我希望他们点击右上角的完成,然后转到下一个屏幕。使用Swift我迷上了prepareForSegue和segue.destinationViewController来实现它。NavigatorIOS onRightButtonPress访问查看数据
使用React Native,我使用NavigatorIOS onRightButtonPress函数,但不确定如何访问View数据以在passProps中使用。
的代码目前看起来是这样的:
return (<NavigatorIOS
ref="nav"
style={styles.nav}
initialRoute={{
nav: this.refs.nav,
component: this.props.onSuccessView,
title: 'What Would You Like To Do?',
rightButtonTitle: 'Next',
onRightButtonPress:() => {this.refs.nav.navigator.push({
title: "Where To Go",
backButtonTitle: 'Back',
component: SuggestionsView
});
}
}}
/>);
我要的是this.props.onSuccessView.onRightButtonPress处理哪个组件应该叫并提供道具。这可能吗?
如果不是,我可以调用一个函数,如道具:this.props.onSuccessView.getProps()?
欢迎任何建议!
感谢
本
答
这种气味怪异。你确定这是你想要做的吗?为什么不传递来自父组件的回调,以便知道你在这里展示的孩子 - 然后你可以通过抓住孩子并对他们采取行动来为你提供所需的资源。
或者:查看NavigatorIOS的the example,看看路由器是如何使用的 - 弹出和推送方法确实觉得你更适合在这里做什么。
答
A.在初始分量
this.props.navigator.push({
title: 'title',
component: MyComponent,
rightButtonTitle: 'rightButton',
passProps: {
ref: (component) => {this.pushedComponent = component},
},
onRightButtonPress:() => {
// Access View Data
this.pushedComponent && this.pushedComponent.props.someObject...;
},
});
B.在推部件
替换onRightButtonPress FUNC推入部件。
componentDidMount: function() {
// get current route
var route = this.props.navigator.navigationContext.currentRoute;
// update onRightButtonPress func
route.onRightButtonPress = () => {
// Access View Data
this.props.someObject...
};
// component will not rerender
this.props.navigator.replace(route);
},
谢谢,它可能是一种气味。我不确定回调是如何工作的,你有任何例子吗?你的意思是类似于passProps:{route:this.props.route}或https://github.com/facebook/react-native/blob/master/Examples/UIExplorer/createExamplePage.js? 我的想法是,我希望视图本身能够对下一步和下一步的数据负责,而不是对视图进行初始化。 –