Skip to content

Commit

Permalink
🛠 Refactor: Rename ModalView.state Item
Browse files Browse the repository at this point in the history
Summary: Rename `ModalView.state.shouldMountModalContent` to `isModalVisible`.
  • Loading branch information
dominicstop committed Jan 9, 2023
1 parent 7ad49d9 commit fed37df
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/components/ModalView/ModalView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class ModalView extends
this.emitter = new TSEventEmitter();

this.state = {
shouldMountModalContent: false,
isModalVisible: false,
childProps: null,
enableSwipeGesture: props.enableSwipeGesture,
isModalInPresentation: props.isModalInPresentation,
Expand All @@ -69,7 +69,7 @@ export class ModalView extends

componentWillUnmount() {
const { autoCloseOnUnmount } = this.getProps();
const { shouldMountModalContent: visible } = this.state;
const { isModalVisible: visible } = this.state;

if (autoCloseOnUnmount && visible) {
this.setVisibility(false);
Expand Down Expand Up @@ -173,7 +173,7 @@ export class ModalView extends
nextVisible: boolean,
childProps: object | null = null
) => {
const { shouldMountModalContent: prevVisible } = this.state;
const { isModalVisible: prevVisible } = this.state;

const didChange = (prevVisible !== nextVisible);

Expand All @@ -185,7 +185,7 @@ export class ModalView extends
// Show modal...
// When showing modal, mount children first,
await Helpers.setStateAsync(this, {
visible: nextVisible,
isModalVisible: nextVisible,
// pass down received props to childProps via state
childProps: Helpers.isObject(childProps) ? childProps : null,
});
Expand All @@ -209,7 +209,7 @@ export class ModalView extends
// When finish hiding modal, unmount children
if (!nextVisible) {
await Helpers.setStateAsync(this, {
visible: nextVisible,
isModalVisible: nextVisible,
childProps: null,
});
}
Expand Down Expand Up @@ -319,7 +319,7 @@ export class ModalView extends
);

this.setState({
shouldMountModalContent: false,
isModalVisible: false,
childProps: null,
// reset state values from props
enableSwipeGesture: props.enableSwipeGesture,
Expand Down Expand Up @@ -371,6 +371,8 @@ export class ModalView extends
}),
};

const shouldMountModalContent = state.isModalVisible;

return (
<RNIModalView
ref={(r) => {
Expand All @@ -389,7 +391,7 @@ export class ModalView extends
{...overrideProps}
{...props.viewProps}
>
{state.shouldMountModalContent && (
{shouldMountModalContent && (
<View
style={[styles.modalContentContainer, props.containerStyle]}
collapsable={false}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ModalView/ModalViewTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export type ModalViewProps =
ViewProps & ModalViewBaseProps;

export type ModalViewState = {
shouldMountModalContent: boolean;
isModalVisible: boolean;
childProps: unknown;
enableSwipeGesture: boolean;
isModalInPresentation: boolean;
Expand Down

0 comments on commit fed37df

Please sign in to comment.