2017-05-28 29 views
0

我想創建一個簡單的進度條,將根據當前狀態動態更改。我使用兩個視圖,一個用於進度條容器,另一個用於進度欄(通過動態更改寬度可視化顯示)。我如何動態更新進度條寬度樣式?我可以動態更改原生反應中的樣式屬性嗎?

這裏是我的(我導入樣式表):

<View style={styles.progressBarContainer}> 
    <View style ={styles.progressBar} /> 
</View> 

progressBarContainer: { 
    width: 300, 
    height: 20, 
    borderWidth: 2, 
    borderColor: 'black' 
    }, 
    progressBar: { 
    height: 16, 
    width: 100, 
    backgroundColor: 'purple' 
    } 
+1

你可以內聯,因爲'styles'對象不會意識到'this'。也正如你所說,它的進口如此變異,這不是最好的主意。你可以試試這個:'{[styles.progressBar,{width:this.state.progressBarWidth}]}' – G0dsquad

回答

0

是的,可以。像這樣的東西。

<View style={styles.progressBarContainer}> 
    <View 
    style={ this.state.pressStatus ? styles.buttonPress : styles.button } 
/> 
</View> 
相關問題