如何防止汉堡菜单替换后退按钮?
How to prevent hamburger menu replace over back button?
我一直在使用:
react-native-router-flux v4.0.6
反应 v16.6.3
react-native v0.57.8
我有一个简单的问题。
我有两个组成部分:Listing.js 和 Detail.js
我有一个抽屉菜单。问题是,当用户点击清单中的详细信息按钮时,下一页汉堡菜单图标仍然存在。
但我想将汉堡包菜单更改为后退按钮。
<Router sceneStyle={{ marginTop: 15 }}>
<Scene
contentComponent={SideMenu}
drawerWidth={280}
drawerPosition={'left'}
drawerImage={require('./hamburger.png')}
initial
drawer
>
<Scene key='main'>
<Scene key='list' component={Listing} title='Albüm APP' initial />
<Scene key='detail' component={Detail} title='Albüm Detay' />
</Scene>
</Scene>
</Router>
问题在这里:
这里我想做的是:
您似乎可以使用自定义导航栏覆盖默认导航栏
import React from 'react';
import { Scene, Router } from 'react-native-router-flux';
import mainScreen from './components/mainScreen';
import challengeScreen from './components/challengeScreen';
import NavBar from './components/NavBar';
const RouterComponent = () => {
return (
<Router>
<Scene key="root">
<Scene key="homeScreen" component={mainScreen} hideNavBar={1} />
<Scene
key="screen2" component={challengeScreen} navTransparent={1}
navBar={NavBar}
/>
</Scene>
</Router>
);
};
export default RouterComponent;
// NavBar.js
import {
View, Image, StatusBar, TouchableWithoutFeedback
} from 'react-native';
import React, { Component } from 'react';
import { Actions, Router, Scene } from 'react-native-router-flux';
class NavBar extends Component {
render() {
return (
<View style={styles.backgroundStyle}>
<StatusBar />
<View style={{ flexDirection: 'row' }}>
<TouchableWithoutFeedback onPress={() => Actions.homeScreen()}>
<Image
source={require('./Images/back-arrow.png')}
style={styles.backarrowStyle} />
</TouchableWithoutFeedback>
<Image
source={require('./Images/help.png')}
style={styles.helpStyle} />
<Image
source={require('./Images/setting.png')}
style={styles.settingStyle} />
</View>
</View>
);
}
}
const styles = {
backgroundStyle: {
backgroundColor: 'transparent'
},
backarrowStyle: {
resizeMode: 'contain',
flexDirection: 'row',
width: 50,
height: 50,
left: 0,
justifyContent: 'flex-start'
},
helpStyle: {
resizeMode: 'contain',
width: 50,
height: 50,
left: 220,
justifyContent: 'flex-end',
position: 'relative'
},
settingStyle: {
resizeMode: 'contain',
width: 50,
height: 50,
justifyContent: 'flex-end',
position: 'relative',
left: 210
}
};
export default NavBar;
您是否尝试过将道具 back
添加到您的 detail
场景中?
<Scene
key='detail'
component={Detail}
title='Albüm Detay'
back
/>
来自关于 back
prop
的文档
If it is true back button is displayed instead of left/drawer button defined by upper container.
我一直在使用:
react-native-router-flux v4.0.6
反应 v16.6.3
react-native v0.57.8
我有一个简单的问题。 我有两个组成部分:Listing.js 和 Detail.js
我有一个抽屉菜单。问题是,当用户点击清单中的详细信息按钮时,下一页汉堡菜单图标仍然存在。
但我想将汉堡包菜单更改为后退按钮。
<Router sceneStyle={{ marginTop: 15 }}>
<Scene
contentComponent={SideMenu}
drawerWidth={280}
drawerPosition={'left'}
drawerImage={require('./hamburger.png')}
initial
drawer
>
<Scene key='main'>
<Scene key='list' component={Listing} title='Albüm APP' initial />
<Scene key='detail' component={Detail} title='Albüm Detay' />
</Scene>
</Scene>
</Router>
问题在这里:
这里我想做的是:
您似乎可以使用自定义导航栏覆盖默认导航栏
import React from 'react';
import { Scene, Router } from 'react-native-router-flux';
import mainScreen from './components/mainScreen';
import challengeScreen from './components/challengeScreen';
import NavBar from './components/NavBar';
const RouterComponent = () => {
return (
<Router>
<Scene key="root">
<Scene key="homeScreen" component={mainScreen} hideNavBar={1} />
<Scene
key="screen2" component={challengeScreen} navTransparent={1}
navBar={NavBar}
/>
</Scene>
</Router>
);
};
export default RouterComponent;
// NavBar.js
import {
View, Image, StatusBar, TouchableWithoutFeedback
} from 'react-native';
import React, { Component } from 'react';
import { Actions, Router, Scene } from 'react-native-router-flux';
class NavBar extends Component {
render() {
return (
<View style={styles.backgroundStyle}>
<StatusBar />
<View style={{ flexDirection: 'row' }}>
<TouchableWithoutFeedback onPress={() => Actions.homeScreen()}>
<Image
source={require('./Images/back-arrow.png')}
style={styles.backarrowStyle} />
</TouchableWithoutFeedback>
<Image
source={require('./Images/help.png')}
style={styles.helpStyle} />
<Image
source={require('./Images/setting.png')}
style={styles.settingStyle} />
</View>
</View>
);
}
}
const styles = {
backgroundStyle: {
backgroundColor: 'transparent'
},
backarrowStyle: {
resizeMode: 'contain',
flexDirection: 'row',
width: 50,
height: 50,
left: 0,
justifyContent: 'flex-start'
},
helpStyle: {
resizeMode: 'contain',
width: 50,
height: 50,
left: 220,
justifyContent: 'flex-end',
position: 'relative'
},
settingStyle: {
resizeMode: 'contain',
width: 50,
height: 50,
justifyContent: 'flex-end',
position: 'relative',
left: 210
}
};
export default NavBar;
您是否尝试过将道具 back
添加到您的 detail
场景中?
<Scene
key='detail'
component={Detail}
title='Albüm Detay'
back
/>
来自关于 back
prop
If it is true back button is displayed instead of left/drawer button defined by upper container.