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

How to fill with color transparent place in icon

Open dennisbejencev-an opened this issue 7 years ago • 14 comments

For example, I have bookmark check icon, and needs transparent check mark fill with color Image I tried in this way, but looks so

<View style={{ backgroundColor: 'white', height: 35, width: 35}}>
    <MaterialIcons
       name  = 'bookmark-check'
       size  = {30}
       color = {'blue'}
    />
</View>

Image

dennisbejencev-an avatar Oct 25 '17 07:10 dennisbejencev-an

I have problems with this too! I'm using "logo-youtube" from Ionicons and I want the middle play triangle to be white while the surrounding part is red, however if I add a white backgroundColor there will be a white box around the icon, and changing the padding to 0 does nothing at all.

remisaado avatar Oct 27 '17 09:10 remisaado

Also having this issue with circle icons such as play-circle. Tried to add border radius and it doesn't seem to work (on iOS, using props, style, Text or View wrapper, or Icon.Button). So yeah, there's box behind the icon that would be nice to figure out how to not show.

douglas-mason avatar Nov 22 '17 03:11 douglas-mason

Don't think this is possible with the current implementation I'm afraid :-/

oblador avatar Jan 08 '18 22:01 oblador

did anyone got the solution for the above issue..please let me know..i am facing the same

sangeethanimapp avatar Aug 12 '18 07:08 sangeethanimapp

Also having this issue

lucas-dolsan avatar Sep 19 '18 16:09 lucas-dolsan

I'm also looking for a solution.

Panduss avatar Sep 27 '18 07:09 Panduss

I also encountered this issue using NativeBase v2.8.0 which has react-native-vector-icons as dependency.

rreina avatar Oct 09 '18 12:10 rreina

@oblador Is there any plans to change that? Or will it be "as is"? I think an ability to fill color is must have feature. Now it's not possible to do in any way (at least I couldn't find) neither with this repo, nor with React Native component (like imaginable overlay or whatever).

likern avatar Oct 18 '18 20:10 likern

I also having this problem. Maybe adding a view behind the icon can fix the problem temporary.

mdeveloper20 avatar Apr 23 '19 06:04 mdeveloper20

I found a somewhat hacky work-around for this issue. I'm importing icons from NativeBase so the component is slightly different, but in @dennisbejencev-an's original example to achieve the desired result you can do something like this:

<View>
  <Icon
    type="MaterialCommunityIcons"
    name="bookmark"
    style={{
      color: "white",
      fontSize: 100
    }}
  />
  <Icon
    type="MaterialCommunityIcons"
    name="bookmark-check"
    style={{
      color: "blue",
      fontSize: 100,
      top: 0,
      left: 0,
      position: "absolute"
    }}
  />
</View>

res

Setting the second Icon to the absolute position 0,0 will overlay it onto the first. Since this example has a filled icon and a checked icon the overlay is perfect. It isn't a general solution since you need two similar icons, but it works in many cases. In situations where the overlay of the two icons doesn't quite line up from you can make one of the icons slightly larger than the other and fiddle around with the positioning to get to something acceptable.

Hope this helps!

natejenkins avatar Jul 14 '19 02:07 natejenkins

I also having this problem. Maybe adding a view behind the icon can fix the problem temporary.

Good idea. I will use the solution before author fix the bug, but maybe is a feature. XD

yesw6a avatar Jul 17 '20 02:07 yesw6a

<View style={{ backgroundColor: '#fff', borderRadius: 25 }}> <MaterialIcons name = 'bookmark-check' size = {30} color = {'blue'} /> </View> try this out ... give borderRadius: 25 or until hide it. Note: no need for width and height if u already write size={30}

Hope this helps!

Mohammed-Salmeen avatar Aug 24 '20 09:08 Mohammed-Salmeen

I have problems with this too! I'm using "logo-youtube" from Ionicons and I want the middle play triangle to be white while the surrounding part is red, however if I add a white backgroundColor there will be a white box around the icon, and changing the padding to 0 does nothing at all.

use reverse attribute

sagarsaurabhssnl avatar May 19 '21 06:05 sagarsaurabhssnl

Give outer box width and height less than inner. See the example

 <TouchableOpacity
        style={{
          backgroundColor: Colors.white,
          width: 44,
          height: 44,
          borderRadius: 22,
          justifyContent: "center",
          alignItems: "center",
        }}
        onPress={() => console.log("+ pressed")}
      >
        <Ionicons
          style={{
            width: 66,
            height: 66,
          }}
          size={66}
          name="add-circle"
          color={Colors.primary}
        />
      </TouchableOpacity>
      ```

EKOLX avatar Aug 12 '22 11:08 EKOLX