Passing props into external stylesheet in React Native?

后端 未结 4 1381
臣服心动
臣服心动 2020-12-16 14:08

I\'m new to React and React Native. At the moment for each component I\'m breaking the code into 2 separate files:

  1. index.js for all the React cod
4条回答
  •  旧巷少年郎
    2020-12-16 14:33

    Create a class that takes iconColor and iconSize as arguments and returns a StyleSheet object

    // styles.js
    
    export default class StyleSheetFactory {
        static getSheet(iconSize, iconColor) {
            return StyleSheet.create({
                icon : {
                    color: iconColor,
                    fontSize: iconSize
                }
            })
        }
    }
    
    // index.js
    
    render() {
        let myStyleSheet = StyleSheetFactory.getSheet(64, 'red')
    }
    

提交回复
热议问题