Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native: Text and Icon inline

I am trying to aline a Icon and a Text inline and align the text to the left and the icon to the right...

This is how it is looking at the moment: enter image description here

However, I want to have the text aligned to the left and the icon to the right and also both on the same height...

My code so far:

<Text
  style={{
    fontSize: 16,
    paddingTop: 15,
    paddingBottom: 15,
    paddingLeft: 10,
    paddingRight: 10,
    color: "black"
  }}
>
  Kategorien:
  <Icon
    style={{
      alignItems: "center",
      justifyContent: "center",
      textAlign: "right"
    }}
    name="keyboard-arrow-down"
    type="MaterialIcons"
  />
</Text>

I also tried to use the react native elements and make use of the right and left element, however, in this case the icon and text is not inline...

<View>
  <Left>
    Text...
  </Left>
  <Right>
    Icon...
  </Right>
</View>

You guys have any idea?

like image 709
Jan Avatar asked Jan 13 '19 19:01

Jan


People also ask

How do I make two text in the same line in react native?

To add space between two elements on the same line in React Native, we can set justifyContent to 'space-between' in the View . to set the flexDirection to 'row' and the justifyContent style to 'space-between' to spread the Text components on the screen.


1 Answers

You need wrap with a View your Text and Icon component. And you can set just padding horizontal and vertical in there.

       <View style={{
            paddingVertical: 15,
            paddingHorizontal: 10,
            flexDirection: "row",
            justifyContent: "space-between",
            alignItems: "center"
        }}>
            <Text style={{
                    fontSize: 16,
                    color: "black"
                }}>Kategorien:</Text>
            <Icon/>
        </View>
like image 69
sdkcy Avatar answered Sep 27 '22 23:09

sdkcy