react-navigation icon indicating copy to clipboard operation
react-navigation copied to clipboard

Remove Margin/Spacing from DrawerList/Drawer Items

Open Eunanibus opened this issue 6 years ago • 11 comments

Current Behavior

  • I'm struggling to find in the documentation, a way to make Drawer items full width (or remove the DrawerList margins)

image

Expected Behavior

I'd like to remove the margin spacing either side of each item in order to consume the width of the drawer.

Your Environment

software version
iOS or Android 14
@react-navigation/native 5.8.1
@react-navigation/drawer 5.10.1
react-native-reanimated 1.13.1
react-native-gesture-handler 1.8.0
react-native-safe-area-context 3.1.8
react-native-screens 2.12.0
react-native 0.63.3
expo N/A
node 14.15.0
npm or yarn npm

Eunanibus avatar Oct 30 '20 19:10 Eunanibus

The versions mentioned in the issue for the following packages differ from the latest versions on npm:

  • @react-navigation/native (found: 5.8.1, latest: 5.8.2)
  • @react-navigation/drawer (found: 5.10.1, latest: 5.10.2)

Can you verify that the issue still exists after upgrading to the latest versions of these packages?

github-actions[bot] avatar Oct 30 '20 19:10 github-actions[bot]

For those who found this looking for the similar problem, it turns out that despite the inspector indicating this margin comes from the DrawerItemList component, it actually comes from the styling for the DrawerItem itself.

So, when you pass drawerContentOptions to your navigator:

        drawerContentOptions={{
          activeTintColor: '#cccccc',
          itemStyle: {
            marginHorizontal: 0,
            borderRadius: 0
          },

marginHorizontal is the property I needed to add here.

Eunanibus avatar Oct 30 '20 19:10 Eunanibus

Hi @Eunanibus , I'm trying to do the same thing today but the API has changed and I can't get anything to work. Did you replicate this with react-navigation version 6 ?

bobOnGitHub avatar Feb 06 '23 13:02 bobOnGitHub

Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro.

github-actions[bot] avatar Feb 06 '23 13:02 github-actions[bot]

@bobOnGitHub Use marginHorizontal: 0 on drawerItemStyle, that should do it - works for me!

SKempin avatar Feb 08 '23 19:02 SKempin

@SKempin, thanks for the reply.

Not the margin I was looking for. Issue #11204 shows the one I wanted: the margin is on a view inside the component drawerItemStyle modifies.

(I have since found a way of getting what I wanted but it uses react-native-paper's drawer.item which then requires reinventing the wheel on some of the inbuilt react-navigation functionality. Leaving #11204 open as it should be possible to remove the margin I'm interested in with react-navigation's api)

bobOnGitHub avatar Feb 09 '23 14:02 bobOnGitHub

In Drawertem in LabelStyle define marginLeft negative like this

   <DrawerItem
          icon={() => (
            <MaterialIcons
              name="attach-money"
              size={getSize(20)}
              color={colors.green200}
            />
          )}
          onPress={() => null}
          labelStyle={styles.itemText}
          label={t('drawer.raceHistory')}
        />
   itemText: {
     fontSize: layout.fontSize.title,
     color: colors.green200,
     marginLeft:-25
    
     // fontWeight:"bold"
 }

YuriLima23 avatar May 17 '23 20:05 YuriLima23

@YuriLima23 I figured that out as well, but it isn't a great solution to this issue, the package should just provide us with the ability to target the styling of all the relevant default styles for DrawerItem and not have to override hardcoded values with negative margins on other elements.

mattaningram avatar Jul 14 '23 18:07 mattaningram

Add PaddingStart as 0 in content container style if using custom component.

<DrawerContentScrollView
        bounces={false}
        contentContainerStyle={{
          marginLeft: 0,
          paddingStart: 0,
          paddingEnd: 0,
          backgroundColor: 'blue',
        }}
      >

sirus-max avatar Feb 03 '25 11:02 sirus-max

Add PaddingStart as 0 in content container style if using custom component.

<DrawerContentScrollView
        bounces={false}
        contentContainerStyle={{
          marginLeft: 0,
          paddingStart: 0,
          paddingEnd: 0,
          backgroundColor: 'blue',
        }}
      >

That's what I was looking for! Thank you

MarcelinaZiolkiewicz avatar Feb 04 '25 17:02 MarcelinaZiolkiewicz

marginLeft: 0, paddingStart: 0, paddingEnd: 0,

This is work for me too 👌

Anamcoollzz avatar Oct 26 '25 18:10 Anamcoollzz