Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. Text,
  5. Button,
  6. } from 'react-native';
  7. import Picker from 'react-native-picker';
  8.  
  9. let data = ['男', '女', '未知'];
  10.  
  11. export default class PickerExample extends Component {
  12.  
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. gender: '未知'
  17. }
  18. }
  19.  
  20. showPicker = () => {
  21. Picker.init({
  22. pickerData: data,
  23. selectedValue: [this.state.gender],
  24. pickerConfirmBtnText: "我確定",
  25. pickerFontSize: 20,
  26. onPickerConfirm: data => {
  27. this.setState({
  28. gender: data
  29. })
  30. },
  31. onPickerCancel: data => {
  32. console.log(data);
  33. },
  34. onPickerSelect: data => {
  35. console.log(data);
  36. }
  37. });
  38. Picker.show();
  39. }
  40.  
  41. render() {
  42. return (
  43. <View style={{marginTop: 100, alignItems: 'center'}}>
  44. <Button title="按我選擇" color="red" onPress={() => this.showPicker()} />
  45. <Text>{this.state.gender}</Text>
  46. </View>
  47. );
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement