Skip to content

Commit 3a63950

Browse files
navioceankelset
authored andcommitted
Add custom style for DrawerItem (react-navigation#2764)
* Add custom style of DrawerItem * Update itemStyle to DrawerNavigator doc * rename style to itemsContainerStyle [BREAKING CHANGE] * update * update * fix issue comma * update DrawerNavigator-test
1 parent 4df002d commit 3a63950

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

docs/api/navigators/DrawerNavigator.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@ const styles = StyleSheet.create({
145145
- `inactiveTintColor` - label and icon color of the inactive label
146146
- `inactiveBackgroundColor` - background color of the inactive label
147147
- `onItemPress(route)` - function to be invoked when an item is pressed
148-
- `style` - style object for the content section
148+
- `itemsContainerStyle` - style object for the content section
149+
- `itemStyle` - style object for the single item, which can contain an Icon and/or a Label
149150
- `labelStyle` - style object to overwrite `Text` style inside content section, when your label is a string
150-
151151
#### Example:
152152

153153
```js
154154
contentOptions: {
155155
activeTintColor: '#e91e63',
156-
style: {
156+
itemsContainerStyle: {
157157
marginVertical: 0,
158158
}
159159
}

src/navigators/__tests__/__snapshots__/DrawerNavigator-test.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ exports[`DrawerNavigator renders successfully 1`] = `
136136
Object {
137137
"backgroundColor": "rgba(0, 0, 0, .04)",
138138
},
139+
undefined,
139140
]
140141
}
141142
>

src/views/Drawer/DrawerNavigatorItems.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ type Props = {
2626
getLabel: (scene: DrawerScene) => ?(React.Element<*> | string),
2727
renderIcon: (scene: DrawerScene) => ?React.Element<*>,
2828
onItemPress: (info: DrawerItem) => void,
29-
style?: ViewStyleProp,
29+
itemsContainerStyle?: ViewStyleProp,
30+
itemStyle?: ViewStyleProp,
3031
labelStyle?: TextStyleProp,
3132
};
3233

@@ -44,10 +45,11 @@ const DrawerNavigatorItems = ({
4445
getLabel,
4546
renderIcon,
4647
onItemPress,
47-
style,
48+
itemsContainerStyle,
49+
itemStyle,
4850
labelStyle,
4951
}: Props) => (
50-
<View style={[styles.container, style]}>
52+
<View style={[styles.container, itemsContainerStyle]}>
5153
{items.map((route: NavigationRoute, index: number) => {
5254
const focused = activeItemKey === route.key;
5355
const color = focused ? activeTintColor : inactiveTintColor;
@@ -65,7 +67,7 @@ const DrawerNavigatorItems = ({
6567
}}
6668
delayPressIn={0}
6769
>
68-
<View style={[styles.item, { backgroundColor }]}>
70+
<View style={[styles.item, { backgroundColor }, itemStyle]}>
6971
{icon ? (
7072
<View style={[styles.icon, focused ? null : styles.inactiveIcon]}>
7173
{icon}

0 commit comments

Comments
 (0)