Skip to content

Commit

Permalink
🛠 Refactor: Types - Rename Modal Event Types
Browse files Browse the repository at this point in the history
Related:
* `TODO:2023-05-03-20-17-56` - Refactor: Types - Typescript type names should match native type names that they are representing.
  • Loading branch information
dominicstop committed May 3, 2023
1 parent ab5dea0 commit 73fcbaa
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 37 deletions.
6 changes: 3 additions & 3 deletions src/components/ModalView/ModalView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
OnPresentationControllerDidDismissEvent,
OnPresentationControllerDidAttemptToDismissEvent,
RNIModalView,
RNIModalBaseEvent,
RNIModalBaseEventData,
RNIModalDeprecatedBaseEvent,
OnModalDetentDidComputeEvent,
OnModalDidChangeSelectedDetentIdentifierEvent,
Expand Down Expand Up @@ -853,7 +853,7 @@ const styles = StyleSheet.create({

class ModalViewHelpers {
static createDeprecatedEventObject(
event: RNIModalBaseEvent
event: RNIModalBaseEventData
): RNIModalDeprecatedBaseEvent {
return {
modalUUID: event.modalNativeID,
Expand All @@ -867,7 +867,7 @@ class ModalViewHelpers {
}

static createDeprecatedBaseEventObject(
event: NativeSyntheticEvent<RNIModalBaseEvent>
event: NativeSyntheticEvent<RNIModalBaseEventData>
): NativeSyntheticEvent<RNIModalDeprecatedBaseEvent> {
return {
...event,
Expand Down
69 changes: 38 additions & 31 deletions src/native_components/RNIModalView/RNIModalViewEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,103 +36,110 @@ export type RNIModalData = {
};

/** Based on `RNIModalBaseEventData` */
export type RNIModalBaseEvent = RNIModalData & {
export type RNIModalBaseEventData = RNIModalData & {
reactTag: number;
modalID?: string;
};

/** Based on `RNIOnModalFocusEventData` */
export type RNIOnModalFocusEvent = RNIModalBaseEvent & {
export type RNIOnModalFocusEventData = RNIModalBaseEventData & {
senderInfo: RNIModalData;
isInitial: boolean;
};

/** Based on `RNIModalSwipeGestureEventData` */
export type RNIModalSwipeGestureEvent = {
export type RNIModalSwipeGestureEventData = {
position: CGPoint;
};

/** Based on `RNIModalDidSnapEventData` */
export type RNIModalDidSnapEvent = {
export type RNIModalDidSnapEventData = {
selectedDetentIdentifier?: string;
modalContentSize: CGSize;
};

/** Based on RNIModalDidChangeSelectedDetentIdentifierEventData */
export type RNIModalDidChangeSelectedDetentIdentifierEventData = {
sheetDetentStringPrevious?: string;
sheetDetentStringCurrent?: string;
};

/** Based on RNIModalDetentDidComputeEventData */
export type RNIModalDetentDidComputeEventData = {
maximumDetentValue: number;
computedDetentValue: number;
key: string;
};

// Native Event Object
// -------------------

export type OnModalWillPresentEventObject = NativeSyntheticEvent<
RNIModalBaseEvent & {}
RNIModalBaseEventData & {}
>;
export type OnModalDidPresentEventObject = NativeSyntheticEvent<
RNIModalBaseEvent & {}
RNIModalBaseEventData & {}
>;

export type OnModalWillDismissEventObject = NativeSyntheticEvent<
RNIModalBaseEvent & {}
RNIModalBaseEventData & {}
>;
export type OnModalDidDismissEventObject = NativeSyntheticEvent<
RNIModalBaseEvent & {}
RNIModalBaseEventData & {}
>;

export type OnModalWillShowEventObject = NativeSyntheticEvent<
RNIModalBaseEvent & {}
RNIModalBaseEventData & {}
>;
export type OnModalDidShowEventObject = NativeSyntheticEvent<
RNIModalBaseEvent & {}
RNIModalBaseEventData & {}
>;

export type OnModalWillHideEventObject = NativeSyntheticEvent<
RNIModalBaseEvent & {}
RNIModalBaseEventData & {}
>;
export type OnModalDidHideEventObject = NativeSyntheticEvent<
RNIModalBaseEvent & {}
RNIModalBaseEventData & {}
>;

export type OnPresentationControllerWillDismissEventObject =
NativeSyntheticEvent<RNIModalBaseEvent & {}>;
NativeSyntheticEvent<RNIModalBaseEventData & {}>;

export type OnPresentationControllerDidDismissEventObject =
NativeSyntheticEvent<RNIModalBaseEvent & {}>;
NativeSyntheticEvent<RNIModalBaseEventData & {}>;

export type OnPresentationControllerDidAttemptToDismissEventObject =
NativeSyntheticEvent<RNIModalBaseEvent & {}>;
NativeSyntheticEvent<RNIModalBaseEventData & {}>;

export type OnModalWillFocusEventObject = NativeSyntheticEvent<
RNIOnModalFocusEvent & {}
RNIOnModalFocusEventData & {}
>;

export type OnModalDidFocusEventObject = NativeSyntheticEvent<
RNIOnModalFocusEvent & {}
RNIOnModalFocusEventData & {}
>;

export type OnModalDetentDidComputeEventObject = NativeSyntheticEvent<{
maximumDetentValue: number;
computedDetentValue: number;
key: string;
}>;
export type OnModalDetentDidComputeEventObject =
NativeSyntheticEvent<RNIModalDetentDidComputeEventData>;

export type OnModalDidChangeSelectedDetentIdentifierEventObject =
NativeSyntheticEvent<{
sheetDetentStringPrevious?: string;
sheetDetentStringCurrent?: string;
}>;
NativeSyntheticEvent<RNIModalDidChangeSelectedDetentIdentifierEventData>;

export type OnModalWillBlurEventObject = NativeSyntheticEvent<
RNIOnModalFocusEvent & {}
RNIOnModalFocusEventData & {}
>;
export type OnModalDidBlurEventObject = NativeSyntheticEvent<
RNIOnModalFocusEvent & {}
RNIOnModalFocusEventData & {}
>;

export type OnModalDidSnapEventObject =
NativeSyntheticEvent<RNIModalDidSnapEvent>;
NativeSyntheticEvent<RNIModalDidSnapEventData>;

export type OnModalSwipeGestureStartEventObject =
NativeSyntheticEvent<RNIModalSwipeGestureEvent>;
NativeSyntheticEvent<RNIModalSwipeGestureEventData>;

export type OnModalSwipeGestureDidEndEventObject =
NativeSyntheticEvent<RNIModalSwipeGestureEvent>;
NativeSyntheticEvent<RNIModalSwipeGestureEventData>;

// Event Handler Types
// -------------------
Expand Down
6 changes: 3 additions & 3 deletions src/native_modules/RNIModalViewModule.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NativeModules, NativeEventEmitter } from 'react-native';
import type { RNIModalBaseEvent } from 'src/native_components/RNIModalView';
import type { RNIModalBaseEventData } from 'src/native_components/RNIModalView';

const MODULE_NAME = 'RNIModalViewModule';

Expand All @@ -26,12 +26,12 @@ interface RNIModalViewModule {
setModalVisibility(
node: number,
visibility: boolean
): Promise<RNIModalBaseEvent>;
): Promise<RNIModalBaseEventData>;

// prettier-ignore
requestModalInfo(
node: number,
): Promise<RNIModalBaseEvent>;
): Promise<RNIModalBaseEventData>;
}

export const RNIModalViewModule: RNIModalViewModule =
Expand Down

0 comments on commit 73fcbaa

Please sign in to comment.