11import React , { Component , PropTypes } from 'react' ;
2+ import Icon from 'react-native-vector-icons/FontAwesome' ;
23import {
34 View ,
45 Text ,
@@ -14,10 +15,11 @@ import {
1415 Modal ,
1516} from 'react-native' ;
1617
17-
1818import CPickroll from './roll2' ;
19+ import styles from './style' ;
1920let CPicker = Platform . OS === 'ios' ? PickerIOS : CPickroll ;
2021let PickerItem = CPicker . Item ;
22+
2123let height = Dimensions . get ( 'window' ) . height ;
2224let top = height - 250 ;
2325let str = '' ;
@@ -39,6 +41,7 @@ class CPickerroll extends Component {
3941 this . _changeAnimateStatus = this . _changeAnimateStatus . bind ( this ) ;
4042 this . state = this . _stateFromProps ( props ) ;
4143 this . state . animatedHeight = new Animated . Value ( height ) ;
44+ this . state . flex = new Animated . Value ( 0 ) ;
4245 }
4346
4447 _stateFromProps ( props ) {
@@ -70,24 +73,24 @@ class CPickerroll extends Component {
7073 }
7174 }
7275
73- let selfStyle = props . selfStyle ;
74- let inputStyle = props . inputStyle ;
7576 let animationType = props . animationType || 'none' ;
7677 let transparent = typeof props . transparent === 'undefined' ? true :props . transparent ;
7778 let visible = typeof props . visible === 'undefined' ? false :props . visible ;
7879 let enable = typeof props . enable === 'undefined' ? true :props . enable ;
7980 let inputValue = props . inputValue || 'please chose' ;
81+ let confirmBtnText = props . confirmBtnText || '确定' ;
82+ let cancelBtnText = props . cancelBtnText || '取消' ;
8083 return {
81- selfStyle,
8284 visible,
8385 transparent,
8486 animationType,
8587 enable,
8688 inputValue,
87- inputStyle,
8889 passData,
8990 selectIndex,
9091 selectedValue,
92+ confirmBtnText,
93+ cancelBtnText,
9194 } ;
9295 }
9396 _confirmChose ( ) {
@@ -100,6 +103,7 @@ class CPickerroll extends Component {
100103 return str ;
101104 }
102105 _cancelChose ( ) {
106+ console . log ( "nono" ) ;
103107 this . state . selectIndex . length = 0 ;
104108 this . state . passData . length = 0 ;
105109 this . state . selectedValue . length = 0 ;
@@ -141,13 +145,13 @@ class CPickerroll extends Component {
141145 if ( visible ) {
142146 this . setState ( { visible : visible } ) ;
143147 Animated . timing (
144- this . state . animatedHeight ,
145- { toValue : top }
148+ this . state . flex ,
149+ { toValue : 1 }
146150 ) . start ( ) ;
147151 } else {
148152 Animated . timing (
149- this . state . animatedHeight ,
150- { toValue : height }
153+ this . state . flex ,
154+ { toValue : 0 }
151155 ) . start ( ( ) => this . _changeAnimateStatus ( type ) )
152156 }
153157 }
@@ -193,11 +197,9 @@ class CPickerroll extends Component {
193197 render ( ) {
194198
195199 let modalBackgroundStyle = {
196- backgroundColor : this . state . transparent ? 'rgba(0, 0, 0, 0.5)' : '#f5fcff' ,
200+ backgroundColor : 'rgba(0, 0, 0, 0.5)' ,
197201 } ;
198- let innerContainerTransparentStyle = this . state . transparent
199- ? { backgroundColor : '#fff' , padding : 20 }
200- : null ;
202+ let innerContainerTransparentStyle = { backgroundColor : '#fff' } ;
201203
202204 return (
203205 < View style = { styles . container } >
@@ -207,29 +209,31 @@ class CPickerroll extends Component {
207209 visible = { this . state . visible }
208210 onRequestClose = { ( ) => { this . _setModalVisible ( false ) } }
209211 >
210- < View style = { [ styles . modalcontainer , modalBackgroundStyle ] } >
211- < Animated . View style = { [ styles . innerContainer , innerContainerTransparentStyle , { marginTop :this . state . animatedHeight } ] } >
212- < View style = { styles . nav } >
212+ < View style = { [ styles . modalContainer ] } >
213+ < View style = { styles . test } > </ View >
214+ < Animated . View style = { [ styles . innerContainer , { flex :this . state . flex } ] } >
215+ < View style = { [ styles . nav , this . props . navStyle ] } >
213216 < TouchableOpacity style = { styles . confirm } >
214217 < Text className = { "confirm" } onPress = { ( ) => { this . _confirmChose ( ) } }
215- style = { { textAlign : 'left' , marginLeft : 10 } } > Confirm </ Text >
218+ style = { [ styles . confirmBtnStyle , this . props . confirmBtnStyle ] } > { this . state . confirmBtnText } </ Text >
216219 </ TouchableOpacity >
220+ < Text style = { [ styles . pickerName , this . props . pickerNameStyle ] } > { this . props . pickerName } </ Text >
217221 < TouchableOpacity style = { styles . cancel } >
218222 < Text
219223 className = { "cancel" }
220- style = { { textAlign :'right' , marginRight :10 } }
221- onPress = { ( ) => { this . _cancelChose ( )
222- } }
223- > Cancel</ Text >
224+ onPress = { ( ) => { this . _cancelChose ( ) } }
225+ style = { [ styles . cancelBtnStyle , this . props . cancelBtnStyle ] }
226+ > { this . state . cancelBtnText } </ Text >
224227 </ TouchableOpacity >
225228 </ View >
226- < View style = { [ styles . pickContainer , this . state . selfStyle ] } >
229+ < View style = { [ styles . pickContainer ] } >
227230 { this . state . passData . map ( ( item , index ) => {
228231 return (
229232 < CPicker
230233 key = { index }
231234 className = { "test" + index }
232235 style = { { flex :1 } }
236+ itemStyle = { { flex :1 } }
233237 selectIndex = { this . state . selectIndex [ index ] }
234238 selectedValue = { this . state . selectedValue [ index ] }
235239 pickerStyle = { { flex :1 } }
@@ -251,15 +255,19 @@ class CPickerroll extends Component {
251255 </ Animated . View >
252256 </ View >
253257 </ Modal >
258+ < View style = { [ styles . outerInput , this . props . inputStyle ] } >
254259 < TextInput
260+ underlineColorAndroid = { 'transparent' }
255261 editable = { this . state . enable }
256- style = { [ styles . textInput , this . props . inputStyle ] }
262+ style = { [ styles . textInput , this . props . textStyle ] }
257263 ref = 'test'
258- multiline = { true }
259264 onFocus = { ( ) => { this . _setEventBegin ( ) } }
260265 placeholder = { this . state . inputValue }
261266 value = { this . state . inputValue }
262- />
267+ /> < TouchableOpacity style = { styles . iconOuter } onPress = { ( ) => { this . _setEventBegin ( ) } } >
268+ < Icon style = { styles . container2Icon } name = "sort-desc" color = "grey" size = { 20 } />
269+ </ TouchableOpacity >
270+ </ View >
263271 </ View >
264272
265273 ) ;
@@ -268,54 +276,7 @@ class CPickerroll extends Component {
268276
269277
270278
271- let styles = StyleSheet . create ( {
272-
273- container : {
274- justifyContent : 'center' ,
275- alignItems : 'center' ,
276- } ,
277- nav : {
278- flex : 1 ,
279- marginTop :10 ,
280- flexDirection : 'row' ,
281- height : 28 ,
282- alignSelf : 'stretch' ,
283- backgroundColor :'white' ,
284- } ,
285- confirm : {
286- flex :1 ,
287- } ,
288- cancel : {
289- flex :1 ,
290-
291- } ,
292- pickContainer :{
293- flex :1 ,
294- justifyContent : 'center' ,
295- alignSelf :'stretch' ,
296- flexDirection :'row' ,
297- } ,
298- modalcontainer : {
299- flex : 1 ,
300- justifyContent : 'center' ,
301- alignItems : 'center' ,
302- flexDirection : 'row' ,
303- } ,
304- innerContainer : {
305- flex :1 ,
306- alignItems : 'center' ,
307- justifyContent : 'flex-end' ,
308- flexDirection : 'column' ,
309- } ,
310- textInput :{
311- padding :10 ,
312- borderBottomWidth :1 ,
313- borderBottomColor : 'grey' ,
314- height : 40 ,
315- }
316-
317279
318- } ) ;
319280
320281
321282export default CPickerroll ;
0 commit comments