I'm currently utilizing stack navigation in my application, but I have made the decision to add a Drawer for the user's menu.
While I was able to incorporate the Drawer into my pages, some of them contain MapView content, causing the user to be unable to drag the menu from the screen. To solve this issue, I opted to implement a button that calls the ToggleDrawer function, as outlined in the documentation. However, I am encountering the following error:
TypeError: navigation.ToggleDrawer is not a function. (In 'navigation.ToggleDrawer()', 'navigation.ToggleDrawer' is undefined)
Below is the section of my map screen where I attempted to include the button like so:
onPress={() => navigation.ToggleDrawer()}
If I remove the <any>
from useNavitation(), I receive the following message:
Property 'ToggleDrawer' does not exist on type 'NavigationProp
export default function IncidentsMap() {
const navigation = useNavigation<any>();
return (
<View style={styles.container}>
{typeof location?.coords.latitude == 'number' ?
<View style={styles.container}>
<MapView
provider={PROVIDER_GOOGLE}
style={styles.map}
>
<Callout tooltip={true} onPress={handleNavigateToIncidentDetails}>
<View style={styles.calloutContainer}>
<Text style={styles.calloutText}>Enchente rasa</Text>
</View>
</Callout>
</Marker>
</MapView>
<View style={styles.footer}>
<Text style={styles.footerText}>Reporte um incidente</Text>
<RectButton style={styles.createFloodButton} onPress={handleNavigateToCreateIncident}>
<Feather name='plus' size={20} color={'#fff'}/>
</RectButton>
</View>
<View style={styles.menuContainer}>
<RectButton style={styles.menuButton} onPress={() => navigation.ToggleDrawer()}>
<Feather name='menu' size={20} color={'#fff'}/>
</RectButton>
</View>
</View> : <View style={styles.container}>
<Text>Loading... Loading... Loading... Loading... Loading...
Loading </Text>
</View>}
</View>
);
}
Here is my routes file:
export default function Routes() {
return(
<NavigationContainer>
<Navigator screenOptions={{headerShown: false}}>
<Screen name={'MyDrawer'} component={DrawerImported}/>
{/*<Screen name="GetLocationTest" component={GetLocationTest}/>*/}
<Screen name="WelcomePage" component={WelcomePage}/>
<Screen name="WelcomePageStep2" component={WelcomePageStep2}/>
<Screen name="IncidentsMap" component={IncidentsMap}/>
<Screen name="IncidentDetails"
component={IncidentDetails}
options={{
headerShown: true,
header: () => <Header showCancel={false} title="Incidente"/>
}}
/>
<Screen name="SelectIncidentLocation" component={SelectIncidentLocation}
options={{
headerShown: true,
header: () => <Header title="Selecione no Mapa" showCancel={false}/>
}}
/>
<Screen name="IncidentData" component={IncidentData}/>
<Screen name="Profile" component={Profile}/>
<Screen name="Settings" component={Settings}
options={{
headerShown: true,
header: () => <Header title="Configurações" showCancel={false}/>
}}
/>
</Navigator>
</NavigationContainer>
)
}
Here is my DrawerFile:
interface Props {
navigation: any
}
export function DrawerImported(props) {
const paperTheme = useTheme();
function CustomDrawerContent(props) {
return (
<View style={{flex:1}}>
<DrawerContentScrollView {...props}>
<View style={styles.drawerContent}>
<View style={styles.userInfoSection}>
<View style={{flexDirection:'row',marginTop: 15}}>
<Avatar.Image
source={{
uri: 'https://avatars.githubusercontent.com/u/47571680?v=4'
}}
size={50}
/>
<View style={{marginLeft:15, flexDirection:'column'}}>
<Title style={styles.title}>Vinícius Melo</Title>
</View>
</View>
</View>
<View style={styles.drawerSection}>
<DrawerItem
icon={({color, size}) => (
<Feather
name="map"
color={color}
size={size}
/>
)}
label="Mapa da região"
onPress={() => {props.navigation.navigate('IncidentsMap')}}
/>
<DrawerItem
icon={({color, size}) => (
<Feather
name="user"
color={color}
size={size}
/>
)}
label="Profile"
onPress={() => {props.navigation.navigate('Profile')}}
/>
<DrawerItem
icon={({color, size}) => (
<Feather
name="settings"
color={color}
size={size}
/>
)}
label="Configurações"
onPress={() => {props.navigation.navigate('Settings')}}
/>
<DrawerItem
icon={({color, size}) => (
<Feather
name="alert-triangle"
color={color}
size={size}
/>
)}
label="Reportar Bug"
onPress={() => {props.navigation.navigate('BugReport')}}
/>
</View>
</View>
</DrawerContentScrollView>
<View style= {styles.bottomDrawerSection}>
<DrawerItem
icon={({color, size}) => (
<Feather
name="log-out"
color={color}
size={size}
/>
)}
label="Log Out"
onPress={() => {}}
/>
</View>
</View>
);
}
const Drawer = createDrawerNavigator();
return (
<Drawer.Navigator drawerContent={props => <CustomDrawerContent {...props} />}>
<Drawer.Screen name="Map" component={IncidentsMap}/>
<Drawer.Screen name="Settings" component={Settings}/>
<Drawer.Screen name="Profile" component={Profile}/>
<Drawer.Screen name="BugReport" component={BugReport}/>
</Drawer.Navigator>
);
}
function MyDrawer() {
return(
<MyDrawer/>
);
}
How do I properly call this Drawer on my screen?