如何在 react-native-navigation v2 中向我的侧边菜单添加图标?
How I could add an icon to my sideMenu in 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'
}
}
}
}]
}
}
}
}
});
}
默认情况下,我可以从屏幕左侧拉出抽屉,但我该如何为其添加图标?
在您希望有汉堡包按钮的视图中,添加:
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
}
}
});
}
}
我看了很多关于它的评论,但我没有解决我的问题。 所以我的导航代码看起来像这样
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' } } } }] } } } } }); }
默认情况下,我可以从屏幕左侧拉出抽屉,但我该如何为其添加图标?
在您希望有汉堡包按钮的视图中,添加:
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
}
}
});
}
}