From 248e740f79225676da73a6345652ddb46bb74f18 Mon Sep 17 00:00:00 2001 From: Dominic Go Date: Mon, 30 Sep 2024 17:47:49 +0800 Subject: [PATCH] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20Impl:=20`ModalSheetViewEve?= =?UTF-8?q?ntEmitter`=20-=20Modal=20Dismiss=20Events?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RNIModalSheetVIew/RNIModalSheetView.tsx | 18 ++++++++++++++++++ src/types/ModalSheetViewEventEmitter.ts | 6 +++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/native_components/RNIModalSheetVIew/RNIModalSheetView.tsx b/src/native_components/RNIModalSheetVIew/RNIModalSheetView.tsx index da5c361e..1c688cad 100644 --- a/src/native_components/RNIModalSheetVIew/RNIModalSheetView.tsx +++ b/src/native_components/RNIModalSheetVIew/RNIModalSheetView.tsx @@ -111,6 +111,24 @@ export const RNIModalSheetView = React.forwardRef< event.nativeEvent ); }} + onModalWillDismiss={(event) => { + props.onModalWillDismiss?.(event); + event.stopPropagation(); + + modalEventEmitterRef.current!.emit( + 'onModalWillDismiss', + event.nativeEvent + ); + }} + onModalDidDismiss={(event) => { + props.onModalDidDismiss?.(event); + event.stopPropagation(); + + modalEventEmitterRef.current!.emit( + 'onModalDidDismiss', + event.nativeEvent + ); + }} onModalWillShow={(event) => { props.onModalWillShow?.(event); event.stopPropagation(); diff --git a/src/types/ModalSheetViewEventEmitter.ts b/src/types/ModalSheetViewEventEmitter.ts index 2c6a7776..b6708fc9 100644 --- a/src/types/ModalSheetViewEventEmitter.ts +++ b/src/types/ModalSheetViewEventEmitter.ts @@ -1,7 +1,7 @@ import type { TSEventEmitter } from '@dominicstop/ts-event-emitter'; import type { RemapObject } from 'react-native-ios-utilities'; -import type { OnModalDidHideEventPayload, OnModalDidPresentEventPayload, OnModalDidShowEventPayload, OnModalWillHideEventPayload, OnModalWillPresentEventPayload, OnModalWillShowEventPayload } from './CommonModalEvents'; +import type { OnModalDidDidDismissEventPayload, OnModalDidHideEventPayload, OnModalDidPresentEventPayload, OnModalDidShowEventPayload, OnModalWillDismissEventPayload, OnModalWillHideEventPayload, OnModalWillPresentEventPayload, OnModalWillShowEventPayload } from './CommonModalEvents'; import type { OnModalSheetStateDidChangeEventPayload, OnModalSheetStateWillChangeEventPayload } from '../native_components/RNIModalSheetVIew'; @@ -9,6 +9,8 @@ export enum ModalSheetViewEvents { // common modal presentation events onModalWillPresent = "onModalWillPresent", onModalDidPresent = "onModalDidPresent", + onModalWillDismiss = "onModalWillDismiss", + onModalDidDismiss = "onModalDidDismiss", onModalWillShow = "onModalWillShow", onModalDidShow = "onModalDidShow", onModalWillHide = "onModalWillHide", @@ -24,6 +26,8 @@ export type ModalSheetViewEventKeys = keyof typeof ModalSheetViewEvents; export type ModalSheetViewEventEmitterMap = RemapObject