ReactNative: 浣跨敤閫夋嫨鍣ㄧ粍浠禤icker缁勪欢

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ReactNative: 浣跨敤閫夋嫨鍣ㄧ粍浠禤icker缁勪欢相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/hang' title='hang'>hang   鏌ヨ   val   hit   export   picker   justify   script   妯″紡   

涓€銆佺畝浠?/strong>

鏈郴鍒楀崥瀹㈠凡缁忎粙缁嶈繃浜嗘棩鏈熼€夋嫨鍣ㄧ殑浣跨敤锛屾棩鏈熼€夋嫨鍣ㄦ槸楂樺害灏佽鐨勭粍浠讹紝寮€鍙戣€呭彲浠ラ€夋嫨鏈€鍘熷鐨勯€夋嫨鍣ㄧ粍浠禤icker缁勪欢杩涜瀹氬埗锛屽畠鏄法骞冲彴鐨勭粍浠躲€侾icker缁勪欢闇€瑕侀厤鍚圥icker.Item缁勪欢涓€璧蜂娇鐢ㄣ€侾icker.Item缁勪欢鏄疨icker缁勪欢鐨勫瓙椤癸紝鐢ㄦ潵璁剧疆Picker缁勪欢鍊肩殑銆侾icker.Item缁勪欢鍙互宓屽澶氫釜Picker.Item缁勪欢銆?/span>

 

浜屻€丳icker缁勪欢API

Picker缁勪欢鎻愪緵鐨勯兘鏄潤鎬佸睘鎬э紝鍒嗘瀽姣忎竴涓睘鎬х殑浣滅敤濡備笅鎵€绀猴細

//閫夋嫨鍣ㄦ牱寮?/span>
style: pickerStyleType

//閫変腑鐨勫瓙椤圭殑鍊?/span>
selectedValue: React.PropTypes.any,

//褰撳垏鎹㈠瓙椤规椂璋冪敤
onValueChange: React.PropTypes.func

//閫夋嫨鍣ㄦ槸鍚﹁兘澶熶氦浜? 浠呴檺瀹夊崜浣跨敤
enabled: React.PropTypes.bool

//閫夋嫨鍣ㄦā寮忥紝鏋氫妇锛歞ialog 瀵硅瘽妗? dropdown锛氫笅钀? 浠呴檺瀹夊崜浣跨敤
mode: React.PropTypes.oneOf([鈥?/span>dialog鈥?/span>, 鈥?/span>dropdown鈥?/span>])

//瀛愰」鐨勬牱寮忥紝浠呴檺ios浣跨敤
itemStyle: itemStylePropType

//鍦ㄥ璇濇妯″紡涓嬪湪android涓婄敤浣滃璇濇鐨勬爣棰? 浠呴檺瀹夊崜浣跨敤
prompt: React.PropTypes.string

//缁勪欢鍞竴鏍囪瘑锛屼究浜庢煡璇㈠埌璇ョ粍浠?/span>
testID: React.PropTypes.string

 

涓夈€丳icker.Item缁勪欢API

Picker.Item缁勪欢鎻愪緵鐨勯兘鏄睘鎬у彧鏈夊嚑涓紝浣嗘槸闈炲父甯哥敤锛屽垎鏋愭瘡涓€涓睘鎬х殑浣滅敤濡備笅鎵€绀猴細

//姝ら」鐩鏄剧ず鐨勬枃瀛?/span>
label: React.PropTypes.string.isRequired

//閫夋嫨姝ら」鐩悗锛屼紶閫掔粰閫夋嫨鍣ㄧ殑onValueChange鍥炶皟鐨勫€笺€?鍙互鏄瓧绗︿覆鎴栨暣鏁般€?/span>
value: React.PropTypes.any

//姝ら」鐩鏄剧ず鐨勬枃瀛楃殑棰滆壊锛屼粎闄愬畨鍗撲娇鐢?/span>
color: ColorPropType

//鍞竴鏍囪瘑
testID: React.PropTypes.string

 

鍥涖€佷娇鐢?/strong>

鐪嬩簡涓€涓嬫枃妗o紝绠€鍗曞疄鐜颁竴涓嬶紝绀轰緥濡備笅锛?/span>

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 鈥?/span>react鈥?/span>;

import {
    AppRegistry,
    StyleSheet,
    View,
    Picker
} from 鈥?/span>react-native鈥?/span>;


export default class ReactNativeDemo extends Component {

    //榛樿閫変腑鐨勫€?/span>
    state = {
        language:鈥?/span>swift鈥?/span>
    };

    render() {
        return (
            <View style={[styles.flex,styles.bgColor,styles.center]}>
                <Picker
                    style={{width:200, height:50}}
                    selectedValue={this.state.language}
                    onValueChange={(lang) => this.setState({language: lang})}>
                    <Picker.Item label="Java" value="java" />
                    <Picker.Item label="javascript" value="js" />
                    <Picker.Item label="Swift" value="swift" />
                    <Picker.Item label="Objective-C" value="oc" />
                </Picker>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    flex: {
        flex: 1
    },
    bgColor: {
      backgroundColor: 鈥?/span>white鈥?/span>
    },
    center: {
        alignItems: 鈥?/span>center鈥?/span>,
        justifyContent: 鈥?/span>center鈥?/span>,
    }
});

AppRegistry.registerComponent(鈥?/span>ReactNativeDemo鈥?/span>, () => ReactNativeDemo);

鎶€鏈浘鐗? src=

 

以上是关于ReactNative: 浣跨敤閫夋嫨鍣ㄧ粍浠禤icker缁勪欢的主要内容,如果未能解决你的问题,请参考以下文章

matlab鑷甫鍚勭鍒嗙被鍣ㄧ殑浣跨敤绀轰緥

涓嶇啛缁?Git 琚紭鍖栦簡锛佽吘璁槸濡備綍浣跨敤 Git 鐨?锛?/h1>

浣跨敤Wireshark鏌ョ湅HTTPS涓璗LS鎻℃墜杩囩▼

10涓潪甯稿疄鐢ㄧ殑 VS Code 鎻掍欢

(c)2006-2024 SYSTEM All Rights Reserved IT常识