如何在react-native-navigation v2中将图标添加到sideMenu中?

时间:2019-02-07 10:50:42

标签: react-native-navigation-v2

我已经读了很多关于它的评论,但是我没有解决我的问题。 所以我的导航代码看起来像这样


    export function pushScreens() {
    Navigation.setRoot({
       root: {
    sideMenu: {
    id: 'sideMenu',
    left: {
    visible: true,
    component: {
      id: 'Drawer',
      name: SIDE_DRAWER,
    },
    },
    center: {
    bottomTabs: {
    children: [{
    stack: {
      children: [{
        component: {
          name: HOME_SCREEN,
          passProps: {
            text: 'Home'
          },
        }
      }],
      options: {
        bottomTab: {
          text: 'Home',
          icon: HomeIcon,
          testID: 'FIRST_TAB_BAR_BUTTON'
        },
      }
    }
    },
    {
    component: {
      name: PROFILE_SCREEN,
      passProps: {
        text: 'Profile'
      },
      options: {
        bottomTab: {
          text: 'Profile',
          icon: HomeIcon,
          testID: 'SECOND_TAB_BAR_BUTTON'
        },
      }
    }
    },
    {
    component: {
      name: POSTS_SCREEN,
      passProps: {
        text: 'Posts'
      },
      options: {
        bottomTab: {
          text: 'Posts',
          icon: HomeIcon,
          testID: 'SECOND_TAB_BAR_BUTTON'
        }
      }
    }
    }]
    }
    }
    }
    }
    });
    }

默认情况下,我可以从屏幕左侧拉出抽屉,但是如何添加图标呢?

1 个答案:

答案 0 :(得分:0)

在您希望有汉堡按钮的视图上,添加:

static get options() {
  topBar: {
    leftButtons: [
      {
        color: colors.white,
        id: TOOLBAR_HUMBERGER_BUTTON_ID,
        icon: require("../resources/hamburger_topBar_button.png")
      }
    ]
  };
return topBar;
}

然后像topBar的每个其他按钮一样处理它:

navigationButtonPressed({ buttonId }) {
  if (buttonId == TOOLBAR_HUMBERGER_BUTTON_ID) {
    Navigation.mergeOptions(SIDEMENU_ID, {
      sideMenu: {
        left: {
          visible: true
        }
      }
    });
  } 
}