Skip to content

Commit

Permalink
🛠 Refactor: Use ModalView.getProps
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Jan 9, 2023
1 parent 4de2ea0 commit d37608d
Showing 1 changed file with 97 additions and 4 deletions.
101 changes: 97 additions & 4 deletions src/components/ModalView/ModalView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,105 @@ export class ModalView extends
}

componentWillUnmount() {
const { autoCloseOnUnmount } = this.props;
const { autoCloseOnUnmount } = this.getProps();
const { visible } = this.state;

if (autoCloseOnUnmount && visible) {
this.setVisibility(false);
}
}

getProps = () => {
const {
// native props - flags
presentViaMount,
isModalBGBlurred,
enableSwipeGesture,
hideNonVisibleModals,
isModalBGTransparent,
isModalInPresentation,
allowModalForceDismiss,

// native props - string
modalID,
modalTransitionStyle,
modalBGBlurEffectStyle,
modalPresentationStyle,

// native props - events
onModalShow,
onModalDismiss,
onRequestResult,
onModalBlur,
onModalFocus,
onModalDidDismiss,
onModalWillDismiss,
onModalAttemptDismiss,

// component props
autoCloseOnUnmount,
setEnableSwipeGestureFromProps,
setModalInPresentationFromProps,
containerStyle,

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

return ({
// A - Add Default Values
presentViaMount: (
presentViaMount ?? false
),
isModalBGBlurred: (
isModalBGBlurred ?? false
),
enableSwipeGesture: (
enableSwipeGesture ?? true
),
hideNonVisibleModals: (
hideNonVisibleModals ?? false
),
isModalBGTransparent: (
isModalBGTransparent ?? false
),
modalTransitionStyle: (
modalTransitionStyle ?? 'coverVertical'
),
modalPresentationStyle: (
modalPresentationStyle ?? 'automatic'
),
autoCloseOnUnmount: (
autoCloseOnUnmount ?? true
),
setEnableSwipeGestureFromProps: (
setEnableSwipeGestureFromProps ?? false
),
setModalInPresentationFromProps: (
setModalInPresentationFromProps ?? false
),

// B - Pass down...
modalID,
isModalInPresentation,
allowModalForceDismiss,
modalBGBlurEffectStyle,
onModalShow,
onModalDismiss,
onRequestResult,
onModalBlur,
onModalFocus,
onModalDidDismiss,
onModalWillDismiss,
onModalAttemptDismiss,
containerStyle,

// C - View-Related Props
children,
viewProps,
});
};

getEmitterRef = () => {
return this.emitter;
};
Expand Down Expand Up @@ -199,15 +290,17 @@ export class ModalView extends
};

_handleOnModalDismiss = (event) => {
const props = this.getProps();

this.props.onModalDismiss?.(event);
this.emitter.emit(ModalEventKeys.onModalDismiss, event);

this.setState({
visible: false,
childProps: null,
// reset state values from props
enableSwipeGesture: this.props.enableSwipeGesture,
isModalInPresentation: this.props.isModalInPresentation,
enableSwipeGesture: props.enableSwipeGesture,
isModalInPresentation: props.isModalInPresentation,
});
};

Expand All @@ -228,7 +321,7 @@ export class ModalView extends
//#endregion

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

const nativeProps = {
Expand Down

0 comments on commit d37608d

Please sign in to comment.