Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions src/components/Popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,41 @@ import PopoverWithoutOverlay from '../PopoverWithoutOverlay';
* On small screen widths, it uses BottomDocked modal type, and a Popover type on wide screen widths.
*/
function Popover(props) {
if (!props.fullscreen && !props.isSmallScreenWidth) {
const {isVisible, onClose, isSmallScreenWidth, fullscreen, animationInTiming, onLayout, animationOutTiming, disableAnimation, withoutOverlay, anchorPosition} = props;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm I understand why you did this, since we need onClose and isVisible as dependencies, we might as well split out all of them?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, splitting everything won't work because we're passing on the props object as it is, to the Modal component.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep! that makes sense.


// Not adding this inside the PopoverProvider

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB - I'm pretty sure we like to have a blank line above any comments. Not sure why the automations didn't catch that though, so maybe I'm wrong?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prettier did not fix this. Not sure if we have the rule set.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah looks like it might not offer that as an option, so maybe we don't have anything automated for that one. Do you mind terribly adding the empty line? I'm checking to make sure I'm not inventing that rule, but I'm pretty sure it's real, haha

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

// because this is an issue on smaller screens as well.
React.useEffect(() => {
const listener = () => {
if (!isVisible) {
return;
}

onClose();
};
window.addEventListener('popstate', listener);
return () => {
window.removeEventListener('popstate', listener);
};
}, [onClose, isVisible]);

if (!fullscreen && !isSmallScreenWidth) {
return createPortal(
<Modal
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
type={CONST.MODAL.MODAL_TYPE.POPOVER}
popoverAnchorPosition={props.anchorPosition}
animationInTiming={props.disableAnimation ? 1 : props.animationInTiming}
animationOutTiming={props.disableAnimation ? 1 : props.animationOutTiming}
popoverAnchorPosition={anchorPosition}
animationInTiming={disableAnimation ? 1 : animationInTiming}
animationOutTiming={disableAnimation ? 1 : animationOutTiming}
shouldCloseOnOutsideClick
onLayout={props.onLayout}
onLayout={onLayout}
/>,
document.body,
);
}

if (props.withoutOverlay && !props.isSmallScreenWidth) {
if (withoutOverlay && !isSmallScreenWidth) {
// eslint-disable-next-line react/jsx-props-no-spreading
return createPortal(<PopoverWithoutOverlay {...props} />, document.body);
}
Expand All @@ -36,12 +54,12 @@ function Popover(props) {
<Modal
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
type={props.isSmallScreenWidth ? CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED : CONST.MODAL.MODAL_TYPE.POPOVER}
popoverAnchorPosition={props.isSmallScreenWidth ? undefined : props.anchorPosition}
fullscreen={props.isSmallScreenWidth ? true : props.fullscreen}
animationInTiming={props.disableAnimation && !props.isSmallScreenWidth ? 1 : props.animationInTiming}
animationOutTiming={props.disableAnimation && !props.isSmallScreenWidth ? 1 : props.animationOutTiming}
onLayout={props.onLayout}
type={isSmallScreenWidth ? CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED : CONST.MODAL.MODAL_TYPE.POPOVER}
popoverAnchorPosition={isSmallScreenWidth ? undefined : anchorPosition}
fullscreen={isSmallScreenWidth ? true : fullscreen}
animationInTiming={disableAnimation && !isSmallScreenWidth ? 1 : animationInTiming}
animationOutTiming={disableAnimation && !isSmallScreenWidth ? 1 : animationOutTiming}
onLayout={onLayout}
/>
);
}
Expand Down