React native: How to combine external and inline styles?

前端 未结 3 1934
我在风中等你
我在风中等你 2020-12-24 13:04

This is a part of a _renderRow-function. I have some basic styles for a button, and also a style that is read from a variable on the row. In this example it\'s \'#f00\' but

相关标签:
3条回答
  • 2020-12-24 13:35

    Your brackets are wrong. If you intend to continue to use the array syntax, Use this instead:

    <TouchableHighlight style={[styles.button,{ backgroundColor: '#f00'}]} 
    
    0 讨论(0)
  • 2020-12-24 13:47

    This is the correct answer, tested in React Native 0.44.2:

    <TouchableHighlight style={{...styles.button, ...{backgroundColor: '#f00'}}}>
    
    0 讨论(0)
  • 2020-12-24 13:54

    Can use the spread syntax:

    <TouchableHighlight style={{ ...styles.button, backgroundColor: '#f00'}}
    
    0 讨论(0)
提交回复
热议问题