我在使用 React Native 0.16 (Android) 时遇到了麻烦。
问题是如何将属性传递给属于<Navigator />
的Navigator.NavigationBar 的routeMapper。组件。
我的代码结构如下
class MyApp extends Component {
...
static NavigationBarRouteMapper = {
LeftButton(route, navigator, index, navState) {
// ### I want to call 'functionABC' here. What Should I do?
},
RightButton(route, navigator, index, navState) {
// ### I want to call 'functionABC' here. What Should I do?
},
Title(route, navigator, index, navState) {
// ### I want to call 'functionABC' here. What Should I do?
},
}
...
functionABC() {
...
}
...
render() {
return (
<View>
<Navigator
initialRoute={{
name: 'Main',
index: 0,
}}
renderScene={this.renderScene.bind(this)}
sceneStyle={{marginTop:50}}
navigationBar={
<Navigator.NavigationBar
routeMapper={MyApp.NavigationBarRouteMapper}
/>
}
ref="nav" />
</View>
);
}
最佳答案
您可以在每次使用函数时生成映射器对象,在您的代码中这可能只是:
class MyApp extends Component {
...
static NavigationBarRouteMapper = props => ({
LeftButton(route, navigator, index, navState) {
},
RightButton(route, navigator, index, navState) {
},
Title(route, navigator, index, navState) {
},
})
render() {
return (
<View>
<Navigator
initialRoute={{
name: 'Main',
index: 0,
}}
renderScene={this.renderScene.bind(this)}
sceneStyle={{marginTop:50}}
navigationBar={
<Navigator.NavigationBar
routeMapper={MyApp.NavigationBarRouteMapper(this.props)}
/>
}
ref="nav" />
</View>
);
}
关于javascript - react native : How to pass props to 'routeMapper' of 'Navigator.NavigationBar' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34730106/