如何在 CustomDrawerContent 中使用 props.navigation.closeDrawer()?(React Native)("@react-navigation/drawer": "^5.11.4")
How to use props.navigation.closeDrawer() inside a CustomDrawerContent?(React Native)("@react-navigation/drawer": "^5.11.4")
我当前场景的代码如下:
function DrawerNavigation(props) {
return (
<DrawerContentScrollView {...props}>
<TouchableOpacity
style={styles.colseIconContainer}
onPress={() => props.navigation.closeDrawer()}>
<IconButton
icon={({size}) => (
<Image
source={require('../../../resource/images/CloseIcon.png')}
style={{width: size, height: size}}
/>
)}
size={40}
/>
</TouchableOpacity>
</DrawerContentScrollView>
);
}
const Drawer = createDrawerNavigator();
export default function MyDrawer(props) {
return (
<Drawer.Navigator
drawerPosition="right"
drawerContent={() => <DrawerNavigation {...props} />}
drawerStyle={styles.drawerStyle}>
<Drawer.Screen
name="Home"
component={HomeScreen}
options={{swipeEnabled: true}}
initialParams={props.navigation}
/>
<Drawer.Screen name="Notifications" component={CommonUserComponent} />
</Drawer.Navigator>
);
}
错误是undefined is not an object (evaluating 'props.naviagtion.closeDrawer')
有什么办法吗??为了让它发挥作用!!
谢谢!!
替换这个
drawerContent={() => <DrawerNavigation {...props} />}
用这个
drawerContent={(props) => <DrawerNavigation {...props} />}
我当前场景的代码如下:
function DrawerNavigation(props) {
return (
<DrawerContentScrollView {...props}>
<TouchableOpacity
style={styles.colseIconContainer}
onPress={() => props.navigation.closeDrawer()}>
<IconButton
icon={({size}) => (
<Image
source={require('../../../resource/images/CloseIcon.png')}
style={{width: size, height: size}}
/>
)}
size={40}
/>
</TouchableOpacity>
</DrawerContentScrollView>
);
}
const Drawer = createDrawerNavigator();
export default function MyDrawer(props) {
return (
<Drawer.Navigator
drawerPosition="right"
drawerContent={() => <DrawerNavigation {...props} />}
drawerStyle={styles.drawerStyle}>
<Drawer.Screen
name="Home"
component={HomeScreen}
options={{swipeEnabled: true}}
initialParams={props.navigation}
/>
<Drawer.Screen name="Notifications" component={CommonUserComponent} />
</Drawer.Navigator>
);
}
错误是undefined is not an object (evaluating 'props.naviagtion.closeDrawer')
有什么办法吗??为了让它发挥作用!!
谢谢!!
替换这个
drawerContent={() => <DrawerNavigation {...props} />}
用这个
drawerContent={(props) => <DrawerNavigation {...props} />}