我相信我正确地执行了代码,但是当我单击其中之一时,什么也没发生 当打开它而不与抽屉链接时,它的工作正常,但是当其与抽屉链接时,可触摸的不透明性将不起作用
这是我的app.js代码:
"text"
我的抽屉代码:
const Navigator = createStackNavigator({
Home:{screen: Home},
mp:{screen: mp},
ch:{screen: ch},
map:{screen:map},
mn:{screen: mn},
rr:{screen: rr},
drawer:{screen: drawer,navigationOptions: { header: null }},
});
const App = createAppContainer(Navigator);
export default App;
以及抽屉中打开的页面代码,当我使用touchableopacity时我无法导航:
const Header =({name, openDrawer})=> (
<View style={styles.header}>
<TouchableOpacity onPress={()=>openDrawer()}>
<Ionicons name="ios-menu" size={32} />
</TouchableOpacity>
<Text>{name}</Text>
<Text style={{width:50}}></Text>
</View>
)
const Profile = ({navigation}) => (
<View style={styles.container}>
<Header name="Profile" openDrawer={navigation.openDrawer}/>
<Image source ={require("../assets/img.png")} style={{width:"80%", height:"30%"}} resizeMode="contain"/>
<Text style={{padding:20}}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam sit amet dictum sapien, nec viverra orci. Morbi sed maximus purus. Phasellus quis justo mi. Nunc ut tellus lectus.
</Text>
<Text style={{padding:20}}>
In eleifend, turpis sit amet suscipit tincidunt, felis ex tempor tellus, at commodo nunc massa rhoncus dui. Vestibulum at malesuada elit.
</Text>
</View>
)
const Settings = ({navigation}) => (
<View style={styles.container}>
<Header name="Settings" openDrawer={navigation.openDrawer}/>
<Image source ={require("../assets/img.png")} style={{width:"80%", height:"30%"}} resizeMode="contain"/>
<Text style={{padding:20}}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam sit amet dictum sapien, nec viverra orci. Morbi sed maximus purus. Phasellus quis justo mi. Nunc ut tellus lectus.
</Text>
<Text style={{padding:20}}>
In eleifend, turpis sit amet suscipit tincidunt, felis ex tempor tellus, at commodo nunc massa rhoncus dui. Vestibulum at malesuada elit.
</Text>
</View>
)
function Item({ item, navigate }) {
return (
<TouchableOpacity style={styles.listItem} onPress={()=>navigate(item.name)}>
<Ionicons name={item.icon} size={32} />
<Text style={styles.title}>{item.name}</Text>
</TouchableOpacity>
);
}
class Sidebar extends React.Component {
state = {
routes:[
{
name:"Home",
icon:"ios-home"
},
{
name:"Profile",
icon:"ios-contact"
},
{
name:"Settings",
icon:"ios-settings"
},
]
}
render(){
return (
<View style={styles.container}>
<Image source={require("../assets/img.png")} style={styles.profileImg}/>
<Text style={{fontWeight:"bold",fontSize:16,marginTop:10}}>Janna Doe</Text>
<Text style={{color:"gray",marginBottom:10}}>janna@doe.com</Text>
<View style={styles.sidebarDivider}></View>
<FlatList
style={{width:"100%",marginLeft:30}}
data={this.state.routes}
renderItem={({ item }) => <Item item={item} navigate={this.props.navigation.navigate}/>}
keyExtractor={item => item.name}
/>
</View>
)
}
}
const Drawer = createDrawerNavigator(
{
Home:{ screen: menu},
Profile:{ screen: Profile},
Settings:{ screen: Settings}
},
{
initialRouteName: "Home",
unmountInactiveRoutes: true,
headerMode: "none",
contentComponent: props => <Sidebar {...props} />
}
)
const AppNavigator = createStackNavigator(
{
Drawer : {screen: Drawer},
},
{
initialRouteName: "Drawer",
headerMode: "none",
unmountInactiveRoutes: true
}
)
const AppContainer = createAppContainer(AppNavigator);
export default class drawer extends React.Component {
render(){
return (
<AppContainer />
);
}
}