Skip to content

Commit

Permalink
⭐️ Impl:ModalView Eventts
Browse files Browse the repository at this point in the history
Related:
* `TODO:2023-05-01-19-12-26` - Implement: `ModalView` events.
* `TODO:2023-04-05-15-35-49` - Impl. `onModalDismissWillCancel` and `onModalDismissDidCancel`.
  • Loading branch information
dominicstop committed May 4, 2023
1 parent c5870c4 commit 49fdbdc
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 6 deletions.
18 changes: 14 additions & 4 deletions ios/src_library/React Native/RNIModalView/RNIModalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,18 @@ public class RNIModalView:
public var modalIndexPrev: Int!;

public lazy var modalPresentationState = RNIModalPresentationStateMachine(
onDismissWillCancel: { [weak self] in
// no-op - TBA
onDismissWillCancel: { [unowned self] in
let eventData = self.synthesizedBaseEventData;
self.onModalDismissWillCancel?(
eventData.synthesizedJSDictionary
);
},
onDismissDidCancel: { [weak self] in
// no-op - TBA

onDismissDidCancel: { [unowned self] in
let eventData = self.synthesizedBaseEventData;
self.onModalDismissDidCancel?(
eventData.synthesizedJSDictionary
);
}
);

Expand Down Expand Up @@ -99,6 +106,9 @@ public class RNIModalView:
@objc var onModalSwipeGestureStart: RCTBubblingEventBlock?;
@objc var onModalSwipeGestureDidEnd: RCTBubblingEventBlock?;

@objc var onModalDismissWillCancel: RCTBubblingEventBlock?;
@objc var onModalDismissDidCancel: RCTBubblingEventBlock?;

// MARK: - Properties: React Props - General
// -----------------------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ @interface RCT_EXTERN_MODULE(RNIModalViewManager, RCTViewManager)
RCT_EXPORT_VIEW_PROPERTY(onModalSwipeGestureStart, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onModalSwipeGestureDidEnd, RCTBubblingEventBlock);

RCT_EXPORT_VIEW_PROPERTY(onModalDismissWillCancel, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onModalDismissDidCancel, RCTBubblingEventBlock);

// MARK: - Value Props - General
// -----------------------------

Expand Down
30 changes: 29 additions & 1 deletion src/components/ModalView/ModalView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import {
OnModalDidSnapEvent,
OnModalSwipeGestureStartEvent,
OnModalSwipeGestureDidEndEvent,
OnModalDismissWillCancelEvent,
OnModalDismissDidCancelEvent,
} from '../../native_components/RNIModalView';

import { RNIModalViewModule } from '../../native_modules/RNIModalViewModule';
Expand Down Expand Up @@ -711,7 +713,31 @@ export class ModalView extends
);
};

private _renderModal() {
private _handleOnModalDismissWillCancel: OnModalDismissWillCancelEvent = (event) => {
const props = this.props;

props.onModalDismissWillCancel?.(event);
event.stopPropagation();

this.emitter.emit(
ModalViewEmitterEvents.onModalDismissWillCancel,
event.nativeEvent
);
};

private _handleOnModalDismissDidCancel: OnModalDismissDidCancelEvent = (event) => {
const props = this.props;

props.onModalDismissDidCancel?.(event);
event.stopPropagation();

this.emitter.emit(
ModalViewEmitterEvents.onModalDismissDidCancel,
event.nativeEvent
);
};

private _renderModal() {
const { viewProps, ...props } = this.getProps();
const state = this.state;

Expand Down Expand Up @@ -760,6 +786,8 @@ export class ModalView extends
onModalDidSnap={this._handleOnModalDidSnap}
onModalSwipeGestureStart={this._handleOnModalSwipeGestureStart}
onModalSwipeGestureDidEnd={this._handleOnModalSwipeGestureDidEnd}
onModalDismissWillCancel={this._handleOnModalDismissWillCancel}
onModalDismissDidCancel={this._handleOnModalDismissDidCancel}
{...overrideProps}
{...viewProps}
>
Expand Down
6 changes: 6 additions & 0 deletions src/components/ModalView/ModalViewEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import type {
OnModalDidSnapEventObject,
OnModalSwipeGestureStartEventObject,
OnModalSwipeGestureDidEndEventObject,
OnModalDismissWillCancelEventObject,
OnModalDismissDidCancelEventObject,
} from 'src/native_components/RNIModalView';

import type { KeyMapType } from '../../types/UtilityTypes';
Expand Down Expand Up @@ -53,6 +55,8 @@ export enum ModalViewEmitterEvents {
onModalDidSnap = 'onModalDidSnap',
onModalSwipeGestureStart = 'onModalSwipeGestureStart',
onModalSwipeGestureDidEnd = 'onModalSwipeGestureDidEnd',
onModalDismissWillCancel = 'onModalDismissWillCancel',
onModalDismissDidCancel = 'onModalDismissDidCancel',

onLayoutModalContentContainer = 'onLayoutModalContentContainer',
}
Expand Down Expand Up @@ -84,6 +88,8 @@ export type ModalViewEmitterEventMap =
onModalDidSnap: OnModalDidSnapEventObject['nativeEvent'];
onModalSwipeGestureStart: OnModalSwipeGestureStartEventObject['nativeEvent'];
onModalSwipeGestureDidEnd: OnModalSwipeGestureDidEndEventObject['nativeEvent'];
onModalDismissWillCancel: OnModalDismissWillCancelEventObject['nativeEvent'];
onModalDismissDidCancel: OnModalDismissDidCancelEventObject['nativeEvent'];

onLayoutModalContentContainer: LayoutChangeEvent['nativeEvent'];
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/ModalView/ModalViewProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export type ModalViewBaseProps = Partial<
| 'onModalDidSnap'
| 'onModalSwipeGestureStart'
| 'onModalSwipeGestureDidEnd'
| 'onModalDismissWillCancel'
| 'onModalDismissDidCancel'
>
> & {
modalContentPreferredContentSize?: RNIComputableSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { CGPoint, CGSize } from 'src/types/NativeTypes';
import type {
ModalFocusState,
ModalPresentationState,
} from 'src/types/RNIModalViewRelatedTypes';
} from 'src/types/RNIModalTypes';

// Event Object Types
// ------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,9 @@ export type OnModalSwipeGestureStartEventObject =

export type OnModalSwipeGestureDidEndEventObject =
NativeSyntheticEvent<RNIModalSwipeGestureEventData>;

export type OnModalDismissWillCancelEventObject =
NativeSyntheticEvent<RNIModalBaseEventData>;

export type OnModalDismissDidCancelEventObject =
NativeSyntheticEvent<RNIModalBaseEventData>;
11 changes: 11 additions & 0 deletions src/native_components/RNIModalView/RNIModalViewEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import type {
OnModalDidSnapEventObject,
OnModalSwipeGestureStartEventObject,
OnModalSwipeGestureDidEndEventObject,
OnModalDismissWillCancelEventObject,
OnModalDismissDidCancelEventObject,
} from './RNIModalViewEventObjects';

// Event Handler Types
Expand Down Expand Up @@ -105,3 +107,12 @@ export type OnModalSwipeGestureStartEvent = (
export type OnModalSwipeGestureDidEndEvent = (
event: OnModalSwipeGestureDidEndEventObject
) => void;

export type OnModalDismissWillCancelEvent = (
event: OnModalDismissWillCancelEventObject
) => void;

export type OnModalDismissDidCancelEvent = (
event: OnModalDismissDidCancelEventObject
) => void;

5 changes: 5 additions & 0 deletions src/native_components/RNIModalView/RNIModalViewTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import type {
OnModalDidSnapEvent,
OnModalSwipeGestureStartEvent,
OnModalSwipeGestureDidEndEvent,
OnModalDismissWillCancelEvent,
OnModalDismissDidCancelEvent,
} from './RNIModalViewEvents';

import type { UnionWithAutoComplete } from 'src/types/UtilityTypes';
Expand Down Expand Up @@ -119,6 +121,9 @@ export type RNIModalViewBaseProps = {

onModalSwipeGestureStart: OnModalSwipeGestureStartEvent;
onModalSwipeGestureDidEnd: OnModalSwipeGestureDidEndEvent;

onModalDismissWillCancel: OnModalDismissWillCancelEvent;
onModalDismissDidCancel: OnModalDismissDidCancelEvent;
};

export type RNIModalViewProps = Partial<ViewProps> & RNIModalViewBaseProps;
Expand Down

0 comments on commit 49fdbdc

Please sign in to comment.