Merge / Combine two or more different StyleSheet components in React Native? Merge / Combine two or more different StyleSheet components in React Native? reactjs reactjs

Merge / Combine two or more different StyleSheet components in React Native?


you are very close:

const baseStyles = [baseStyle, platformStyle];

basically any component can cascade styles like this:

<View style={[styles.style1,styles.style2]}></View>


You can combine style sheets using the spread operator '...', be warned that any variables of the same name will be overwritten by the last instance.

Heres a small demo app to demonstrate:

'use strict';import React, { Component } from 'react';import {   Alert,   Button,   StyleSheet,   Text,   AppRegistry,   View, } from 'react-native';class listTest extends Component {render() {  return (   <View style={styles3.myViewBox}>      <Text style = {styles3.myTextBox1}>        TEST      </Text>    </View>   );  } }const styles = StyleSheet.create({  myTextBox1: {     backgroundColor:'red',  },  myViewBox: {    backgroundColor:'blue',    margin:15,    padding:15,  }});const styles2 = StyleSheet.create({  myTextBox2: {    backgroundColor:'yellow',  },  myViewBox: {    backgroundColor:'green',    margin:15,    padding:15,  },});const styles3 = {...styles,...styles2};AppRegistry.registerComponent('listTest', () => listTest);