@@ -31,28 +31,77 @@ import ModalContext from './ModalContext';
3131import ReanimatedModal from './ReanimatedModal' ;
3232import type ReanimatedModalProps from './ReanimatedModal/types' ;
3333import type BaseModalProps from './types' ;
34+ import type { FocusTrapOptions } from './types' ;
3435
3536const REANIMATED_MODAL_TYPES : Array < ValueOf < typeof CONST . MODAL . MODAL_TYPE > > = [ CONST . MODAL . MODAL_TYPE . BOTTOM_DOCKED , CONST . MODAL . MODAL_TYPE . FULLSCREEN ] ;
3637
3738type ModalComponentProps = ( ReactNativeModalProps | ReanimatedModalProps ) & {
3839 type ?: ValueOf < typeof CONST . MODAL . MODAL_TYPE > ;
3940 shouldUseReanimatedModal ?: boolean ;
41+ shouldPreventScrollOnFocus ?: boolean ;
42+ initialFocus ?: FocusTrapOptions [ 'initialFocus' ] ;
43+ isVisible : boolean ;
44+ isKeyboardActive : boolean ;
45+ saveFocusState : ( ) => void ;
4046} ;
4147
42- function ModalComponent ( { type, shouldUseReanimatedModal, ...props } : ModalComponentProps ) {
48+ function ModalComponent ( {
49+ type,
50+ shouldUseReanimatedModal,
51+ isVisible,
52+ shouldPreventScrollOnFocus,
53+ initialFocus,
54+ children,
55+ saveFocusState,
56+ onDismiss = ( ) => { } ,
57+ isKeyboardActive,
58+ ...props
59+ } : ModalComponentProps ) {
4360 // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
4461 if ( ( type && REANIMATED_MODAL_TYPES . includes ( type ) ) || shouldUseReanimatedModal ) {
4562 return (
4663 < ReanimatedModal
4764 // eslint-disable-next-line react/jsx-props-no-spreading
4865 { ...( props as ReanimatedModalProps ) }
4966 type = { type }
50- />
67+ isVisible = { isVisible }
68+ shouldPreventScrollOnFocus = { shouldPreventScrollOnFocus }
69+ initialFocus = { initialFocus }
70+ onDismiss = { onDismiss }
71+ >
72+ < ModalContent
73+ onModalWillShow = { saveFocusState }
74+ onDismiss = { onDismiss }
75+ >
76+ { children }
77+ </ ModalContent >
78+ { ! isKeyboardActive && < NavigationBar /> }
79+ </ ReanimatedModal >
5180 ) ;
5281 }
5382
54- // eslint-disable-next-line react/jsx-props-no-spreading
55- return < ReactNativeModal { ...( props as ReactNativeModalProps ) } /> ;
83+ return (
84+ < ReactNativeModal
85+ // eslint-disable-next-line react/jsx-props-no-spreading
86+ { ...( props as ReactNativeModalProps ) }
87+ isVisible = { isVisible }
88+ onDismiss = { onDismiss }
89+ >
90+ < ModalContent
91+ onModalWillShow = { saveFocusState }
92+ onDismiss = { onDismiss }
93+ >
94+ < FocusTrapForModal
95+ active = { isVisible }
96+ initialFocus = { initialFocus }
97+ shouldPreventScroll = { shouldPreventScrollOnFocus }
98+ >
99+ { children }
100+ </ FocusTrapForModal >
101+ </ ModalContent >
102+ { ! isKeyboardActive && < NavigationBar /> }
103+ </ ReactNativeModal >
104+ ) ;
56105}
57106
58107function BaseModal (
@@ -379,6 +428,8 @@ function BaseModal(
379428 onDismiss = { handleDismissModal }
380429 onSwipeComplete = { onClose }
381430 swipeDirection = { swipeDirection }
431+ shouldPreventScrollOnFocus = { shouldPreventScrollOnFocus }
432+ initialFocus = { initialFocus }
382433 swipeThreshold = { swipeThreshold }
383434 isVisible = { isVisible }
384435 backdropColor = { theme . overlay }
@@ -403,26 +454,16 @@ function BaseModal(
403454 customBackdrop = { shouldUseCustomBackdrop ? < Overlay onPress = { handleBackdropPress } /> : undefined }
404455 type = { type }
405456 shouldUseReanimatedModal = { shouldUseReanimatedModal }
457+ isKeyboardActive = { keyboardStateContextValue ?. isKeyboardActive }
458+ saveFocusState = { saveFocusState }
406459 >
407- < ModalContent
408- onModalWillShow = { saveFocusState }
409- onDismiss = { handleDismissModal }
460+ < Animated . View
461+ onLayout = { onViewLayout }
462+ style = { [ styles . defaultModalContainer , modalContainerStyle , modalPaddingStyles , ! isVisible && styles . pointerEventsNone , sidePanelReanimatedStyle ] }
463+ ref = { ref }
410464 >
411- < FocusTrapForModal
412- active = { isVisible }
413- initialFocus = { initialFocus }
414- shouldPreventScroll = { shouldPreventScrollOnFocus }
415- >
416- < Animated . View
417- onLayout = { onViewLayout }
418- style = { [ styles . defaultModalContainer , modalContainerStyle , modalPaddingStyles , ! isVisible && styles . pointerEventsNone , sidePanelReanimatedStyle ] }
419- ref = { ref }
420- >
421- < ColorSchemeWrapper > { children } </ ColorSchemeWrapper >
422- </ Animated . View >
423- </ FocusTrapForModal >
424- </ ModalContent >
425- { ! keyboardStateContextValue ?. isKeyboardActive && < NavigationBar /> }
465+ < ColorSchemeWrapper > { children } </ ColorSchemeWrapper >
466+ </ Animated . View >
426467 </ ModalComponent >
427468 </ View >
428469 </ ScreenWrapperOfflineIndicatorContext . Provider >
0 commit comments