How to add side menu icon in wix-react-native-navigation v2?

4.5k views Asked by At

I am new to react-native. i want to add side menu icon like the following image enter image description here

in wix-react-native-navigation v1 was fairly simple. We need to just add

{
  tabs:[
    screen: "myscreenName",
    label: "MyLabel",
    icon: require('icon-url')
  ]
}

But in V2 documentation they said if you add to side menu use this but they didn't say about how to add icon.

{
  root: {
    sideMenu: {
      left: {
        component: {
          name: 'sideDrawer'
        }
      },
      center: {
        bottomTabs: {
          .....
        }
      }
    }
  }
}

As a result a side drawer is appear if i dragged from left side but the icon is missing. Any idea ho do i add a icon like this on wix-react-native-navigation v2

3

There are 3 answers

0
shojol80 On BEST ANSWER

You can check this link https://github.com/wix/react-native-navigation/issues/796

The hamburger button is no longer added by default since a lot of users asked to control when it's displayed and when not. In every screen you'd like to have the hamburger button, add it explicitly:

static navigatorButtons = { leftButtons: [ { id: 'sideMenu' } ] };

4
TheHound.developer On

You can try the below code. This creates a tab based screen. If you want as screen, you can use Navigation.startSingleScreenApp(...)

    Navigation.events().registerAppLaunchedListener(() => {
  Navigation.setRoot({
    root: {
      sideMenu: {
        id: "sideMenu",
        left: {
          component: {
            id: "Drawer",
            name: "navigation.Drawer"
          }
        },
        center: {
          stack: {
            id: "AppRoot",
            children: [{
              component: {
                id: "App",
                name: "navigation.AppScreen"
              }
            }]
          }
        }
      }
    }
  });
}
0
ketimaBU On

You can add this static function with different configs in your screen:

export default class Screen extends Component {

  static get options() {
    return {
      topBar: {
        title: {
          text: 'Screen',
        },
        leftButtons: [
          {
            icon: require('../../../assets/icons/burgerMenu.png'),
            id: 'toggleDrawer',
          },
        ],
      },
    };
  }
}

The complete list of options can be found in the docs in this link: topBar options