From 9f0cfae6ddf454d25d616dd6f89a52e58defd32b Mon Sep 17 00:00:00 2001 From: Dominic Go Date: Wed, 2 Oct 2024 14:28:37 +0800 Subject: [PATCH] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20Impl:=20Add=20`viewControl?= =?UTF-8?q?lerInstanceID`=20To=20`ModalSheetView`=20Events?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RNIModalSheetViewDelegate.swift | 23 ++++++++++++++++--- .../RNIModalSheetViewEvents.ts | 14 ++++++++--- src/types/CommonModalEvents.ts | 9 ++++++++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift b/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift index c7e3cfa..9774453 100644 --- a/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift +++ b/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift @@ -270,6 +270,7 @@ extension RNIModalSheetViewDelegate: ViewControllerLifecycleNotifiable { self.dispatchEvent( for: .onModalWillShow, withPayload: [ + "viewControllerInstanceID": sender.synthesizedStringID, "isAnimated": isAnimated, "isFirstAppearance": isFirstAppearance, ] @@ -284,6 +285,7 @@ extension RNIModalSheetViewDelegate: ViewControllerLifecycleNotifiable { self.dispatchEvent( for: .onModalDidShow, withPayload: [ + "viewControllerInstanceID": sender.synthesizedStringID, "isAnimated": isAnimated, "isFirstAppearance": isFirstAppearance, ] @@ -297,6 +299,7 @@ extension RNIModalSheetViewDelegate: ViewControllerLifecycleNotifiable { self.dispatchEvent( for: .onModalWillHide, withPayload: [ + "viewControllerInstanceID": sender.synthesizedStringID, "isAnimated": isAnimated, ] ); @@ -309,6 +312,7 @@ extension RNIModalSheetViewDelegate: ViewControllerLifecycleNotifiable { self.dispatchEvent( for: .onModalDidHide, withPayload: [ + "viewControllerInstanceID": sender.synthesizedStringID, "isAnimated": isAnimated, ] ); @@ -327,6 +331,7 @@ extension RNIModalSheetViewDelegate: ModalViewControllerEventsNotifiable { self.dispatchEvent( for: .onModalWillPresent, withPayload: [ + "viewControllerInstanceID": sender.synthesizedStringID, "isAnimated": isAnimated, ] ); @@ -339,6 +344,7 @@ extension RNIModalSheetViewDelegate: ModalViewControllerEventsNotifiable { self.dispatchEvent( for: .onModalDidPresent, withPayload: [ + "viewControllerInstanceID": sender.synthesizedStringID, "isAnimated": isAnimated, ] ); @@ -351,6 +357,7 @@ extension RNIModalSheetViewDelegate: ModalViewControllerEventsNotifiable { self.dispatchEvent( for: .onModalWillDismiss, withPayload: [ + "viewControllerInstanceID": sender.synthesizedStringID, "isAnimated": isAnimated, ] ); @@ -363,6 +370,7 @@ extension RNIModalSheetViewDelegate: ModalViewControllerEventsNotifiable { self.dispatchEvent( for: .onModalDidDismiss, withPayload: [ + "viewControllerInstanceID": sender.synthesizedStringID, "isAnimated": isAnimated, ] ); @@ -388,6 +396,7 @@ extension RNIModalSheetViewDelegate: ModalSheetPresentationStateEventsNotifiable ]; payload.unwrapAndMerge(withOther: [ + "viewControllerInstanceID": self.modalSheetController?.synthesizedStringID, "prevState": prevState?.asDictionary ]); @@ -407,6 +416,7 @@ extension RNIModalSheetViewDelegate: ModalSheetPresentationStateEventsNotifiable ]; payload.unwrapAndMerge(withOther: [ + "viewControllerInstanceID": self.modalSheetController?.synthesizedStringID, "prevState": prevState?.asDictionary ]); @@ -428,7 +438,9 @@ extension RNIModalSheetViewDelegate: ModalSheetViewControllerEventsNotifiable { ) { self.dispatchEvent( for: .onModalSheetDidAttemptToDismissViaGesture, - withPayload: [:] + withPayload: [ + "viewControllerInstanceID": sender.synthesizedStringID, + ] ); }; @@ -438,7 +450,9 @@ extension RNIModalSheetViewDelegate: ModalSheetViewControllerEventsNotifiable { ) { self.dispatchEvent( for: .onModalSheetWillDismissViaGesture, - withPayload: [:] + withPayload: [ + "viewControllerInstanceID": sender.synthesizedStringID, + ] ); }; @@ -448,7 +462,9 @@ extension RNIModalSheetViewDelegate: ModalSheetViewControllerEventsNotifiable { ) { self.dispatchEvent( for: .onModalSheetDidDismissViaGesture, - withPayload: [:] + withPayload: [ + "viewControllerInstanceID": sender.synthesizedStringID, + ] ); }; }; @@ -466,6 +482,7 @@ extension RNIModalSheetViewDelegate: ModalFocusEventNotifiable { ) { var payload: Dictionary = [ + "viewControllerInstanceID": viewController.synthesizedStringID, "currentState": currentState.rawValue, "nextState": nextState.rawValue, ]; diff --git a/src/native_components/RNIModalSheetVIew/RNIModalSheetViewEvents.ts b/src/native_components/RNIModalSheetVIew/RNIModalSheetViewEvents.ts index 223d133..fb51acf 100644 --- a/src/native_components/RNIModalSheetVIew/RNIModalSheetViewEvents.ts +++ b/src/native_components/RNIModalSheetVIew/RNIModalSheetViewEvents.ts @@ -7,21 +7,29 @@ import type { RNIModalSheetStateMetrics } from '../../types/RNIModalSheetStateMe // ------------------- export type OnModalSheetStateWillChangeEventPayload = Readonly<{ + viewControllerInstanceID: string; prevState?: RNIModalSheetStateMetrics; currentState: RNIModalSheetStateMetrics; nextState: RNIModalSheetStateMetrics; }>; export type OnModalSheetStateDidChangeEventPayload = Readonly<{ + viewControllerInstanceID: string; prevState: RNIModalSheetStateMetrics; currentState: RNIModalSheetStateMetrics; }>; -export type onModalSheetWillDismissViaGestureEventPayload = Readonly<{}>; +export type onModalSheetWillDismissViaGestureEventPayload = Readonly<{ + viewControllerInstanceID: string; +}>; -export type onModalSheetDidDismissViaGestureEventPayload = Readonly<{}>; +export type onModalSheetDidDismissViaGestureEventPayload = Readonly<{ + viewControllerInstanceID: string; +}>; -export type onModalSheetDidAttemptToDismissViaGestureEventPayload = Readonly<{}>; +export type onModalSheetDidAttemptToDismissViaGestureEventPayload = Readonly<{ + viewControllerInstanceID: string; +}>; // MARK: Events // ------------ diff --git a/src/types/CommonModalEvents.ts b/src/types/CommonModalEvents.ts index a0a1e90..0151f9b 100644 --- a/src/types/CommonModalEvents.ts +++ b/src/types/CommonModalEvents.ts @@ -6,40 +6,49 @@ import type { ModalFocusState } from './ModalFocusState'; // ------------------- export type OnModalWillPresentEventPayload = Readonly<{ + viewControllerInstanceID: string; isAnimated: boolean; }>; export type OnModalDidPresentEventPayload = Readonly<{ + viewControllerInstanceID: string; isAnimated: boolean; }>; export type OnModalWillDismissEventPayload = Readonly<{ + viewControllerInstanceID: string; isAnimated: boolean; }>; export type OnModalDidDidDismissEventPayload = Readonly<{ + viewControllerInstanceID: string; isAnimated: boolean; }>; export type OnModalWillShowEventPayload = Readonly<{ + viewControllerInstanceID: string; isAnimated: boolean; isFirstAppearance: boolean; }>; export type OnModalDidShowEventPayload = Readonly<{ + viewControllerInstanceID: string; isAnimated: boolean; isFirstAppearance: boolean; }>; export type OnModalWillHideEventPayload = Readonly<{ + viewControllerInstanceID: string; isAnimated: boolean; }>; export type OnModalDidHideEventPayload = Readonly<{ + viewControllerInstanceID: string; isAnimated: boolean; }>; export type OnModalFocusChangeEventPayload = Readonly<{ + viewControllerInstanceID: string; prevState?: ModalFocusState; currentState: ModalFocusState; nextState: ModalFocusState;