you have to Use
REF = {_抽屉=>(this.drawer = _drawer)}
import React, { Component } from "react";
import {
Text,
View,
DrawerLayoutAndroid,
TouchableHighlight
} from "react-native";
export default class DrawerExample extends Component {
constructor() {
super();
this.openDrawer = this.openDrawer.bind(this);
}
openDrawer() {
this.drawer.openDrawer();
}
render() {
var navigationView = (
<View style={{ flex: 1, backgroundColor: "#fff" }}>
<Text style={{ margin: 10, fontSize: 15, textAlign: "left" }}>
I'm in the Drawer!
</Text>
</View>
);
return (
<DrawerLayoutAndroid
drawerWidth={300}
ref={_drawer => (this.drawer = _drawer)}
drawerPosition={DrawerLayoutAndroid.positions.Left}
renderNavigationView={() => navigationView}
>
<View style={{ flex: 1, alignItems: "center" }}>
<Text style={{ margin: 10, fontSize: 15, textAlign: "right" }}>
Hello
</Text>
<Text style={{ margin: 10, fontSize: 15, textAlign: "right" }}>
World!
</Text>
<TouchableHighlight onPress={this.openDrawer}>
<Text>{"Open Drawer"}</Text>
</TouchableHighlight>
</View>
</DrawerLayoutAndroid>
);
}
}
谢谢,我已经知道了使用正常功能视图里面,但我会给你一个不管怎么说,因为它可以帮助其他人 –