import React from 'react' ; import { UIManager , findNodeHandle } from 'react-native' ; import PromiseFactory from '../PromiseFactory' ; import { UIPickerSelectionsEvent } from '../../config/interfaces' ; interface Selections { [ column ] : string ; } /**
 * Methods to control and observe the native iOS `UIPickerView`.
 */ export default class UIPickerManager { private ref : React . RefObject < any > = React . createRef ( ) ; private promiseFactory : PromiseFactory = new PromiseFactory ( ) ; get reactRef ( ) : React . RefObject < any > { return this . ref ; } param { number } index param { string } columnKey param { boolean = true return { void } selectIndex = ( index , column , animated = true ) : void => { if ( this . ref . current ) { UIManager . dispatchViewManagerCommand ( findNodeHandle ( this . ref . current ) , ( UIManager as any ) . UIPicker . Commands . selectIndex , [ index , column , animated ] ) ; } } ; return { Promise < Selections > } getCurrentSelections = ( ) : Promise < Selections > => { if ( ! this . ref . current ) { return Promise . resolve ( { } ) ; } const promise = new Promise ( ( resolve , reject ) => { const pid = this . promiseFactory . add ( { resolve , reject } ) ; UIManager . dispatchViewManagerCommand ( findNodeHandle ( this . ref . current ) , ( UIManager as any ) . UIPicker . Commands . emitSelections , [ pid ] ) ; } ) ; return promise ; } ; param { UIPickerSelectionsEvent } return { void } ingestSelections = ( { nativeEvent : { selections , pid } } ) : void => { const promise = this . promiseFactory . get ( pid ) ; if ( promise ) { promise . resolve ( selections ) ; this . promiseFactory . delete ( pid ) ; } } ; }