React Native: Как передать реквизиты в "routeMapper" из "Navigator.NavigationBar"?
У меня проблемы с использованием React Native 0.16 (Android). Вопрос в том, как передать реквизиты в routeMapper Navigator.NavigationBar, которые принадлежат <Navigator />
составная часть.
Моя структура кода, как показано ниже
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>
);
}
1 ответ
Решение
Вы можете генерировать объект mapper каждый раз, используя функцию, в вашем коде это может быть просто:
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>
);
}