diff --git a/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift b/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift index d6e85c8..fb08454 100644 --- a/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift +++ b/ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift @@ -30,6 +30,8 @@ public final class RNIModalSheetViewDelegate: UIView, RNIContentView { case onModalWillHide; case onModalDidHide; + case onModalFocusChange; + case onModalSheetWillDismissViaGesture; case onModalSheetDidDismissViaGesture; case onModalSheetDidAttemptToDismissViaGesture; @@ -113,6 +115,7 @@ public final class RNIModalSheetViewDelegate: UIView, RNIContentView { modalVC.lifecycleEventDelegates.add(self); modalVC.modalLifecycleEventDelegates.add(self); modalVC.sheetPresentationStateMachine.eventDelegates.add(self); + modalVC.modalFocusEventDelegates.add(self); return modalVC; }; @@ -450,3 +453,30 @@ extension RNIModalSheetViewDelegate: ModalSheetViewControllerEventsNotifiable { ); }; }; + +// MARK: - RNIModalSheetViewDelegate+ModalSheetViewControllerEventsNotifiable +// -------------------------------------------------------------------------- + +extension RNIModalSheetViewDelegate: ModalFocusEventNotifiable { + + public func notifyForModalFocusStateChange( + prevState: ModalFocusState?, + currentState: ModalFocusState, + nextState: ModalFocusState + ) { + + var payload: Dictionary = [ + "currentState": currentState.rawValue, + "nextState": nextState.rawValue, + ]; + + payload.unwrapAndMerge(withOther: [ + "prevState": prevState?.rawValue, + ]); + + self.dispatchEvent( + for: .onModalFocusChange, + withPayload: payload + ); + }; +}; diff --git a/ios/RNIModalSheetView/RNIModalSheetViewManager.mm b/ios/RNIModalSheetView/RNIModalSheetViewManager.mm index 0797990..e99bdcd 100644 --- a/ios/RNIModalSheetView/RNIModalSheetViewManager.mm +++ b/ios/RNIModalSheetView/RNIModalSheetViewManager.mm @@ -45,6 +45,8 @@ - (UIView *)view RNI_EXPORT_VIEW_EVENT(onModalWillHide, RCTBubblingEventBlock); RNI_EXPORT_VIEW_EVENT(onModalDidHide, RCTBubblingEventBlock); +RNI_EXPORT_VIEW_EVENT(onModalFocusChange, RCTBubblingEventBlock); + RNI_EXPORT_VIEW_EVENT(onModalSheetWillDismissViaGesture, RCTBubblingEventBlock); RNI_EXPORT_VIEW_EVENT(onModalSheetDidDismissViaGesture, RCTBubblingEventBlock); RNI_EXPORT_VIEW_EVENT(onModalSheetDidAttemptToDismissViaGesture, RCTBubblingEventBlock); diff --git a/src/components/ModalSheetView/ModalSheetViewTypes.tsx b/src/components/ModalSheetView/ModalSheetViewTypes.tsx index 3ff58e9..0032720 100644 --- a/src/components/ModalSheetView/ModalSheetViewTypes.tsx +++ b/src/components/ModalSheetView/ModalSheetViewTypes.tsx @@ -46,6 +46,7 @@ export type ModalSheetViewInheritedProps = Pick; onModalDidHide?: BubblingEventHandler<{}>; + onModalFocusChange?: BubblingEventHandler<{}>; + // presentation controller delegate events /** * From `UIAdaptivePresentationControllerDelegate`. diff --git a/src/native_components/RNIModalSheetVIew/RNIModalSheetViewTypes.ts b/src/native_components/RNIModalSheetVIew/RNIModalSheetViewTypes.ts index 879b3bf..22e865d 100644 --- a/src/native_components/RNIModalSheetVIew/RNIModalSheetViewTypes.ts +++ b/src/native_components/RNIModalSheetVIew/RNIModalSheetViewTypes.ts @@ -42,6 +42,7 @@ export type RNIModalSheetViewInheritedOptionalProps = Partial; +export type OnModalFocusChangeEventPayload = Readonly<{ + prevState?: ModalFocusState; + currentState: ModalFocusState; + nextState: ModalFocusState; +}>; + // MARK: Events // ------------ @@ -65,3 +72,5 @@ export type OnModalWillHideEvent = export type OnModalDidHideEvent = BubblingEventHandler; +export type OnModalFocusChangeEvent = + BubblingEventHandler; \ No newline at end of file diff --git a/src/types/ModalFocusState.ts b/src/types/ModalFocusState.ts new file mode 100644 index 0000000..a73753e --- /dev/null +++ b/src/types/ModalFocusState.ts @@ -0,0 +1,6 @@ + +export type ModalFocusState = + | 'blurred' + | 'blurring' + | 'focused' + | 'focusing'; \ No newline at end of file