React native 我的子卡如何在NavigationExperimental中实现自己的导航标题按钮?
NavigationHeader及其左右按钮在堆栈的根导航器卡中定义。如果我想让堆栈中的孩子实现他们自己的左键和右键操作呢?实现这一点的最佳方式是什么?当然,我不希望根导航器中出现巨大的if/else块,根导航器也不需要知道它的子实现React native 我的子卡如何在NavigationExperimental中实现自己的导航标题按钮?,react-native,navigator,React Native,Navigator,NavigationHeader及其左右按钮在堆栈的根导航器卡中定义。如果我想让堆栈中的孩子实现他们自己的左键和右键操作呢?实现这一点的最佳方式是什么?当然,我不希望根导航器中出现巨大的if/else块,根导航器也不需要知道它的子实现 render () { return ( <NavigationCardStack direction='horizontal' navigationState={this.props.navigati
render () {
return (
<NavigationCardStack
direction='horizontal'
navigationState={this.props.navigation}
onNavigate={this._handleNavigate.bind(this)}
renderOverlay={this._renderHeader.bind(this)}
renderScene={this._renderScene} />
)
}
_renderHeader(props) {
const showHeader = props.scene.route.title &&
(Platform.OS === 'ios' || props.scene.route.key === 'details');
if (showHeader) {
return (
<NavigationHeader
{...props}
renderTitleComponent={this._renderTitleComponent.bind(this)}
renderLeftComponent={this._renderLeftComponent.bind(this)}
renderRightComponent={this._renderRightComponent.bind(this)}
/>
);
}
return null;
}
_renderTitleComponent(props) {
return (
<NavigationHeader.Title>
{props.scene.route.title}
</NavigationHeader.Title>
);
}
_renderLeftComponent(props) {
const { dispatch, navigation } = this.props;
if (props.scene.route.key === 'chat_overview') {
return (
<TouchableHighlight
style={styles.buttonContainer}
onPress={this.props._handleMenu}>
<Text>Menu</Text>
</TouchableHighlight>
);
}
else if (props.scene.route.showBackButton) {
return (
<NavigationHeaderBackButton onNavigate={() => dispatch(popRoute(navigation.key))} />
);
}
return null;
}
render(){
返回(
)
}
_渲染器(道具){
const showHeader=props.scene.route.title&&
(Platform.OS=='ios'| | props.scene.route.key=='details');
如果(显示标题){
返回(
);
}
返回null;
}
_渲染器组件(道具){
返回(
{props.scene.route.title}
);
}
_renderLeftComponent(道具){
const{dispatch,navigation}=this.props;
如果(props.scene.route.key===“聊天概述”){
返回(
菜单
);
}
else if(道具、场景、路线、ShowBack按钮){
返回(
调度(popRoute(navigation.key))}/>
);
}
返回null;
}