react-native-vector-icons icon indicating copy to clipboard operation
react-native-vector-icons copied to clipboard

Remove padding from Icon

Open nzwnabdulwahid opened this issue 6 years ago • 14 comments

Good day everyone! I am currently trying to remove padding from the Icon but it seems like what ever I did the padding is still there.

screen shot 2018-07-16 at 2 14 58 pm

I am trying to push both of the arrow at the end of the container and this is my current code.

<View style={{zIndex:10, position: 'absolute', width:20, padding:0, margin:0, backgroundColor:'rgba(0,0,0,0)', justifyContent: 'space-between',alignSelf:'center'}}> <Icon name={"md-arrow-dropdown"} size={35} color="white" style={{padding:0, margin:0, backgroundColor:'red' }} /> <Icon name={"md-arrow-dropup"} size={35} color="white" style={{padding:0, margin:0, backgroundColor:'green'}} /> </View>

How can I achieve that ?

nzwnabdulwahid avatar Jul 16 '18 06:07 nzwnabdulwahid

Same problem, tried padding: 0, paddingTop: 0, etc - none of them worked

screen shot 2018-11-23 at 00 30 02

import Icon from 'react-native-vector-icons/Ionicons';

<TouchableOpacity>
    <Icon name="ios-close" size={30} style={styles.fileDeleteIcon} />
</TouchableOpacity>

fileDeleteIcon: {
    flex: 0,
    width: 20,
    height: 20,
    alignSelf: 'center',
    alignItems: 'center',
    justifyContent: 'center',
    textAlign: 'center',
    backgroundColor: '#e24c4b',
    color: 'white',
    margin: 0,
    padding: 0,
    paddingTop: 0,
}

sryze avatar Nov 22 '18 18:11 sryze

I have the same issue with a Materialcons icon. Forgive me for not setting the backgroundColor to red to show it, but if I do you can clearly see padding at the bottom. No amount of styling will recenter or remove/adjust the padding. I am placing this info icon at the end of text. It's not aligned and in a block of text it makes that particular line of text taller than the rest. The only way I can solve this is to make the icon smaller than the surrounding text, but then the icon is way too small and it is still not vertically aligned.

icon

I believe I know why this is occurring. It's because these are not graphics, they are basically fonts being placed to look like a graphic. Still, the documentation says it is possible to style them to move them around, but I am finding that not to be the case such as your two documented examples above. Also, other solutions provided by doing some Google searching have not worked. Such as wrapping them in a view.

Edit: I was finally able to solve my problem by getting the icon out of a Text element that was several layers up. I had to break up all my sections of text into many different Text containers. Now it is only wrapped by a View and I can do whatever I want with it. Still new at everything, so I have to get creative with Views to place it where I want.

screenshot_1544771228

themeadery avatar Dec 14 '18 06:12 themeadery

I have the same error here. I was thinking, maybe is a default character padding. What do you think about?

<MaterialCommunityIcons name="plus-circle" size={40} color={colors.primary} backgroundColor="#3b5998" style={{margin:0, padding:0}} />

luanccp avatar Jul 23 '19 15:07 luanccp

Try placing your component inside a "View" by passing the backgroundColor setting to it, then use negative numbers in the margin and padding (MaterialCommunityIcons) until you adjust the space between the edges. Ex:

captura

brenomaiacosta avatar Sep 27 '19 07:09 brenomaiacosta

phorensic in your case you can use (borderRadius: 50) after adjusting the spaces, as I explained for the luanccp.

Guys, I hope I collaborated with you :-)

brenomaiacosta avatar Sep 27 '19 07:09 brenomaiacosta

This is not a scalable solution

luisgurmendezMLabs avatar Jun 05 '20 17:06 luisgurmendezMLabs

U guys can use textAlign : center|left|right|top|bottom whatever suits u

Bsingh2697 avatar Jul 22 '20 05:07 Bsingh2697

same problem.

hengkx avatar Aug 10 '20 05:08 hengkx

Also having this issue, any help?

MichaelKim39 avatar Jan 23 '21 23:01 MichaelKim39

Same problem here folks, any news?

rhuankarlus avatar Jan 30 '21 19:01 rhuankarlus

Hello guys! Previously I presented a possible solution, but it is not a scalable solution as already mentioned. So I'm making a possible solution available to you. Hope this helps.

The secret is in defining the alignments in the parent component (TouchableOpacity), through "alignItens" and "JustifyContent".

Here is a possible solution: https://github.com/brenomaiacosta/solutionIssueRemovePaddingFromIcon774/blob/main/Solution.txt

Below is an example of several types of button content alignments: image image

brenomaiacosta avatar Feb 01 '21 18:02 brenomaiacosta

I encountered the same problem and I ended up using a wrapper to set the width and height to make the icon centered.

The wrapper component

import React from 'react';

function Icon({ size, style, iconClass, ...otherProps }) {
    const IconClass = iconClass;
    return (
        <IconClass
            {...otherProps}
            size={size}
            style={{ ...style, width: size, height: size }}
        />
    );
}

export default Icon;

An example using the wrapper component

import AntIcon from 'react-native-vector-icons/AntDesign';

function SomeComponent() {
    return (
        <Icon
            iconClass={AntIcon}
            name="setting"
            color="#000"
            size={20}
        />
    );
}

timfbfbfbfb avatar Jun 30 '21 10:06 timfbfbfbfb

I just use display: flex; on the parent element and it works.

joao-vasconcelos avatar Jun 28 '22 23:06 joao-vasconcelos

I use expo vector icons which I believe is based on react-native-vector-icons or vice versa. Anyway wrapping the icon in a view and setting it's width to the size of the icon worked for me:

    <View style={{ width: size }}>
      <Ionicons
        name={name}
        size={size}
        color={color || theme.primaryColor}
        style={style}
      />
    </View>

If you're dealing with extra vertical padding then you may also need to set the height of the view to the same size.

TowhidKashem avatar Aug 06 '22 16:08 TowhidKashem

I've just created a tool to remove padding around icon sets automatically. It requires you to create a new icon set, but it might be helpful: https://github.com/jgillick/IconsetCropper

jgillick avatar Mar 08 '23 00:03 jgillick