Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line with text in react native without using a library

Trying to replicate the below design but not able to. Will appreciate any help with this.

enter image description here

Code that I tried from my end is as below but the line overwrites the text.

<View>
  <View style={{ alignSelf:'center', borderBottomColor:'black', borderBottomWidth:1,height:'50%', width:'90%' }}/>
  <Text style={{ alignSelf:'center', paddingHorizontal:5 }}>Your class</Text>
</View>
like image 583
Rigorous implementation Avatar asked Dec 18 '17 05:12

Rigorous implementation


People also ask

How do you put a line through text in React Native?

Use the textDecoration property to strikethrough text in React, e.g. <span style={{textDecoration: 'line-through'}}> .

How do I add a straight line in React Native?

To create a horizontal line in React, you can add an hr element to the React component. The object style has the color, background-color and height . The color will give the line a solid color and the background-color for other properties.

How do you put a horizontal line in React Native?

Use the <hr /> tag and set the style prop on it. Set the height of the line and optionally set backGroundColor and color .


1 Answers

Made it works this way:

<View style={{flexDirection: 'row'}}>
    <View style={{backgroundColor: 'black', height: 2, flex: 1, alignSelf: 'center'}} />
    <Text style={{ alignSelf:'center', paddingHorizontal:5, fontSize: 24 }}>Your class</Text>
    <View style={{backgroundColor: 'black', height: 2, flex: 1, alignSelf: 'center'}} />
</View>

enter image description here

like image 100
Val Avatar answered Nov 23 '22 19:11

Val