Skip to content

Commit

Permalink
⭐️ Impl: ModalView.isModalContentLazy
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Mar 3, 2023
1 parent 0ee8a5b commit c6f41b2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/components/ModalView/ModalView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export class ModalView extends
setEnableSwipeGestureFromProps,
setModalInPresentationFromProps,
containerStyle,
isModalContentLazy,

children,
...viewProps
Expand Down Expand Up @@ -149,6 +150,9 @@ export class ModalView extends
isModalInPresentation: (
isModalInPresentation ?? false
),
isModalContentLazy: (
isModalContentLazy ?? true
),

// B - Pass down...
modalID,
Expand Down Expand Up @@ -192,6 +196,7 @@ export class ModalView extends
nextVisible: boolean,
childProps: object | null = null
) => {
const props = this.getProps();
const { isModalVisible: prevVisible } = this.state;

const didChange = (prevVisible !== nextVisible);
Expand All @@ -210,11 +215,13 @@ export class ModalView extends
});

// wait for view to mount
await Helpers.promiseWithTimeout(500, new Promise<void>((resolve) => {
this.emitter.once(ModalViewEmitterEvents.onLayoutModalContentContainer, () => {
resolve();
});
}));
if (props.isModalContentLazy){
await Helpers.promiseWithTimeout(500, new Promise<void>((resolve) => {
this.emitter.once(ModalViewEmitterEvents.onLayoutModalContentContainer, () => {
resolve();
});
}));
}
}

try {
Expand Down Expand Up @@ -394,7 +401,10 @@ export class ModalView extends
}),
};

const shouldMountModalContent = state.isModalVisible;
// TODO: Fix `isModalContentLazy` props
// * Error when opening modal once it's been closed
const shouldMountModalContent =
!props.isModalContentLazy || state.isModalVisible;

return (
<RNIModalView
Expand Down
1 change: 1 addition & 0 deletions src/components/ModalView/ModalViewTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type ModalViewBaseProps = Partial<
autoCloseOnUnmount?: boolean;
setEnableSwipeGestureFromProps?: boolean;
setModalInPresentationFromProps?: boolean;
isModalContentLazy?: boolean;

containerStyle: ViewStyle;
children?: React.ReactNode;
Expand Down

0 comments on commit c6f41b2

Please sign in to comment.