11import React from 'react' ;
22import { StyleSheet , View } from 'react-native' ;
3- import { PickerStateContext } from "../PickerStateProvider" ;
4- import { IOS_MODAL_HEIGHT } from "../constants" ;
3+ import { PickerStateContext } from '../PickerStateProvider' ;
4+ import { IOS_MODAL_ANIMATION_DURATION_MS , IOS_MODAL_HEIGHT } from '../constants' ;
5+
6+ function schedule ( callback , timeout ) {
7+ const handle = setTimeout ( callback , timeout ) ;
8+ return ( ) => clearTimeout ( handle ) ;
9+ }
510
611/**
712 * PickerAvoidingView is a React component that adjusts the view layout to avoid
@@ -19,10 +24,25 @@ export function PickerAvoidingView(props) {
1924 const context = React . useContext ( PickerStateContext ) ;
2025 const isPickerOpen = context && context . isPickerOpen ;
2126
27+ const [ shouldAddSpace , setShouldAddSpace ] = React . useState ( false ) ;
28+
29+ React . useEffect ( ( ) => {
30+ if ( isPickerOpen ) {
31+ // Add a delay, as adding the padding before the modal fully expanded gives a visually unpleasant effect
32+ return schedule ( ( ) => {
33+ setShouldAddSpace ( true ) ;
34+ } , IOS_MODAL_ANIMATION_DURATION_MS ) ;
35+ } else {
36+ setShouldAddSpace ( false ) ;
37+ }
38+ } , [ isPickerOpen ] ) ;
39+
2240 return (
23- < View style = { StyleSheet . compose ( props . style , {
24- paddingBottom : isPickerOpen ? IOS_MODAL_HEIGHT : 0 ,
25- } ) } >
41+ < View
42+ style = { StyleSheet . compose ( props . style , {
43+ paddingBottom : shouldAddSpace ? IOS_MODAL_HEIGHT : 0 ,
44+ } ) }
45+ >
2646 { props . children }
2747 </ View >
2848 ) ;
0 commit comments