3

I Used "react-navigation": "^4.0.10", "react-navigation-drawer": "^2.3.2",

and implement a drawer and inside them, I added my item, one of them is "Call us" and it should open a phone so I used for it Linking and I don't know if that's a good way to invoke a function instead of Screen as default in RN-drawer

so I do that's But after click to this item my app crashed and stop to work!! so how can I achieve this?

const DrawerNavigator = createDrawerNavigator({
 ...
 CallUsDrawer: {
      screen: () => Linking.openURL(`tel:0597093830`),
      navigationOptions: {
        drawerLabel: 'call us',
        drawerIcon: () => <Icon name="ios-call" size={28} color="#1E558E" />,
      },
    },
 ...
}); 
Oliver D
  • 2,579
  • 6
  • 37
  • 80

2 Answers2

0

This is a wrong approach. You should create a contentcomponent for the createDrawerNavigator and there should be a <Button> or something for "call us". and in onPress of that component wright the logic Linking.openURL(tel:0597093830)

plese check,

https://reactnavigation.org/docs/en/drawer-navigator.html#providing-a-custom-contentcomponent

Sample

const drawerNavigator = createDrawerNavigator(
  {
   ... screens here
  },
  {
    contentComponent: MenuScreen,
    drawerWidth: 300
  }
);

where MenuScreen is a Componet

Adarsh
  • 2,219
  • 2
  • 23
  • 37
0

Use DrawerItem instead of Drawer.Screen. Complete Docs here. Example available in this Snack

Muhammad Muaz
  • 157
  • 1
  • 13
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Albert Logic Einstein Aug 29 '22 at 18:38