3

I adding image of screen, this work in part of screen. The Contacts screen need to be main page and not screen1 but its didn't work if i replace between them. I adding the code, in 'LogedInNavigator' have there TabNavigator and DrawerNavigator - the 'Contants' page initializing from TabNavigator and part two - Screen1 with the side menu it's from DrawerNavigator - maybe it's doing the problem? enter image description here

LogedInNavigator.js

import.......
styles......

const LoggedInNavigator = TabNavigator(
  {
    Contacts: {screen: ContactScreen,},
    Chat: {screen: ChatScreen,},
    Dashbaord: {screen: DashbaordScreen,},
    Profile: {screen: ProfileScreen,},
    Search: {screen: SearchScreen,},
  }, 
  {
    initialRouteName: "Contacts", 
    tabBarPosition: "bottom",
    tabBarOptions: {
      showIcon: true,
      activeTintColor: 'white',
    }
  }
);

export default () => <LoggedInNavigator onNavigationStateChange={null} />

export const Drawer = DrawerNavigator ({
  Home:{
    screen: Screen1,
    navigationOptions: {
      drawer:{
        label: 'Home',
      },
    }
  },  
  Camera: {
    screen: Screen2,
    navigationOptions: {
      drawer:{
        label: 'Camera',
      },
    }
  }, 
}) 

Contants.js

class Contacts extends Component {
  componentDidMount() {
    // TBD loggedin should come from login process and removed from here
    const { loggedIn, getContacts } = this.props;
    loggedIn(1);
    getContacts();
  }

  render() {
    const Router = createRouter( () => ({})); //IDAN 
    const { navigation, avatar, contacts } = this.props;
    return (
      <NavigationProvider router={Router}>
        <View style={{flex:1}}>
          <ContactView
            navigation={navigation}
            avatar={avatar}
            contacts={contacts}
          />
         <Drawer />
        </View>
      </NavigationProvider>
    );
  }
}

const mapStateToProps = (state) => {
  return (
    {
      avatar: state.user.user.avatar,
      contacts: state.contacts.contacts,
    }
  );
};

export default connect(mapStateToProps, { loggedIn, getContacts })(Contacts);

Help me please..

Idan
  • 3,604
  • 1
  • 28
  • 33

4 Answers4

4

After a while, i want to answer on my own question (with react-navigation v2) everything inside <RootNavigator/>

const RootNavigator= createDrawerNavigator({ Tabs }, {
    contentComponent: SideMenu,
    drawerWidth: Dimensions.get('window').width * .75,
})

SideMenu:

class SideMenu extends Component {
   render() {
        return ( //...your side menu view )
   }
}

Tab:

export default createBottomTabNavigator({
    Menu: {
        screen: HomeStack,
        navigationOptions: {
            title: 'תפריט',
            tabBarIcon: ({ focused, tintColor }) => {
                return <Icon name={'home'} size={20} color={tintColor} />;
            },
        }
    },
    Dashboard: {
        screen: DashboardStack,
        navigationOptions: {
            title: 'בית',
            tabBarOnPress: ({ navigation, defaultHandler }) => handleTabPress(navigation, defaultHandler),
            tabBarIcon: ({ focused, tintColor }) => {
                return <Icon name={'dashboard'} size={20} color={'green'} />;
            },
        }
    },
    QuickView: {
        screen: QuickNav,
        navigationOptions: {
            title: 'מבט מהיר',
            tabBarIcon: ({ focused, tintColor }) => {
                return <Icon name={'short-list'} size={20} color={tintColor} />;
            },
        },
    },
    Chat: {
        screen: Chat,
        navigationOptions: {
            title: "צ'אט",
            tabBarIcon: ({ focused, tintColor }) => {
                return <Icon name={'chat'} size={20} color={tintColor} />;
            },
        },
    },
},
    {
        initialRouteName: 'Dashboard',
        tabBarOptions: {
            activeTintColor: 'green',
            labelStyle: {
                fontSize: 16,
                marginBottom: 3,
            },
        },
    },
)
Idan
  • 3,604
  • 1
  • 28
  • 33
2

For v5 onwards you can use drawer style

import deviceInfoModule from 'react-native-device-info';


 <Drawer.Navigator
          drawerStyle={{
            width: deviceInfoModule.isTablet()
              ? Dimensions.get('window').width * 0.55
              : Dimensions.get('window').width * 0.7,
          }}
Rajesh N
  • 6,198
  • 2
  • 47
  • 58
2

In react-navigation version 6, you can use the drawerStyle in the screenOptions prop in the Drawer.Navigator component to change the width and add styles. This applies the applied style to all screens in the navigator.

<Drawer.Navigator
  screenOptions: {{
    drawerStyle: {
      width: 240
    }
  }}
>

If you want the drawer to cover the entire screen, then import Dimensions from the react-native library and use Dimensions.get('window').width

import { Dimensions } from 'react-native'

<Drawer.Navigator
  screenOptions: {{
    drawerStyle: {
      width: Dimensions.get('window').width
    }
  }}
>

Refer to react-navigation drawer for more.

Farhan08
  • 21
  • 1
1

You can set the drawer width using Dimensions width. See the docs here

https://reactnavigation.org/docs/navigators/drawer

import { Dimensions } from 'react-native';

...

const { width } = Dimensions.get('screen');

...

export const Drawer = DrawerNavigator (
{
  Home:{
    screen: Screen1,
    navigationOptions: {
      drawer:{
        label: 'Home',
      },
    }
  },  
  Camera: {
    screen: Screen2,
    navigationOptions: {
      drawer:{
        label: 'Camera',
      },
    }
  }, 
},
{
  drawerWidth: width
});
DennisFrea
  • 1,112
  • 8
  • 10
  • It don't work... the Width mine to the menu after open..so its open it all of the width screen but it still on same place – Idan Nov 18 '17 at 16:12