Search code examples
androidcssreact-nativestylesstylesheet

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>

Solution

  • 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>