1616'use strict' ;
1717
1818const React = require ( 'react-native' ) ;
19+ const StyleSheet = require ( 'StyleSheet' ) ;
1920const UIExplorerBlock = require ( 'UIExplorerBlock' ) ;
2021const UIExplorerPage = require ( 'UIExplorerPage' ) ;
2122
2223const {
23- PickerAndroid ,
24+ Picker ,
2425 Text,
2526 TouchableWithoutFeedback,
2627} = React ;
27- const Item = PickerAndroid . Item ;
28+ const Item = Picker . Item ;
2829
29- const PickerAndroidExample = React . createClass ( {
30+ const PickerExample = React . createClass ( {
3031
3132 statics : {
32- title : '<PickerAndroid >' ,
33+ title : '<Picker >' ,
3334 description : 'Provides multiple options to choose from, using either a dropdown menu or a dialog.' ,
3435 } ,
3536
@@ -38,103 +39,102 @@ const PickerAndroidExample = React.createClass({
3839 selected1 : 'key1' ,
3940 selected2 : 'key1' ,
4041 selected3 : 'key1' ,
41- selected4 : 'key1' ,
4242 color : 'red' ,
43- mode : PickerAndroid . MODE_DIALOG ,
43+ mode : Picker . MODE_DIALOG ,
4444 } ;
4545 } ,
4646
4747 displayName : 'Android Picker' ,
4848
4949 render : function ( ) {
5050 return (
51- < UIExplorerPage title = "<PickerAndroid >" >
51+ < UIExplorerPage title = "<Picker >" >
5252 < UIExplorerBlock title = "Basic Picker" >
53- < PickerAndroid
54- style = { { width : 100 , height : 56 } }
55- onSelect = { this . onSelect . bind ( this , 'selected1' ) } >
56- < Item text = "hello" value = "key0" selected = { this . state . selected1 === 'key0' } />
57- < Item text = "world" value = "key1" selected = { this . state . selected1 === 'key1' } />
58- </ PickerAndroid >
53+ < Picker
54+ style = { styles . picker }
55+ selectedValue = { this . state . selected1 }
56+ onValueChange = { this . onValueChange . bind ( this , 'selected1' ) } >
57+ < Item label = "hello" value = "key0" />
58+ < Item label = "world" value = "key1" />
59+ </ Picker >
5960 </ UIExplorerBlock >
6061 < UIExplorerBlock title = "Disabled picker" >
61- < PickerAndroid style = { { width : 100 , height : 56 } } enabled = { false } >
62- < Item text = "hello" value = "key0" selected = { this . state . selected1 === 'key0' } />
63- < Item text = "world" value = "key1" selected = { this . state . selected1 === 'key1' } />
64- </ PickerAndroid >
62+ < Picker style = { styles . picker } enabled = { false } selectedValue = { this . state . selected1 } >
63+ < Item label = "hello" value = "key0" />
64+ < Item label = "world" value = "key1" />
65+ </ Picker >
6566 </ UIExplorerBlock >
6667 < UIExplorerBlock title = "Dropdown Picker" >
67- < PickerAndroid
68- style = { { width : 100 , height : 56 } }
69- onSelect = { this . onSelect . bind ( this , 'selected2' ) }
68+ < Picker
69+ style = { styles . picker }
70+ selectedValue = { this . state . selected2 }
71+ onValueChange = { this . onValueChange . bind ( this , 'selected2' ) }
7072 mode = "dropdown" >
71- < Item text = "hello" value = "key0" selected = { this . state . selected2 === 'key0' } />
72- < Item text = "world" value = "key1" selected = { this . state . selected2 === 'key1' } />
73- </ PickerAndroid >
74- </ UIExplorerBlock >
75- < UIExplorerBlock title = "Alternating Picker" >
76- < PickerAndroid
77- style = { { width : 100 , height : 56 } }
78- onSelect = { this . onSelect . bind ( this , 'selected3' ) }
79- mode = { this . state . mode } >
80- < Item text = "hello" value = "key0" selected = { this . state . selected3 === 'key0' } />
81- < Item text = "world" value = "key1" selected = { this . state . selected3 === 'key1' } />
82- </ PickerAndroid >
83- < TouchableWithoutFeedback onPress = { this . changeMode } >
84- < Text > Tap here to switch between dialog/dropdown.</ Text >
85- </ TouchableWithoutFeedback >
73+ < Item label = "hello" value = "key0" />
74+ < Item label = "world" value = "key1" />
75+ </ Picker >
8676 </ UIExplorerBlock >
8777 < UIExplorerBlock title = "Picker with prompt message" >
88- < PickerAndroid
89- style = { { width : 100 , height : 56 } }
90- onSelect = { this . onSelect . bind ( this , 'selected4' ) }
78+ < Picker
79+ style = { styles . picker }
80+ selectedValue = { this . state . selected3 }
81+ onValueChange = { this . onValueChange . bind ( this , 'selected3' ) }
9182 prompt = "Pick one, just one" >
92- < Item text = "hello" value = "key0" selected = { this . state . selected4 === 'key0' } />
93- < Item text = "world" value = "key1" selected = { this . state . selected4 === 'key1' } />
94- </ PickerAndroid >
83+ < Item label = "hello" value = "key0" />
84+ < Item label = "world" value = "key1" />
85+ </ Picker >
9586 </ UIExplorerBlock >
9687 < UIExplorerBlock title = "Picker with no listener" >
97- < PickerAndroid style = { { width : 100 , height : 56 } } >
98- < Item text = "hello" value = "key0" />
99- < Item text = "world" value = "key1" />
100- </ PickerAndroid >
88+ < Picker style = { styles . picker } >
89+ < Item label = "hello" value = "key0" />
90+ < Item label = "world" value = "key1" />
91+ </ Picker >
10192 < Text >
102- You can not change the value of this picker because it doesn't set a selected prop on
103- its items.
93+ Cannot change the value of this picker because it doesn't update selectedValue.
10494 </ Text >
10595 </ UIExplorerBlock >
10696 < UIExplorerBlock title = "Colorful pickers" >
107- < PickerAndroid style = { { width : 100 , height : 56 , color : 'black' } }
108- onSelect = { this . onSelect . bind ( this , 'color' ) }
97+ < Picker
98+ style = { [ styles . picker , { color : 'white' , backgroundColor : '#333' } ] }
99+ selectedValue = { this . state . color }
100+ onValueChange = { this . onValueChange . bind ( this , 'color' ) }
109101 mode = "dropdown" >
110- < Item text = "red" color = "red" value = "red" selected = { this . state . color === 'red' } />
111- < Item text = "green" color = "green" value = "green" selected = { this . state . color === 'green' } />
112- < Item text = "blue" color = "blue" value = "blue" selected = { this . state . color === 'blue' } />
113- </ PickerAndroid >
114- < PickerAndroid style = { { width : 100 , height : 56 } }
115- onSelect = { this . onSelect . bind ( this , 'color' ) }
102+ < Item label = "red" color = "red" value = "red" />
103+ < Item label = "green" color = "green" value = "green" />
104+ < Item label = "blue" color = "blue" value = "blue" />
105+ </ Picker >
106+ < Picker
107+ style = { styles . picker }
108+ selectedValue = { this . state . color }
109+ onValueChange = { this . onValueChange . bind ( this , 'color' ) }
116110 mode = "dialog" >
117- < Item text = "red" color = "red" value = "red" selected = { this . state . color === 'red' } />
118- < Item text = "green" color = "green" value = "green" selected = { this . state . color === 'green' } />
119- < Item text = "blue" color = "blue" value = "blue" selected = { this . state . color === 'blue' } />
120- </ PickerAndroid >
111+ < Item label = "red" color = "red" value = "red" />
112+ < Item label = "green" color = "green" value = "green" />
113+ < Item label = "blue" color = "blue" value = "blue" />
114+ </ Picker >
121115 </ UIExplorerBlock >
122116 </ UIExplorerPage >
123117 ) ;
124118 } ,
125119
126120 changeMode : function ( ) {
127- const newMode = this . state . mode === PickerAndroid . MODE_DIALOG
128- ? PickerAndroid . MODE_DROPDOWN
129- : PickerAndroid . MODE_DIALOG ;
121+ const newMode = this . state . mode === Picker . MODE_DIALOG
122+ ? Picker . MODE_DROPDOWN
123+ : Picker . MODE_DIALOG ;
130124 this . setState ( { mode : newMode } ) ;
131125 } ,
132126
133- onSelect : function ( key : string , value : string ) {
127+ onValueChange : function ( key : string , value : string ) {
134128 const newState = { } ;
135129 newState [ key ] = value ;
136130 this . setState ( newState ) ;
137131 } ,
138132} ) ;
139133
140- module . exports = PickerAndroidExample ;
134+ var styles = StyleSheet . create ( {
135+ picker : {
136+ width : 100 ,
137+ } ,
138+ } ) ;
139+
140+ module . exports = PickerExample ;
0 commit comments