Skip to content

Commit

Permalink
⭐️ Impl: ModalSheetView Dismiss Events
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Sep 30, 2024
1 parent 1f2ac6d commit 3918772
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 2 deletions.
27 changes: 27 additions & 0 deletions ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public final class RNIModalSheetViewDelegate: UIView, RNIContentView {
case onModalWillPresent;
case onModalDidPresent;

case onModalWillDismiss;
case onModalDidDismiss;

case onModalWillShow;
case onModalDidShow;

Expand Down Expand Up @@ -304,6 +307,30 @@ extension RNIModalSheetViewDelegate: ModalViewControllerEventsNotifiable {
]
);
};

public func notifyOnModalWillDismiss(
sender: UIViewController,
isAnimated: Bool
) {
self.dispatchEvent(
for: .onModalWillDismiss,
withPayload: [
"isAnimated": isAnimated,
]
);
};

public func notifyOnModalDidDismiss(
sender: UIViewController,
isAnimated: Bool
) {
self.dispatchEvent(
for: .onModalDidDismiss,
withPayload: [
"isAnimated": isAnimated,
]
);
};
};

// MARK: - RNIModalSheetViewDelegate+ViewControllerLifecycleNotifiable
Expand Down
3 changes: 3 additions & 0 deletions ios/RNIModalSheetView/RNIModalSheetViewManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ - (UIView *)view
RNI_EXPORT_VIEW_EVENT(onModalWillPresent, RCTBubblingEventBlock);
RNI_EXPORT_VIEW_EVENT(onModalDidPresent, RCTBubblingEventBlock);

RNI_EXPORT_VIEW_EVENT(onModalWillDismiss, RCTBubblingEventBlock);
RNI_EXPORT_VIEW_EVENT(onModalDidDismiss, RCTBubblingEventBlock);

RNI_EXPORT_VIEW_EVENT(onModalWillShow, RCTBubblingEventBlock);
RNI_EXPORT_VIEW_EVENT(onModalDidShow, RCTBubblingEventBlock);

Expand Down
2 changes: 1 addition & 1 deletion src/components/ModalSheetView/ModalSheetView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export const ModalSheetView = React.forwardRef<
{...props}
ref={ref => nativeRef.current = ref}
style={styles.nativeModalSheet}
onModalDidHide={(event) => {
onModalDidDismiss={(event) => {
setShouldExplicitlyMountModalContents(false);

props.onModalDidHide?.(event);
Expand Down
2 changes: 2 additions & 0 deletions src/components/ModalSheetView/ModalSheetViewTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export type ModalSheetViewInheritedProps = Pick<RNIModalSheetViewProps,
// common modal presentation events
| 'onModalWillPresent'
| 'onModalDidPresent'
| 'onModalWillDismiss'
| 'onModalDidDismiss'
| 'onModalWillShow'
| 'onModalDidShow'
| 'onModalWillHide'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from './RNIModalSheetViewNativeComponent';

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


type RNIModalSheetViewNativeComponentBaseProps =
Expand All @@ -19,6 +19,9 @@ export type RNIModalSheetNativeViewBaseProps = RemapObject<RNIModalSheetViewNati
onModalWillPresent: OnModalWillPresentEvent;
onModalDidPresent: OnModalDidPresentEvent;

onModalWillDismiss: OnModalWillDismissEvent;
onModalDidDismiss: OnModalDidDismissEvent;

onModalWillShow: OnModalWillShowEvent;
onModalDidShow: OnModalDidShowEvent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export interface NativeProps extends ViewProps {
onModalWillPresent?: BubblingEventHandler<{}>;
onModalDidPresent?: BubblingEventHandler<{}>;

onModalWillDismiss: BubblingEventHandler<{}>;
onModalDidDismiss: BubblingEventHandler<{}>;

onModalWillShow?: BubblingEventHandler<{}>;
onModalDidShow?: BubblingEventHandler<{}>;
onModalWillHide?: BubblingEventHandler<{}>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export type RNIModalSheetViewInheritedOptionalProps = Partial<Pick<RNIModalSheet
// common modal presentation events
| 'onModalWillPresent'
| 'onModalDidPresent'
| 'onModalWillDismiss'
| 'onModalDidDismiss'
| 'onModalWillShow'
| 'onModalDidShow'
| 'onModalWillHide'
Expand Down
14 changes: 14 additions & 0 deletions src/types/CommonModalEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ export type OnModalDidPresentEventPayload = Readonly<{
isAnimated: boolean;
}>;

export type OnModalWillDismissEventPayload = Readonly<{
isAnimated: boolean;
}>;

export type OnModalDidDidDismissEventPayload = Readonly<{
isAnimated: boolean;
}>;

export type OnModalWillShowEventPayload = Readonly<{
isAnimated: boolean;
isFirstAppearance: boolean;
Expand Down Expand Up @@ -39,6 +47,12 @@ export type OnModalWillPresentEvent =
export type OnModalDidPresentEvent =
BubblingEventHandler<OnModalDidPresentEventPayload>;

export type OnModalWillDismissEvent =
BubblingEventHandler<OnModalWillDismissEventPayload>;

export type OnModalDidDismissEvent =
BubblingEventHandler<OnModalDidDidDismissEventPayload>;

export type OnModalWillShowEvent =
BubblingEventHandler<OnModalWillShowEventPayload>;

Expand Down

0 comments on commit 3918772

Please sign in to comment.