import { ActionSheetIOS , ActionSheetIOSOptions , findNodeHandle } from 'react-native' ; /** wrapper func for setState that returns a promise */ export function setStateAsync < T > ( that , newState ) { return new Promise < void > ( ( resolve ) => { that . setState ( newState , ( ) => { resolve ( ) ; } ) ; } ) ; } ; /** wrapper for timeout that returns a promise */ export function timeout ( ms ) { return new Promise < void > ( resolve => { const timeoutID = setTimeout ( ( ) => { clearTimeout ( timeoutID ) ; resolve ( ) ; } , ms ) ; } ) ; } ; export function pad ( num , places = 2 ) { return String ( num ) . padStart ( places , '0' ) ; } ; export function asyncActionSheet ( config ) { return new Promise ( resolve => { ActionSheetIOS . showActionSheetWithOptions ( config , ( buttonIndex ) => { resolve ( buttonIndex ) ; } ) ; } ) ; } ; export function asyncActionSheetConfirm ( config ) { const isDestructive = config . isDestructive ?? false ; return new Promise ( resolve => { ActionSheetIOS . showActionSheetWithOptions ( { title : config . title , message : config . message , options : [ 'Cancel' , config . confirmText ] , cancelButtonIndex : 0 , ... ( isDestructive && { destructiveButtonIndex : 1 , } ) , } , ( buttonIndex ) => { resolve ( ( buttonIndex === 1 ) ) ; } ) ; } ) ; } ; export function getNativeNodeHandle ( nativeRef ) { const nodeHandle = findNodeHandle ( nativeRef ) ; if ( nodeHandle == null ) { throw new Error ( 'Unable to get the node handle for the native ref.' ) ; } ; return nodeHandle ; } ;