[英]NativeBase: How to make Picker disabled?
我正在使用NativeBase
的Picker
組件,我想根據條件禁用它。
有一個名為enabled
的屬性,它僅適用於 Android,那么 iOS 呢?
謝謝。
當前源代碼中缺少 renderButton 方法中的 DISABLED 參數,請參閱: https : //github.com/GeekyAnts/NativeBase/blob/master/src/basic/Picker.ios.js
我解決了這個問題,將函數renderButton傳遞給 Picker 組件,在其中我將禁用的道具傳遞給 Button,請參見下面的示例:
renderOptionFieldSOF( props : Object, fieldName : String, optionItems : Array, disabled : Boolean, placeHolderText : String) {
const {width} = Dimensions.get("window");
const buttonStyle = {backgroundColor: disabled ? "#rgb(200,200,200)" : "transparent" , width: width - 20};
return (<Picker
mode="dialog"
enabled={!disabled} /*This works only on Android*/
renderButton={
({onPress, text, picker, selectedItem }) => {
return (
<Button
style={buttonStyle}
dark
picker
transparent
onPress={onPress}
disabled={disabled} /*This will disable user interaction on IOS*/
>
{selectedItem ? (
<Text style={this.props.textStyle} note={this.props.note}>
{text}
</Text>
) : (
<Text
style={[this.props.textStyle, this.props.placeholderStyle]}
note={this.props.note === false ? false : true}>
{placeHolderText}
</Text>
)}
</Button>
)}
}
>
{
optionItems && optionItems.map( (item) => (<Item label={item.Name} value={item.Key} key={item.Key}/>))
}
</Picker>);}
為我工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.