Skip to content

Commit

Permalink
🛠 Refactor: Types - Fix Type Errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Jan 18, 2023
1 parent 49c2858 commit d399d3b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
24 changes: 14 additions & 10 deletions src/components/ModalView/ModalView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ export class ModalView extends
constructor(props: ModalViewProps) {
super(props);

const defaultProps = this.getProps(props);

this.emitter = new TSEventEmitter();

this.state = {
isModalVisible: false,
childProps: null,
enableSwipeGesture: props.enableSwipeGesture,
isModalInPresentation: props.isModalInPresentation,
enableSwipeGesture: defaultProps.enableSwipeGesture,
isModalInPresentation: defaultProps.isModalInPresentation,
};
}

Expand All @@ -76,7 +78,7 @@ export class ModalView extends
}
}

private getProps = () => {
private getProps = (propOverride: ModalViewProps | null = null) => {
const {
// native props - flags
presentViaMount,
Expand Down Expand Up @@ -110,7 +112,7 @@ export class ModalView extends

children,
...viewProps
} = this.props;
} = propOverride ?? this.props;

return ({
// A - Add Default Values
Expand Down Expand Up @@ -144,10 +146,12 @@ export class ModalView extends
setModalInPresentationFromProps: (
setModalInPresentationFromProps ?? false
),
isModalInPresentation: (
isModalInPresentation ?? false
),

// B - Pass down...
modalID,
isModalInPresentation,
allowModalForceDismiss,
modalBGBlurEffectStyle,
onModalShow,
Expand Down Expand Up @@ -216,7 +220,7 @@ export class ModalView extends
try {
// request modal to open/close
await RNIModalViewModule.setModalVisibility(
findNodeHandle(this.nativeRefModalView),
findNodeHandle(this.nativeRefModalView)!,
nextVisible
);

Expand All @@ -239,7 +243,7 @@ export class ModalView extends
try {
// request modal to send modal info
return await RNIModalViewModule.requestModalInfo(
findNodeHandle(this.nativeRefModalView)
findNodeHandle(this.nativeRefModalView)!
);
} catch (error) {
console.log('ModalView, requestModalInfo failed:');
Expand Down Expand Up @@ -377,7 +381,7 @@ export class ModalView extends
};

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

const overrideProps = {
Expand All @@ -396,7 +400,7 @@ export class ModalView extends
<RNIModalView
{...props}
ref={(r) => {
this.nativeRefModalView = r;
this.nativeRefModalView = r!;
}}
style={styles.rootContainer}
onStartShouldSetResponder={this._shouldSetResponder}
Expand All @@ -408,7 +412,7 @@ export class ModalView extends
onModalWillDismiss={this._handleOnModalWillDismiss}
onModalAttemptDismiss={this._handleOnModalAttemptDismiss}
{...overrideProps}
{...props.viewProps}
{...viewProps}
>
{shouldMountModalContent && (
<View
Expand Down
4 changes: 2 additions & 2 deletions src/native_components/RNIModalView/RNIModalView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export const RNIModalView: HostComponent<RNIModalViewProps> = Platform.select({
default: () => View,
})();

export const RNIModalViewConstants = UIManager[nativeViewName]
?.Constants as RNIModalViewConstantMap;
export const RNIModalViewConstants: Partial<RNIModalViewConstantMap> =
(UIManager as Record<string, any>)[nativeViewName]?.Constants ?? {};

export const AvailableBlurEffectStyles =
RNIModalViewConstants?.availableBlurEffectStyles ?? [];
Expand Down
26 changes: 14 additions & 12 deletions src/native_components/RNIModalView/RNIModalViewTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@ import type {
OnModalAttemptDismissEvent,
} from './RNIModalViewEvents';

export type RNIModalViewProps = ViewProps & {
export type RNIModalViewBaseProps = {
// Props - Flags
// --------------

presentViaMount: boolean;
isModalBGBlurred: boolean;
enableSwipeGesture: boolean;
hideNonVisibleModals: boolean;
isModalBGTransparent: boolean;
isModalInPresentation: boolean;
allowModalForceDismiss: boolean;
presentViaMount?: boolean;
isModalBGBlurred?: boolean;
enableSwipeGesture?: boolean;
hideNonVisibleModals?: boolean;
isModalBGTransparent?: boolean;
isModalInPresentation?: boolean;
allowModalForceDismiss?: boolean;

// Props - Strings
// --------------

modalID: string;
modalTransitionStyle: UIModalTransitionStyle;
modalBGBlurEffectStyle: UIBlurEffectStyles;
modalPresentationStyle: UIModalPresentationStyle;
modalID?: string;
modalTransitionStyle?: UIModalTransitionStyle;
modalBGBlurEffectStyle?: UIBlurEffectStyles;
modalPresentationStyle?: UIModalPresentationStyle;

// Props - Events
// --------------
Expand All @@ -54,6 +54,8 @@ export type RNIModalViewProps = ViewProps & {
onModalAttemptDismiss: OnModalAttemptDismissEvent;
};

export type RNIModalViewProps = Partial<ViewProps> & RNIModalViewBaseProps;

export type RNIModalViewConstantMap = ViewManagerConstantMap<{
availableBlurEffectStyles: UIBlurEffectStyles[];
availablePresentationStyles: UIModalPresentationStyle[];
Expand Down

0 comments on commit d399d3b

Please sign in to comment.