Bac*_*kom 5 react-native react-native-ios react-navigation
抽屉式导航器位于stackNavigator中。
我将标题设置为none,并且我想在按下按钮时使标题部分起作用。
我写了下面的代码。
this.props.navigation.dispatch(DrawerActions.toggleDrawer());
没有错误发生。但是它什么也没做。
导航器代码如下所示:
navigator.js
const MainScene = createStackNavigator({
MainTab: {screen: MainTab},
OtherScene: {screen: OtherScene}
},{...})
const OtherScene: createStackNavigator({
DrawerScene: {screen: DrawerScene}
},{...})
const DrawerScene = createDrawerNavigator({
Page1: {screen: Page1},
Page2: {screen: Page2},
},{...})
Run Code Online (Sandbox Code Playgroud)
Header.js
_sideMenu() {
this.props.navigation.dispatch(DrawerActions.toggleDrawer());
}
render() {
return (
...
<TouchableOpacity
onPress={() => this._sideMenu()}>
<Image ... />
</TouchableOpacity>
...
)
}
Run Code Online (Sandbox Code Playgroud)
page1和page2都包含直接编写的标题。
Page1.js
render() {
return(
<View>
<Header navigation={this.props.navigation} />
...
</View>
)
}
Run Code Online (Sandbox Code Playgroud)
小智 6
试试这个 import { DrawerActions } from "react-navigation";
this.props.navigation.dispatch(DrawerActions.openDrawer());
this.props.navigation.dispatch(DrawerActions.closeDrawer());
| 归档时间: |
|
| 查看次数: |
2570 次 |
| 最近记录: |