From 91ce3f674f8f48a9b9a2853c1222057524fe380e Mon Sep 17 00:00:00 2001 From: Dominic Go Date: Tue, 1 Oct 2024 20:09:07 +0800 Subject: [PATCH] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20Impl:=20`ModalSheetView`?= =?UTF-8?q?=20Presentation=20Controller=20Related=20Events?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RNIModalSheetViewDelegate.swift | 47 ++++++++++++++++++- .../RNIModalSheetViewManager.mm | 4 ++ .../ModalSheetView/ModalSheetViewTypes.tsx | 5 ++ .../RNIModalSheetNativeView.ts | 6 ++- .../RNIModalSheetViewEvents.ts | 15 ++++++ .../RNIModalSheetViewNativeComponent.ts | 36 +++++++++++++- .../RNIModalSheetViewTypes.ts | 6 ++- 7 files changed, 114 insertions(+), 5 deletions(-) diff --git a/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift b/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift index 95236462..fbc5c7a7 100644 --- a/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift +++ b/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift @@ -30,6 +30,10 @@ public final class RNIModalSheetViewDelegate: UIView, RNIContentView { case onModalWillHide; case onModalDidHide; + case onModalSheetWillDismissViaGesture; + case onModalSheetDidDismissViaGesture; + case onModalSheetDidAttemptToDismissViaGesture; + case onModalSheetStateWillChange; case onModalSheetStateDidChange; }; @@ -307,6 +311,9 @@ extension RNIModalSheetViewDelegate: ViewControllerLifecycleNotifiable { }; }; +// MARK: - RNIModalSheetViewDelegate+ModalViewControllerEventsNotifiable +// --------------------------------------------------------------------- + extension RNIModalSheetViewDelegate: ModalViewControllerEventsNotifiable { public func notifyOnModalWillPresent( @@ -358,8 +365,8 @@ extension RNIModalSheetViewDelegate: ModalViewControllerEventsNotifiable { }; }; -// MARK: - RNIModalSheetViewDelegate+ViewControllerLifecycleNotifiable -// ------------------------------------------------------------------- +// MARK: - RNIModalSheetViewDelegate+ModalSheetPresentationStateEventsNotifiable +// ----------------------------------------------------------------------------- extension RNIModalSheetViewDelegate: ModalSheetPresentationStateEventsNotifiable { @@ -403,3 +410,39 @@ extension RNIModalSheetViewDelegate: ModalSheetPresentationStateEventsNotifiable ); }; }; + +// MARK: - RNIModalSheetViewDelegate+ModalSheetViewControllerEventsNotifiable +// -------------------------------------------------------------------------- + +extension RNIModalSheetViewDelegate: ModalSheetViewControllerEventsNotifiable { + + public func notifyOnSheetDidAttemptToDismissViaGesture( + sender: UIViewController, + presentationController: UIPresentationController + ) { + self.dispatchEvent( + for: .onModalSheetDidAttemptToDismissViaGesture, + withPayload: [:] + ); + }; + + public func notifyOnSheetDidDismissViaGesture( + sender: UIViewController, + presentationController: UIPresentationController + ) { + self.dispatchEvent( + for: .onModalSheetWillDismissViaGesture, + withPayload: [:] + ); + }; + + public func notifyOnSheetWillDismissViaGesture( + sender: UIViewController, + presentationController: UIPresentationController + ) { + self.dispatchEvent( + for: .onModalSheetDidDismissViaGesture, + withPayload: [:] + ); + }; +}; diff --git a/ios/RNIModalSheetView/RNIModalSheetViewManager.mm b/ios/RNIModalSheetView/RNIModalSheetViewManager.mm index dd1928cb..07979907 100644 --- a/ios/RNIModalSheetView/RNIModalSheetViewManager.mm +++ b/ios/RNIModalSheetView/RNIModalSheetViewManager.mm @@ -45,6 +45,10 @@ - (UIView *)view RNI_EXPORT_VIEW_EVENT(onModalWillHide, RCTBubblingEventBlock); RNI_EXPORT_VIEW_EVENT(onModalDidHide, RCTBubblingEventBlock); +RNI_EXPORT_VIEW_EVENT(onModalSheetWillDismissViaGesture, RCTBubblingEventBlock); +RNI_EXPORT_VIEW_EVENT(onModalSheetDidDismissViaGesture, RCTBubblingEventBlock); +RNI_EXPORT_VIEW_EVENT(onModalSheetDidAttemptToDismissViaGesture, RCTBubblingEventBlock); + RNI_EXPORT_VIEW_EVENT(onModalSheetStateWillChange, RCTBubblingEventBlock); RNI_EXPORT_VIEW_EVENT(onModalSheetStateDidChange, RCTBubblingEventBlock); diff --git a/src/components/ModalSheetView/ModalSheetViewTypes.tsx b/src/components/ModalSheetView/ModalSheetViewTypes.tsx index 0a275d4a..3ff58e90 100644 --- a/src/components/ModalSheetView/ModalSheetViewTypes.tsx +++ b/src/components/ModalSheetView/ModalSheetViewTypes.tsx @@ -46,6 +46,11 @@ export type ModalSheetViewInheritedProps = Pick; diff --git a/src/native_components/RNIModalSheetVIew/RNIModalSheetViewEvents.ts b/src/native_components/RNIModalSheetVIew/RNIModalSheetViewEvents.ts index 5e6f2107..223d133f 100644 --- a/src/native_components/RNIModalSheetVIew/RNIModalSheetViewEvents.ts +++ b/src/native_components/RNIModalSheetVIew/RNIModalSheetViewEvents.ts @@ -17,9 +17,24 @@ export type OnModalSheetStateDidChangeEventPayload = Readonly<{ currentState: RNIModalSheetStateMetrics; }>; +export type onModalSheetWillDismissViaGestureEventPayload = Readonly<{}>; + +export type onModalSheetDidDismissViaGestureEventPayload = Readonly<{}>; + +export type onModalSheetDidAttemptToDismissViaGestureEventPayload = Readonly<{}>; + // MARK: Events // ------------ +export type onModalSheetWillDismissViaGestureEvent = + BubblingEventHandler; + +export type onModalSheetDidDismissViaGestureEvent = + BubblingEventHandler; + +export type onModalSheetDidAttemptToDismissViaGestureEvent = + BubblingEventHandler; + export type OnModalSheetStateWillChangeEvent = BubblingEventHandler; diff --git a/src/native_components/RNIModalSheetVIew/RNIModalSheetViewNativeComponent.ts b/src/native_components/RNIModalSheetVIew/RNIModalSheetViewNativeComponent.ts index 1017141a..fb4cd8a3 100644 --- a/src/native_components/RNIModalSheetVIew/RNIModalSheetViewNativeComponent.ts +++ b/src/native_components/RNIModalSheetVIew/RNIModalSheetViewNativeComponent.ts @@ -7,6 +7,13 @@ import type { HostComponent, ViewProps } from 'react-native'; export interface NativeProps extends ViewProps { // props reactChildrenCount: Int32; + + /** + * From `UIAdaptivePresentationControllerDelegate`. + * Value from prop returned to: `presentationControllerShouldDismiss`. + * + * * return false to prevent dismissal of the view controller via gesture + * */ shouldAllowDismissalViaGesture?: boolean; // common/shared events @@ -25,7 +32,34 @@ export interface NativeProps extends ViewProps { onModalWillHide?: BubblingEventHandler<{}>; onModalDidHide?: BubblingEventHandler<{}>; - // events + // presentation controller delegate events + /** + * From `UIAdaptivePresentationControllerDelegate`. + * Event invoked by: `presentationControllerWillDismiss`. + * + * * Invoked when sheet dismissal via gesture started + * * Note: This is not called if the presentation is dismissed programatically. + * */ + onModalSheetWillDismissViaGesture?: BubblingEventHandler<{}>; + + /** + * From `UIAdaptivePresentationControllerDelegate`. + * Event invoked by: `presentationControllerDidDismiss`. + * + * * Invoked after sheet dismissal via gesture finished (after animations) + * * Note: This is not called if the presentation is dismissed programatically. + * */ + onModalSheetDidDismissViaGesture?: BubblingEventHandler<{}>; + + /** + * From `UIAdaptivePresentationControllerDelegate`. + * Event invoked by: `presentationControllerDidAttemptToDismiss`. + * + * * Invoked after sheet dismissal via gesture was prevented + * */ + onModalSheetDidAttemptToDismissViaGesture?: BubblingEventHandler<{}>; + + // sheet events onModalSheetStateWillChange?: BubblingEventHandler<{}>; onModalSheetStateDidChange?: BubblingEventHandler<{}>; }; diff --git a/src/native_components/RNIModalSheetVIew/RNIModalSheetViewTypes.ts b/src/native_components/RNIModalSheetVIew/RNIModalSheetViewTypes.ts index 364b1e36..879b3bf3 100644 --- a/src/native_components/RNIModalSheetVIew/RNIModalSheetViewTypes.ts +++ b/src/native_components/RNIModalSheetVIew/RNIModalSheetViewTypes.ts @@ -43,6 +43,11 @@ export type RNIModalSheetViewInheritedOptionalProps = Partial