Varunkumar Gande
Varunkumar Gande

Reputation: 599

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>

Upvotes: 2

Views: 4031

Answers (2)

avani kothari
avani kothari

Reputation: 739

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.

Upvotes: 1

Varunkumar Gande
Varunkumar Gande

Reputation: 599

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>

Upvotes: 9

Related Questions