diff --git a/src/components/ModalSheetView/ModalSheetView.tsx b/src/components/ModalSheetView/ModalSheetView.tsx index dc8c222b..727734ec 100644 --- a/src/components/ModalSheetView/ModalSheetView.tsx +++ b/src/components/ModalSheetView/ModalSheetView.tsx @@ -10,6 +10,9 @@ import { RNIModalSheetView, type RNIModalSheetViewRef } from '../../native_compo import { ModalSheetViewContext, type ModalSheetViewContextType } from '../../context/ModalSheetViewContext'; import { useLazyRef } from '../../hooks/useLazyRef'; +import { DEFAULT_MODAL_SHEET_VIEW_METRICS as MODAL_SHEET_STATE_METRICS_DEFAULT } from './ModalSheetViewConstants'; +import type { RNIModalSheetStateMetrics } from '../../types/RNIModalSheetStateMetrics'; + export const ModalSheetView = React.forwardRef< ModalSheetViewRef, @@ -18,6 +21,16 @@ export const ModalSheetView = React.forwardRef< const nativeRef = React.useRef(); + const [ + prevModalSheetStateMetrics, + setPrevModalSheetStateMetrics, + ] = React.useState(); + + const [ + currentModalSheetStateMetrics, + setCurrentModalSheetStateMetrics, + ] = React.useState(MODAL_SHEET_STATE_METRICS_DEFAULT); + const callbacksToInvokeOnNextRender = React.useRef void>>([]); React.useEffect(() => { const totalItems = callbacksToInvokeOnNextRender.current.length; @@ -117,6 +130,8 @@ export const ModalSheetView = React.forwardRef< }); const contextValue: ModalSheetViewContextType = { + prevModalSheetStateMetrics, + currentModalSheetStateMetrics, getModalSheetViewRef: () => rawRef.current! }; @@ -132,6 +147,13 @@ export const ModalSheetView = React.forwardRef< props.onModalDidHide?.(event); event.stopPropagation(); }} + onModalSheetStateDidChange={(event) => { + setPrevModalSheetStateMetrics(event.nativeEvent.prevState); + setCurrentModalSheetStateMetrics(event.nativeEvent.currentState); + + props.onModalSheetStateDidChange?.(event); + event.stopPropagation(); + }} > {children} diff --git a/src/components/ModalSheetView/ModalSheetViewConstants.ts b/src/components/ModalSheetView/ModalSheetViewConstants.ts new file mode 100644 index 00000000..6604a267 --- /dev/null +++ b/src/components/ModalSheetView/ModalSheetViewConstants.ts @@ -0,0 +1,10 @@ +import type { RNIModalSheetStateMetrics } from "../../types/RNIModalSheetStateMetrics"; + +export const DEFAULT_MODAL_SHEET_VIEW_METRICS: RNIModalSheetStateMetrics = { + state: 'dismissed', + isDismissed: true, + isDismissing: false, + isPresented: false, + isPresenting: false, + simplified: 'dismissed' +}; \ No newline at end of file diff --git a/src/context/ModalSheetViewContext.ts b/src/context/ModalSheetViewContext.ts index 9ccfe63a..dd1d3f54 100644 --- a/src/context/ModalSheetViewContext.ts +++ b/src/context/ModalSheetViewContext.ts @@ -1,7 +1,11 @@ import React from 'react'; import type { ModalSheetViewRef } from '../components/ModalSheetView'; +import type { RNIModalSheetStateMetrics } from '../types/RNIModalSheetStateMetrics'; export type ModalSheetViewContextType = { + prevModalSheetStateMetrics: RNIModalSheetStateMetrics | undefined; + currentModalSheetStateMetrics: RNIModalSheetStateMetrics; + getModalSheetViewRef: () => ModalSheetViewRef; };