From c3d620bc63b59b0e8aff98ac290b436f708d6b21 Mon Sep 17 00:00:00 2001 From: xwenliang Date: Tue, 20 Sep 2016 17:03:50 +0800 Subject: [PATCH] data structure --- example/PickerTest/index.android.js | 97 +------------------ example/PickerTest/index.ios.js | 143 +--------------------------- example/PickerTest/index.js | 124 ++++++++++++++++++++++++ 3 files changed, 129 insertions(+), 235 deletions(-) create mode 100644 example/PickerTest/index.js diff --git a/example/PickerTest/index.android.js b/example/PickerTest/index.android.js index 3c28eff..afea330 100644 --- a/example/PickerTest/index.android.js +++ b/example/PickerTest/index.android.js @@ -1,102 +1,11 @@ /** - * Sample React Native App - * https://github.com/facebook/react-native + * react-native-picker example for android */ -import React, {Component} from 'react'; import { - View, - Text, - TouchableOpacity, - Dimensions, - StyleSheet, AppRegistry } from 'react-native'; -import Picker from 'react-native-picker'; +import PickerTest from './index.js'; -function createDateData(){ - let date = {}; - for(let i=1950;i<2050;i++){ - let month = {}; - for(let j = 1;j<13;j++){ - let day = []; - if(j === 2){ - for(let k=1;k<29;k++){ - day.push(k+'日'); - } - } - else if(j in {1:1, 3:1, 5:1, 7:1, 8:1, 10:1, 12:1}){ - for(let k=1;k<32;k++){ - day.push(k+'日'); - } - } - else{ - for(let k=1;k<31;k++){ - day.push(k+'日'); - } - } - month[j+'月'] = day; - } - date[i+'年'] = month; - } - return date; -}; - -class PickerTest extends Component { - - constructor(props, context) { - super(props, context); - } - - _onPressHandle() { - Picker.init({ - pickerData: createDateData(), - selectedValue: ['2015年', '12月', '12日'], - onPickerConfirm: pickedValue => { - alert(JSON.stringify(pickedValue)); - console.log(pickedValue); - }, - onPickerCancel: pickedValue => { - alert(JSON.stringify(pickedValue)); - console.log(pickedValue); - }, - onPickerSelect: pickedValue => { - alert(JSON.stringify(pickedValue)); - console.log(pickedValue); - } - }); - Picker.show(); - } - - render() { - return ( - - - Click Me - - - ); - } -} - -const styles = StyleSheet.create({ - container: { - flex: 1, - justifyContent: 'center', - alignItems: 'center', - backgroundColor: '#F5FCFF', - }, - welcome: { - fontSize: 20, - textAlign: 'center', - margin: 10, - }, - instructions: { - textAlign: 'center', - color: '#333333', - marginBottom: 5, - }, -}); - -AppRegistry.registerComponent('PickerTest', () => PickerTest); +AppRegistry.registerComponent('PickerTest', () => PickerTest); \ No newline at end of file diff --git a/example/PickerTest/index.ios.js b/example/PickerTest/index.ios.js index d4b791c..a5449d9 100644 --- a/example/PickerTest/index.ios.js +++ b/example/PickerTest/index.ios.js @@ -1,150 +1,11 @@ /** - * Sample React Native App - * https://github.com/facebook/react-native + * react-native-picker example for ios */ -import React, {Component} from 'react'; import { - View, - Text, - TouchableOpacity, - Dimensions, - StyleSheet, AppRegistry } from 'react-native'; -import Picker from 'react-native-picker'; - -function createDateData(){ - let date = {}; - for(let i=1950;i<2050;i++){ - let month = {}; - for(let j = 1;j<13;j++){ - let day = []; - if(j === 2){ - for(let k=1;k<29;k++){ - day.push(k+'日'); - } - } - else if(j in {1:1, 3:1, 5:1, 7:1, 8:1, 10:1, 12:1}){ - for(let k=1;k<32;k++){ - day.push(k+'日'); - } - } - else{ - for(let k=1;k<31;k++){ - day.push(k+'日'); - } - } - month[j+'月'] = day; - } - date[i+'年'] = month; - } - return date; -}; - -function createAreaData(callback){ - fetch('https://raw.githubusercontent.com/beefe/react-native-picker/master/example/PickerTest/area.json').then(res => { - res.json().then(area => { - let data = {}; - let len = area.length; - for(let i=0;i { - console.log(err); - }); -}; - -class PickerTest extends Component { - - constructor(props, context) { - super(props, context); - } - - _showDatePicker() { - Picker.init({ - pickerData: createDateData(), - selectedValue: ['2015年', '12月', '12日'], - onPickerConfirm: pickedValue => { - alert(JSON.stringify(pickedValue)); - console.log(pickedValue); - }, - onPickerCancel: pickedValue => { - alert(JSON.stringify(pickedValue)); - console.log(pickedValue); - }, - onPickerSelect: pickedValue => { - alert(JSON.stringify(pickedValue)); - console.log(pickedValue); - } - }); - Picker.show(); - } - - _showAreaPicker() { - createAreaData(data => { - Picker.init({ - pickerData: data, - selectedValue: ['北京', '北京', '朝阳区'], - onPickerConfirm: pickedValue => { - alert(JSON.stringify(pickedValue)); - console.log(pickedValue); - }, - onPickerCancel: pickedValue => { - alert(JSON.stringify(pickedValue)); - console.log(pickedValue); - }, - onPickerSelect: pickedValue => { - alert(JSON.stringify(pickedValue)); - console.log(pickedValue); - } - }); - Picker.show(); - }); - } - - render() { - return ( - - - DatePicker - - - AreaPicker - - - ); - } -} - -const styles = StyleSheet.create({ - container: { - flex: 1, - justifyContent: 'center', - alignItems: 'center', - backgroundColor: '#F5FCFF', - }, - welcome: { - fontSize: 20, - textAlign: 'center', - margin: 10, - }, - instructions: { - textAlign: 'center', - color: '#333333', - marginBottom: 5, - }, -}); +import PickerTest from './index.js'; AppRegistry.registerComponent('PickerTest', () => PickerTest); diff --git a/example/PickerTest/index.js b/example/PickerTest/index.js new file mode 100644 index 0000000..0e7c289 --- /dev/null +++ b/example/PickerTest/index.js @@ -0,0 +1,124 @@ +/** + * Bootstrap of PickerTest + */ + +import React, {Component} from 'react'; +import { + View, + Text, + TouchableOpacity, + Dimensions +} from 'react-native'; + +import Picker from 'react-native-picker'; + +function createDateData(){ + let date = {}; + for(let i=1950;i<2050;i++){ + let month = {}; + for(let j = 1;j<13;j++){ + let day = []; + if(j === 2){ + for(let k=1;k<29;k++){ + day.push(k+'日'); + } + } + else if(j in {1:1, 3:1, 5:1, 7:1, 8:1, 10:1, 12:1}){ + for(let k=1;k<32;k++){ + day.push(k+'日'); + } + } + else{ + for(let k=1;k<31;k++){ + day.push(k+'日'); + } + } + month[j+'月'] = day; + } + date[i+'年'] = month; + } + return date; +}; + +function createAreaData(callback){ + fetch('https://raw.githubusercontent.com/beefe/react-native-picker/master/example/PickerTest/area.json').then(res => { + res.json().then(area => { + let data = {}; + let len = area.length; + for(let i=0;i { + console.log(err); + }); +}; + +export default class PickerTest extends Component { + + constructor(props, context) { + super(props, context); + } + + _showDatePicker() { + Picker.hide(); + Picker.init({ + pickerData: createDateData(), + selectedValue: ['2015年', '12月', '12日'], + onPickerConfirm: pickedValue => { + alert(JSON.stringify(pickedValue)); + console.log(pickedValue); + }, + onPickerCancel: pickedValue => { + alert(JSON.stringify(pickedValue)); + console.log(pickedValue); + }, + onPickerSelect: pickedValue => { + alert(JSON.stringify(pickedValue)); + console.log(pickedValue); + } + }); + Picker.show(); + } + + _showAreaPicker() { + createAreaData(data => { + Picker.init({ + pickerData: data, + selectedValue: ['北京', '北京', '朝阳区'], + onPickerConfirm: pickedValue => { + console.log(pickedValue); + }, + onPickerCancel: pickedValue => { + console.log(pickedValue); + }, + onPickerSelect: pickedValue => { + console.log(pickedValue); + } + }); + Picker.show(); + }); + } + + render() { + return ( + + + DatePicker + + + AreaPicker + + + ); + } +}; -- 2.26.2