2017-11-18 157 views

回答

1

眼下CheckBox組件只支持Android系統。正如here所述,對於iOS,您應該使用Switch。

對於Android,使用非常簡單。

<View style={{ flexDirection: 'column'}}> 
    <CheckBox /> 
    <View style={{ flexDirection: 'row' }}> 
    <CheckBox 
     value={this.state.checked} 
     onValueChange={() => this.setState({ checked: !this.state.checked })} 
    /> 
    <Text style={{marginTop: 5}}> this is checkbox</Text> 
    </View> 
</View> 

視圖和文本組件是可選的,只是爲了顯示CheckBox如何與這些組件一起使用。 上面的代碼將在Android設備上生成此屏幕。 Screenshot of the above code

這在iOS設備上

enter image description here

+0

哦 - 好 - 似乎沒有提到它在文檔頁 – Greg

+0

是的,反應原生文檔通常沒有記錄。最好的辦法是去github問題並在那裏搜索 – magneticz

1

使用react-native-elements,任務更容易和例子可供選擇:

import { CheckBox } from 'react-native-elements' 

<CheckBox 
    title='Click Here' 
    checked={this.state.checked} 
/> 

<CheckBox 
    center 
    title='Click Here' 
    checked={this.state.checked} 
/> 

<CheckBox 
    center 
    title='Click Here' 
    checkedIcon='dot-circle-o' 
    uncheckedIcon='circle-o' 
    checked={this.state.checked} 
/> 

<CheckBox 
    center 
    title='Click Here to Remove This Item' 
    iconRight 
    iconType='material' 
    checkedIcon='clear' 
    uncheckedIcon='add' 
    checkedColor='red' 
    checked={this.state.checked} 
/> 
+0

明白 - 我只是試圖讓「本土」反應天然的「複選框」組件在這裏工作.... – Greg

+0

@格雷格沒有你設法做任何事情呢? Im在react-native 0.49的複選框中掙扎,它似乎只能工作一次,然後狀態不會改回來。 – Waqar

+0

似乎有沒有人反應本身本身 – Greg