Skip to content

Instantly share code, notes, and snippets.

@chuyihuang
Created September 26, 2017 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuyihuang/a538ab9332d41cbc6d8455c185c68263 to your computer and use it in GitHub Desktop.
Save chuyihuang/a538ab9332d41cbc6d8455c185c68263 to your computer and use it in GitHub Desktop.
week_7_demo_8
import React, {Component} from 'react';
import {
View,
Text,
Button,
} from 'react-native';
import Picker from 'react-native-picker';
let data = ['男', '女', '未知'];
export default class PickerExample extends Component {
constructor(props) {
super(props);
this.state = {
gender: '未知'
}
}
showPicker = () => {
Picker.init({
pickerData: data,
selectedValue: [this.state.gender],
pickerConfirmBtnText: "我確定",
pickerFontSize: 20,
onPickerConfirm: data => {
this.setState({
gender: data
})
},
onPickerCancel: data => {
console.log(data);
},
onPickerSelect: data => {
console.log(data);
}
});
Picker.show();
}
render() {
return (
<View style={{marginTop: 100, alignItems: 'center'}}>
<Button title="按我選擇" color="red" onPress={() => this.showPicker()} />
<Text>{this.state.gender}</Text>
</View>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment