Skip to content

Commit

Permalink
⭐️ Impl: Add viewControllerInstanceID To ModalSheetView Events
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Oct 2, 2024
1 parent a05400f commit 9f0cfae
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
23 changes: 20 additions & 3 deletions ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ extension RNIModalSheetViewDelegate: ViewControllerLifecycleNotifiable {
self.dispatchEvent(
for: .onModalWillShow,
withPayload: [
"viewControllerInstanceID": sender.synthesizedStringID,
"isAnimated": isAnimated,
"isFirstAppearance": isFirstAppearance,
]
Expand All @@ -284,6 +285,7 @@ extension RNIModalSheetViewDelegate: ViewControllerLifecycleNotifiable {
self.dispatchEvent(
for: .onModalDidShow,
withPayload: [
"viewControllerInstanceID": sender.synthesizedStringID,
"isAnimated": isAnimated,
"isFirstAppearance": isFirstAppearance,
]
Expand All @@ -297,6 +299,7 @@ extension RNIModalSheetViewDelegate: ViewControllerLifecycleNotifiable {
self.dispatchEvent(
for: .onModalWillHide,
withPayload: [
"viewControllerInstanceID": sender.synthesizedStringID,
"isAnimated": isAnimated,
]
);
Expand All @@ -309,6 +312,7 @@ extension RNIModalSheetViewDelegate: ViewControllerLifecycleNotifiable {
self.dispatchEvent(
for: .onModalDidHide,
withPayload: [
"viewControllerInstanceID": sender.synthesizedStringID,
"isAnimated": isAnimated,
]
);
Expand All @@ -327,6 +331,7 @@ extension RNIModalSheetViewDelegate: ModalViewControllerEventsNotifiable {
self.dispatchEvent(
for: .onModalWillPresent,
withPayload: [
"viewControllerInstanceID": sender.synthesizedStringID,
"isAnimated": isAnimated,
]
);
Expand All @@ -339,6 +344,7 @@ extension RNIModalSheetViewDelegate: ModalViewControllerEventsNotifiable {
self.dispatchEvent(
for: .onModalDidPresent,
withPayload: [
"viewControllerInstanceID": sender.synthesizedStringID,
"isAnimated": isAnimated,
]
);
Expand All @@ -351,6 +357,7 @@ extension RNIModalSheetViewDelegate: ModalViewControllerEventsNotifiable {
self.dispatchEvent(
for: .onModalWillDismiss,
withPayload: [
"viewControllerInstanceID": sender.synthesizedStringID,
"isAnimated": isAnimated,
]
);
Expand All @@ -363,6 +370,7 @@ extension RNIModalSheetViewDelegate: ModalViewControllerEventsNotifiable {
self.dispatchEvent(
for: .onModalDidDismiss,
withPayload: [
"viewControllerInstanceID": sender.synthesizedStringID,
"isAnimated": isAnimated,
]
);
Expand All @@ -388,6 +396,7 @@ extension RNIModalSheetViewDelegate: ModalSheetPresentationStateEventsNotifiable
];

payload.unwrapAndMerge(withOther: [
"viewControllerInstanceID": self.modalSheetController?.synthesizedStringID,
"prevState": prevState?.asDictionary
]);

Expand All @@ -407,6 +416,7 @@ extension RNIModalSheetViewDelegate: ModalSheetPresentationStateEventsNotifiable
];

payload.unwrapAndMerge(withOther: [
"viewControllerInstanceID": self.modalSheetController?.synthesizedStringID,
"prevState": prevState?.asDictionary
]);

Expand All @@ -428,7 +438,9 @@ extension RNIModalSheetViewDelegate: ModalSheetViewControllerEventsNotifiable {
) {
self.dispatchEvent(
for: .onModalSheetDidAttemptToDismissViaGesture,
withPayload: [:]
withPayload: [
"viewControllerInstanceID": sender.synthesizedStringID,
]
);
};

Expand All @@ -438,7 +450,9 @@ extension RNIModalSheetViewDelegate: ModalSheetViewControllerEventsNotifiable {
) {
self.dispatchEvent(
for: .onModalSheetWillDismissViaGesture,
withPayload: [:]
withPayload: [
"viewControllerInstanceID": sender.synthesizedStringID,
]
);
};

Expand All @@ -448,7 +462,9 @@ extension RNIModalSheetViewDelegate: ModalSheetViewControllerEventsNotifiable {
) {
self.dispatchEvent(
for: .onModalSheetDidDismissViaGesture,
withPayload: [:]
withPayload: [
"viewControllerInstanceID": sender.synthesizedStringID,
]
);
};
};
Expand All @@ -466,6 +482,7 @@ extension RNIModalSheetViewDelegate: ModalFocusEventNotifiable {
) {

var payload: Dictionary<String, Any> = [
"viewControllerInstanceID": viewController.synthesizedStringID,
"currentState": currentState.rawValue,
"nextState": nextState.rawValue,
];
Expand Down
14 changes: 11 additions & 3 deletions src/native_components/RNIModalSheetVIew/RNIModalSheetViewEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
// ------------
Expand Down
9 changes: 9 additions & 0 deletions src/types/CommonModalEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9f0cfae

Please sign in to comment.