import * as React from 'react' ; import AntPickerView from '@ant-design/react-native/lib/picker-view' ; import { noop } from '../../utils' ; import { PickerViewProps } from './PropsType' ; export default class _Picker extends React . Component < PickerViewProps > { static defaultProps = { data : [ ] , value : [ ] } ; onChange = ( val ) : void => { const { onChange = noop } = this . props ; onChange ( { detail : { value : val } } ) ; } ; handleChildren = ( children ) : any [ ] => { return children . map ( ( child , index ) => { return { label : this . getLabelFromChildren ( child ) , value : index } ; } ) ; } ; joinString = ( data ) : string => { return ( Array . isArray ( data ) ? data : [ data ] ) . join ( '' ) ; } ; getLabelFromChildren = ( child ) : string => { return child . props && child . props . children ? this . getLabelFromChildren ( child . props . children ) : this . joinString ( child ) ; } ; getDataFromChildren = ( children ) : any [ ] => { return ( Array . isArray ( children ) ? children : [ children ] ) . map ( ( child ) => { return this . handleChildren ( child . props && child . props . children ? child . props . children : [ child ] ) ; } ) ; } ; render ( ) { const { data , value , children , ... restProps } = this . props ; if ( ! children ) return null ; return ( < AntPickerView { ... restProps } cols = { 1 } value = { value } data = { data . length > 0 ? data : this . getDataFromChildren ( children ) } onChange = { this . onChange } cascade = { false } / > ) ; } }