Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to combine multiple inline style objects and inline css in react-native?

How to combine multiple inline style objects and inline css in react-native?

it has 3 style objects TimelineGreenColor, TimelineLeftBorder, TimelineLeftLine to be used in view div

  const stylesB = StyleSheet.create( {
     TimelineGreenColor:
     {
       backgroundColor: "green",
     },
     TimelineLeftBorder:
     {
       position: 'absolute',
       width: 4,
       backgroundColor: "green",
       height: '100%',
       left: 4,
       top: 15,
     },
     TimelineLeftCircle:
     {
       position: 'absolute',
       width: 12,
       height: 12,
       backgroundColor: "green",
       top: 12,
       borderRadius: 50,
       left: 0,
       /*boxShadow: "0px 0px 10px -2px black",*/
     },
     TimelineLeftLine:
     {
       position: 'absolute',
       width: 15,
       height: 3,
       backgroundColor: "green",
       top: 16,
       left: 5,
   }

   <View style={how to write styles in react-native ??????????}></View>
like image 287
Varunkumar Gande Avatar asked Dec 07 '25 14:12

Varunkumar Gande


2 Answers

type 1: if you have one inline style

<View style = {{marginLeft: 7,paddingRight: "9%"}}></View>

type 2: if you have one style from styles object

<View style = {styles.TimelineLeftBorder}></View>

type 3: if you have two or more styles from styles object

<View style = {[styles.TimelineLeftBorder,styles.TimelineGreenColor]}></View>

type 4: if you have two or more styles from styles object and you want to give normal inline css also

<View style = {[styles.TimelineLeftBorder,styles.TimelineGreenColor,{marginLeft: 7}]}></View>

like image 80
Varunkumar Gande Avatar answered Dec 09 '25 14:12

Varunkumar Gande


simply pass all the styles object in array in style prop.

<View style={[stylesB.TimelineGreenColor,styleB.TimelineLeftBorder,styleB.TimelineLeftCircle,styleB.TimelineLeftLine]}/>

Remember that style prop accepts array of style objects in case of multiple styles and a object of style object in case of single style.

like image 23
avani kothari Avatar answered Dec 09 '25 14:12

avani kothari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!