Используя Navigator
, мне нужна правая кнопка, которая изменяет состояние представления верхнего уровня. Используя Navigator
и пользовательский NavigationBarRouteMapper
, я могу добиться всего этого, за исключением действия кнопки.
Используя эту реализацию Navigator
:
<Navigator
ref='navigator'
style={styles.appContainer}
initialRoute={{name: initialRootView.title, component: initialRootView.view}}
navigationBar={
<Navigator.NavigationBar
routeMapper={NavigationBarRouteMapper}
style={styles.navBar}
/>
}
configureScene={() => {
return Navigator.SceneConfigs.FloatFromRight;
}}
renderScene={(route, navigator) => {
if (route.component) {
// add `navigator` and `cache` as props to any top-level component that gets pushed
// onto the navigation stack.
return React.createElement(route.component, { navigator: navigator, cache: this.state.cache, ...route.props });
}
}}
/>
А это NavigationBarRouteMapper
:
var NavigationBarRouteMapper = {
RightButton: function(route, navigator, index, navState) {
console.log(route.component);
return (
<TouchableOpacity
onPress={route.component.onRightButton}
style={{width: 100, height: 44, justifyContent: 'center', alignItems: 'center'}}>
<Text>Right Button</Text>
</TouchableOpacity>
);
},
};
Это правильно отображает правую кнопку, и мой компонент верхнего уровня имеет функцию onRightButton
. Но почему его никогда не вызывают?
Выполняя некоторую отладку в контексте RightButton
, route.component.prototype.hasOwnProperty('onRightButton')
возвращает true
, а route.component.hasOwnProperty('onRightButton')
возвращает false
. Как это возможно? Что странного в возвращенной ссылке route.component
?
Любая помощь приветствуется.