2016-07-22 145 views
0

foo.js(代碼塊從陣營母語樣板):陣營母語:模塊化造型

const styles = StyleSheet.create({ 
    container: { 
    flex: 1, 
    justifyContent: 'center', 
    alignItems: 'center', 
    backgroundColor: '#F5FCFF', 
    }, 
    welcome: { 
    fontSize: 20, 
    textAlign: 'center', 
    margin: 10, 
    }, 
    instructions: { 
    textAlign: 'center', 
    color: '#333333', 
    marginBottom: 5, 
    }, 
}); 

什麼是從一個不同的文件bar.js宣佈新的風格的最佳方式是什麼?

1)添加一個新的屬性到styles

//import styles from 'foo.js' 

styles.forNewComponent = { 
    fontSize: 30, 
}; 

2)或者創建新的StyleSheet obj?

const StylesforNewComponent = StyleSheet.create({ 
    fontSize: 30, 
}); 

當使用1)方法和console.log(styles);輸出是:

Object {container: 3, welcome: 4, instructions: 5, forNewComponent: Object}

爲什麼forNewComponent的值是一個對象,但其他性能都ID我做錯了?我會有性能問題嗎?

回答

1

使用StyleSheet.create代替普通對象。因爲StyleSheet創建類似緩存的東西。

靜態創建(OBJ) - 創建從給定對象樣式表樣式參考。

而當你使用StyleSheet - 你會,如果你做錯事的風格


警告,好的做法是1種成分= 1級的樣式表

+0

感謝您的解釋! – Edgar

+0

不客氣。樂意效勞 ) –