2016-08-05 111 views
1

我需要給動態內嵌樣式與靜態默認樣式風格。我該如何做到這一點動態inilne風格陣營本地

<View 
    style={[styles.card,{{width:width, height: height}}]}> 
      <View style={styles.card}> 
       <Text> 
        <Image 
        source={{uri: this.props.media.image_url}} 
        style={{width:width, height: this.props.media.height}}/> 
       </Text> 
      </View> 
</View> 

上面的代碼不適合我。

+0

,如果你會去服務器渲染,你可能不得不改變未來的事情,因爲風格加載器未通過服務器渲染 – abhirathore2006

+0

什麼可以爲服務器渲染解決方案支持? –

+0

使用https://github.com/webpack/extract-text-webpack-plugin這將結合在一個文件中的所有CSS。 – abhirathore2006

回答

2

不,這個問題是不是訂單,你有沒有通過動態(內聯樣式)正確。你額外花括號包裹其中

更改此:

style={[styles.card,{{width:width, height: height}}]} 

到:

style={[styles.card,{width:width, height: height}]} 

你實際上已經做了同樣的事情在你的答案以上。

0

最後想了很多後,我能解決這個問題。 下面是代碼

<View 
    <View style={[{width:width, height: height},styles.card]}> 
     <View style={styles.card}> 
      <Text> 
       <Image 
       source={{uri: this.props.media.image_url}} 
       style={{width:width, height: this.props.media.height}}/> 
      </Text> 
     </View> 
    </View> 
</View> 
+0

澄清解決方案:樣式* do *的順序很重要,它們從左到右應用,所以'styles.card'覆蓋寬度和高度。 – Hanse