Skip to content

Commit

Permalink
⭐️ Impl: ModalSheetView Presentation Controller Related Events
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Oct 1, 2024
1 parent ba3f001 commit 91ce3f6
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 5 deletions.
47 changes: 45 additions & 2 deletions ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public final class RNIModalSheetViewDelegate: UIView, RNIContentView {
case onModalWillHide;
case onModalDidHide;

case onModalSheetWillDismissViaGesture;
case onModalSheetDidDismissViaGesture;
case onModalSheetDidAttemptToDismissViaGesture;

case onModalSheetStateWillChange;
case onModalSheetStateDidChange;
};
Expand Down Expand Up @@ -307,6 +311,9 @@ extension RNIModalSheetViewDelegate: ViewControllerLifecycleNotifiable {
};
};

// MARK: - RNIModalSheetViewDelegate+ModalViewControllerEventsNotifiable
// ---------------------------------------------------------------------

extension RNIModalSheetViewDelegate: ModalViewControllerEventsNotifiable {

public func notifyOnModalWillPresent(
Expand Down Expand Up @@ -358,8 +365,8 @@ extension RNIModalSheetViewDelegate: ModalViewControllerEventsNotifiable {
};
};

// MARK: - RNIModalSheetViewDelegate+ViewControllerLifecycleNotifiable
// -------------------------------------------------------------------
// MARK: - RNIModalSheetViewDelegate+ModalSheetPresentationStateEventsNotifiable
// -----------------------------------------------------------------------------

extension RNIModalSheetViewDelegate: ModalSheetPresentationStateEventsNotifiable {

Expand Down Expand Up @@ -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: [:]
);
};
};
4 changes: 4 additions & 0 deletions ios/RNIModalSheetView/RNIModalSheetViewManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 5 additions & 0 deletions src/components/ModalSheetView/ModalSheetViewTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ export type ModalSheetViewInheritedProps = Pick<RNIModalSheetViewProps,
| 'onModalDidShow'
| 'onModalWillHide'
| 'onModalDidHide'

// presentation controller delegate events
| 'onModalSheetWillDismissViaGesture'
| 'onModalSheetDidDismissViaGesture'
| 'onModalSheetDidAttemptToDismissViaGesture'

// modal sheet events
| 'onModalSheetStateWillChange'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
type NativeProps as RNIModalSheetViewNativeComponentProps,
} from './RNIModalSheetViewNativeComponent';

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


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

onModalSheetWillDismissViaGesture: onModalSheetWillDismissViaGestureEvent;
onModalSheetDidDismissViaGesture: onModalSheetDidDismissViaGestureEvent;
onModalSheetDidAttemptToDismissViaGesture: onModalSheetDidAttemptToDismissViaGestureEvent;

onModalSheetStateWillChange: OnModalSheetStateWillChangeEvent;
onModalSheetStateDidChange: OnModalSheetStateDidChangeEvent;
}>;
Expand Down
15 changes: 15 additions & 0 deletions src/native_components/RNIModalSheetVIew/RNIModalSheetViewEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<onModalSheetWillDismissViaGestureEventPayload>;

export type onModalSheetDidDismissViaGestureEvent =
BubblingEventHandler<onModalSheetDidDismissViaGestureEventPayload>;

export type onModalSheetDidAttemptToDismissViaGestureEvent =
BubblingEventHandler<onModalSheetDidAttemptToDismissViaGestureEventPayload>;

export type OnModalSheetStateWillChangeEvent =
BubblingEventHandler<OnModalSheetStateWillChangeEventPayload>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<{}>;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,18 @@ export type RNIModalSheetViewInheritedOptionalProps = Partial<Pick<RNIModalSheet
| 'onModalWillHide'
| 'onModalDidHide'

// presentation controller delegate events
| 'onModalSheetWillDismissViaGesture'
| 'onModalSheetDidDismissViaGesture'
| 'onModalSheetDidAttemptToDismissViaGesture'

// modal sheet events
| 'onModalSheetStateWillChange'
| 'onModalSheetStateDidChange'
>>;

export type RNIModalSheetViewBaseProps = {
shouldEnableDebugBackgroundColors?: boolean;
contentContainerStyle?: ViewProps['style'];
};

export type RNIModalSheetViewProps = PropsWithChildren<
Expand Down

0 comments on commit 91ce3f6

Please sign in to comment.