Nativebase: (react-native) Ionicon icons are aligned left within their <Icon>'s internal <Text> component.

Created on 26 Sep 2017  路  3Comments  路  Source: GeekyAnts/NativeBase

FYI: I am using NativeBase's Icon component that uses Ionicons.
I've also submitted this here: https://github.com/oblador/react-native-vector-icons/issues/556

Pictures are worth a thousand words:

image

and the other icon highlighted too:

image

This makes working with the icons a bit tedious as it's really hard to align different kinds of icons.

Is this intended behavior or is there something wrong with my setup? Is there a way to make the icons align center instead of left?

Note: this is not an issue with my own code, I have:

<View style={{width: 40, alignItems: 'center', justifyContent: 'center'}}>
  <Icon active name={icon} size={20} />   
</View>

and the highlighted part in the above pictures is not the View, it's inside the Icon component.

Most helpful comment

hi @akhil-geekyants,

I'm using https://docs.nativebase.io/Components.html#card-list-headref

Code is similar to:

<View style={{flexDirection: 'row'}}>
  <Card>
    <CardItem style={{flexDirection: 'row'}}>
      <View style={{width: 40, flexDirection: 'row', justifyContent: 'center'}}>
        <Icon active name={icon} size={20} />
      </View>

      <View style={{flex: 1}}>
        <Text>{name}</Text>
      </View>

      <View style={{width: 20}}>
        <Icon name="arrow-forward" />
      </View>
    </CardItem>
    ...
  </Card>
</View>

EDIT:

so, apparently <Icon active name={icon} size={20} style={{textAlign: 'center'}}/> solves my problem.

All 3 comments

@elnygren you can bring the icon to center. To do this, you need to eject the theme as described in the NativeBase docs

After ejecting the theme, go to file native-base-theme/components/ListItem.js add

textAlign:'center'

to "NativeBase.Icon":{} object inside "NativeBase.Left":{} (if you are using <Left>) inside listItemTheme:{} object.

hi @akhil-geekyants,

I'm using https://docs.nativebase.io/Components.html#card-list-headref

Code is similar to:

<View style={{flexDirection: 'row'}}>
  <Card>
    <CardItem style={{flexDirection: 'row'}}>
      <View style={{width: 40, flexDirection: 'row', justifyContent: 'center'}}>
        <Icon active name={icon} size={20} />
      </View>

      <View style={{flex: 1}}>
        <Text>{name}</Text>
      </View>

      <View style={{width: 20}}>
        <Icon name="arrow-forward" />
      </View>
    </CardItem>
    ...
  </Card>
</View>

EDIT:

so, apparently <Icon active name={icon} size={20} style={{textAlign: 'center'}}/> solves my problem.

@elnygren you can bring the icon to center. To do this, you need to eject the theme as described in the NativeBase docs

After ejecting the theme, go to file native-base-theme/components/ListItem.js add

textAlign:'center'

to "NativeBase.Icon":{} object inside "NativeBase.Left":{} (if you are using <Left>) inside listItemTheme:{} object.

Actually this helped a lot. Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eggybot picture eggybot  路  3Comments

sihemhssine picture sihemhssine  路  3Comments

kitsune7 picture kitsune7  路  3Comments

chetnadaffodil picture chetnadaffodil  路  3Comments

aloifolia picture aloifolia  路  3Comments