From 39187728d1a5b9f67f7e994c8614ae89c33c0e03 Mon Sep 17 00:00:00 2001 From: Dominic Go Date: Mon, 30 Sep 2024 17:33:31 +0800 Subject: [PATCH] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20Impl:=20`ModalSheetView`?= =?UTF-8?q?=20Dismiss=20Events?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RNIModalSheetViewDelegate.swift | 27 +++++++++++++++++++ .../RNIModalSheetViewManager.mm | 3 +++ .../ModalSheetView/ModalSheetView.tsx | 2 +- .../ModalSheetView/ModalSheetViewTypes.tsx | 2 ++ .../RNIModalSheetNativeView.ts | 5 +++- .../RNIModalSheetViewNativeComponent.ts | 3 +++ .../RNIModalSheetViewTypes.ts | 2 ++ src/types/CommonModalEvents.ts | 14 ++++++++++ 8 files changed, 56 insertions(+), 2 deletions(-) diff --git a/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift b/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift index 62a651cd..8637b148 100644 --- a/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift +++ b/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift @@ -21,6 +21,9 @@ public final class RNIModalSheetViewDelegate: UIView, RNIContentView { case onModalWillPresent; case onModalDidPresent; + case onModalWillDismiss; + case onModalDidDismiss; + case onModalWillShow; case onModalDidShow; @@ -304,6 +307,30 @@ extension RNIModalSheetViewDelegate: ModalViewControllerEventsNotifiable { ] ); }; + + public func notifyOnModalWillDismiss( + sender: UIViewController, + isAnimated: Bool + ) { + self.dispatchEvent( + for: .onModalWillDismiss, + withPayload: [ + "isAnimated": isAnimated, + ] + ); + }; + + public func notifyOnModalDidDismiss( + sender: UIViewController, + isAnimated: Bool + ) { + self.dispatchEvent( + for: .onModalDidDismiss, + withPayload: [ + "isAnimated": isAnimated, + ] + ); + }; }; // MARK: - RNIModalSheetViewDelegate+ViewControllerLifecycleNotifiable diff --git a/ios/RNIModalSheetView/RNIModalSheetViewManager.mm b/ios/RNIModalSheetView/RNIModalSheetViewManager.mm index 0154ffa5..c7b5872d 100644 --- a/ios/RNIModalSheetView/RNIModalSheetViewManager.mm +++ b/ios/RNIModalSheetView/RNIModalSheetViewManager.mm @@ -31,6 +31,9 @@ - (UIView *)view RNI_EXPORT_VIEW_EVENT(onModalWillPresent, RCTBubblingEventBlock); RNI_EXPORT_VIEW_EVENT(onModalDidPresent, RCTBubblingEventBlock); +RNI_EXPORT_VIEW_EVENT(onModalWillDismiss, RCTBubblingEventBlock); +RNI_EXPORT_VIEW_EVENT(onModalDidDismiss, RCTBubblingEventBlock); + RNI_EXPORT_VIEW_EVENT(onModalWillShow, RCTBubblingEventBlock); RNI_EXPORT_VIEW_EVENT(onModalDidShow, RCTBubblingEventBlock); diff --git a/src/components/ModalSheetView/ModalSheetView.tsx b/src/components/ModalSheetView/ModalSheetView.tsx index 727734ec..b109c231 100644 --- a/src/components/ModalSheetView/ModalSheetView.tsx +++ b/src/components/ModalSheetView/ModalSheetView.tsx @@ -141,7 +141,7 @@ export const ModalSheetView = React.forwardRef< {...props} ref={ref => nativeRef.current = ref} style={styles.nativeModalSheet} - onModalDidHide={(event) => { + onModalDidDismiss={(event) => { setShouldExplicitlyMountModalContents(false); props.onModalDidHide?.(event); diff --git a/src/components/ModalSheetView/ModalSheetViewTypes.tsx b/src/components/ModalSheetView/ModalSheetViewTypes.tsx index 32ee171f..4a621f07 100644 --- a/src/components/ModalSheetView/ModalSheetViewTypes.tsx +++ b/src/components/ModalSheetView/ModalSheetViewTypes.tsx @@ -40,6 +40,8 @@ export type ModalSheetViewInheritedProps = Pick; onModalDidPresent?: BubblingEventHandler<{}>; + onModalWillDismiss: BubblingEventHandler<{}>; + onModalDidDismiss: BubblingEventHandler<{}>; + onModalWillShow?: BubblingEventHandler<{}>; onModalDidShow?: BubblingEventHandler<{}>; onModalWillHide?: BubblingEventHandler<{}>; diff --git a/src/native_components/RNIModalSheetVIew/RNIModalSheetViewTypes.ts b/src/native_components/RNIModalSheetVIew/RNIModalSheetViewTypes.ts index c8ed7718..51477476 100644 --- a/src/native_components/RNIModalSheetVIew/RNIModalSheetViewTypes.ts +++ b/src/native_components/RNIModalSheetVIew/RNIModalSheetViewTypes.ts @@ -35,6 +35,8 @@ export type RNIModalSheetViewInheritedOptionalProps = Partial; +export type OnModalWillDismissEventPayload = Readonly<{ + isAnimated: boolean; +}>; + +export type OnModalDidDidDismissEventPayload = Readonly<{ + isAnimated: boolean; +}>; + export type OnModalWillShowEventPayload = Readonly<{ isAnimated: boolean; isFirstAppearance: boolean; @@ -39,6 +47,12 @@ export type OnModalWillPresentEvent = export type OnModalDidPresentEvent = BubblingEventHandler; +export type OnModalWillDismissEvent = + BubblingEventHandler; + +export type OnModalDidDismissEvent = + BubblingEventHandler; + export type OnModalWillShowEvent = BubblingEventHandler;