Skip to content

Commit

Permalink
⭐️ Impl: ModalSheetView Focus Events
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Oct 2, 2024
1 parent 06f18fa commit 0d9206e
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 1 deletion.
30 changes: 30 additions & 0 deletions ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public final class RNIModalSheetViewDelegate: UIView, RNIContentView {
case onModalWillHide;
case onModalDidHide;

case onModalFocusChange;

case onModalSheetWillDismissViaGesture;
case onModalSheetDidDismissViaGesture;
case onModalSheetDidAttemptToDismissViaGesture;
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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<String, Any> = [
"currentState": currentState.rawValue,
"nextState": nextState.rawValue,
];

payload.unwrapAndMerge(withOther: [
"prevState": prevState?.rawValue,
]);

self.dispatchEvent(
for: .onModalFocusChange,
withPayload: payload
);
};
};
2 changes: 2 additions & 0 deletions ios/RNIModalSheetView/RNIModalSheetViewManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/components/ModalSheetView/ModalSheetViewTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export type ModalSheetViewInheritedProps = Pick<RNIModalSheetViewProps,
| 'onModalDidShow'
| 'onModalWillHide'
| 'onModalDidHide'
| 'onModalFocusChange'

// presentation controller delegate events
| 'onModalSheetWillDismissViaGesture'
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export type * from './types/PresentationControllerMetrics';
export type * from './types/ModalMetrics';
export type * from './types/CommonModalEvents';
export type * from './types/ModalSheetState';
export type * from './types/ModalFocusState';
export type * from './types/RNIModalSheetStateMetrics';
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from './RNIModalSheetViewNativeComponent';

import type { OnModalSheetStateDidChangeEvent, OnModalSheetStateWillChangeEvent, onModalSheetWillDismissViaGestureEvent, onModalSheetDidDismissViaGestureEvent, onModalSheetDidAttemptToDismissViaGestureEvent } from './RNIModalSheetViewEvents';
import type { OnModalWillPresentEvent, OnModalDidPresentEvent, OnModalWillShowEvent, OnModalDidShowEvent, OnModalWillHideEvent, OnModalDidHideEvent, OnModalWillDismissEvent, OnModalDidDismissEvent } from '../../types/CommonModalEvents';
import type { OnModalWillPresentEvent, OnModalDidPresentEvent, OnModalWillShowEvent, OnModalDidShowEvent, OnModalWillHideEvent, OnModalDidHideEvent, OnModalWillDismissEvent, OnModalDidDismissEvent, OnModalFocusChangeEventPayload, OnModalFocusChangeEvent } from '../../types/CommonModalEvents';


type RNIModalSheetViewNativeComponentBaseProps =
Expand All @@ -29,6 +29,8 @@ export type RNIModalSheetNativeViewBaseProps = RemapObject<RNIModalSheetViewNati
onModalWillHide: OnModalWillHideEvent;
onModalDidHide: OnModalDidHideEvent;

onModalFocusChange: OnModalFocusChangeEvent;

onModalSheetWillDismissViaGesture: onModalSheetWillDismissViaGestureEvent;
onModalSheetDidDismissViaGesture: onModalSheetDidDismissViaGestureEvent;
onModalSheetDidAttemptToDismissViaGesture: onModalSheetDidAttemptToDismissViaGestureEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export interface NativeProps extends ViewProps {
onModalWillHide?: BubblingEventHandler<{}>;
onModalDidHide?: BubblingEventHandler<{}>;

onModalFocusChange?: BubblingEventHandler<{}>;

// presentation controller delegate events
/**
* From `UIAdaptivePresentationControllerDelegate`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export type RNIModalSheetViewInheritedOptionalProps = Partial<Pick<RNIModalSheet
| 'onModalDidShow'
| 'onModalWillHide'
| 'onModalDidHide'
| 'onModalFocusChange'

// presentation controller delegate events
| 'onModalSheetWillDismissViaGesture'
Expand Down
9 changes: 9 additions & 0 deletions src/types/CommonModalEvents.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { BubblingEventHandler } from 'react-native/Libraries/Types/CodegenTypes';
import type { ModalFocusState } from './ModalFocusState';


// MARK: Event Objects
Expand Down Expand Up @@ -38,6 +39,12 @@ export type OnModalDidHideEventPayload = Readonly<{
isAnimated: boolean;
}>;

export type OnModalFocusChangeEventPayload = Readonly<{
prevState?: ModalFocusState;
currentState: ModalFocusState;
nextState: ModalFocusState;
}>;

// MARK: Events
// ------------

Expand Down Expand Up @@ -65,3 +72,5 @@ export type OnModalWillHideEvent =
export type OnModalDidHideEvent =
BubblingEventHandler<OnModalDidHideEventPayload>;

export type OnModalFocusChangeEvent =
BubblingEventHandler<OnModalFocusChangeEventPayload>;
6 changes: 6 additions & 0 deletions src/types/ModalFocusState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

export type ModalFocusState =
| 'blurred'
| 'blurring'
| 'focused'
| 'focusing';

0 comments on commit 0d9206e

Please sign in to comment.