Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/components/Modal/BaseModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function BaseModal(
isVisibleRef.current = isVisible;
let removeOnCloseListener: () => void;
if (isVisible) {
Modal.willAlertModalBecomeVisible(true);
Modal.willAlertModalBecomeVisible(true, type === CONST.MODAL.MODAL_TYPE.POPOVER || type === CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED);
// To handle closing any modal already visible when this modal is mounted, i.e. PopoverReportActionContextMenu
removeOnCloseListener = Modal.setCloseModal(onClose);
}
Expand All @@ -91,7 +91,7 @@ function BaseModal(
}
removeOnCloseListener();
};
}, [isVisible, wasVisible, onClose]);
}, [isVisible, wasVisible, onClose, type]);

useEffect(
() => () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/PopoverWithoutOverlay/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function PopoverWithoutOverlay(
close(anchorRef);
Modal.onModalDidClose();
}
Modal.willAlertModalBecomeVisible(isVisible);
Modal.willAlertModalBecomeVisible(isVisible, true);

return () => {
if (!removeOnClose) {
Expand Down
30 changes: 26 additions & 4 deletions src/components/ThreeDotsMenu/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, {useRef, useState} from 'react';
import React, {useEffect, useRef, useState} from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import type {PopoverMenuItem} from '@components/PopoverMenu';
Expand All @@ -13,11 +15,18 @@ import useThemeStyles from '@hooks/useThemeStyles';
import * as Browser from '@libs/Browser';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import type {AnchorPosition} from '@src/styles';
import type {Modal} from '@src/types/onyx';
import type AnchorAlignment from '@src/types/utils/AnchorAlignment';
import type IconAsset from '@src/types/utils/IconAsset';

type ThreeDotsMenuProps = {
type ThreeDotsMenuOnyxProps = {
/** Details about any modals being used */
modal: OnyxEntry<Modal>;
};

type ThreeDotsMenuProps = ThreeDotsMenuOnyxProps & {
/** Tooltip for the popup icon */
iconTooltip?: TranslationPaths;

Expand Down Expand Up @@ -67,12 +76,14 @@ function ThreeDotsMenu({
shouldOverlay = false,
shouldSetModalVisibility = true,
disabled = false,
modal = {},
}: ThreeDotsMenuProps) {
const theme = useTheme();
const styles = useThemeStyles();
const [isPopupMenuVisible, setPopupMenuVisible] = useState(false);
const buttonRef = useRef<HTMLDivElement | null>(null);
const {translate} = useLocalize();

@c3024 c3024 Jan 25, 2024

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.

NIT: In here

const isBehindModal = modal?.willAlertModalBecomeVisible && !modal?.isPopover && !shouldOverlay;

I think if modal?.willAlertModalBecomeVisible is true, the next ? after modal is not necessary.

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.

although we have default value {} for modal but its type is modal: OnyxEntry, not modal?: Modal, and OnyxEntry can be null -> ? is necessary here

@c3024 c3024 Jan 31, 2024

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.

I meant at line 86

const isBehindModal = modal?.willAlertModalBecomeVisible && !modal?.isPopover && !shouldOverlay;

it will reach to checking !modal?.isPopover only when modal?.willAlertModalBecomeVisible is true which guarantees that modal is not null so in the modal?.isPopover being evaluated only after modal?.willAlertModalBecomeVisible is true, modal check for null in modal?.isPopover does not appear to be required.

It is a non issue and a very minor nitpick anyway 😁 . Need not be changed.

const isBehindModal = modal?.willAlertModalBecomeVisible && !modal?.isPopover && !shouldOverlay;

const showPopoverMenu = () => {
setPopupMenuVisible(true);
Expand All @@ -82,6 +93,13 @@ function ThreeDotsMenu({
setPopupMenuVisible(false);
};

useEffect(() => {
if (!isBehindModal || !isPopupMenuVisible) {
return;
}
hidePopoverMenu();
}, [isBehindModal, isPopupMenuVisible]);

return (
<>
<View>
Expand Down Expand Up @@ -120,7 +138,7 @@ function ThreeDotsMenu({
</View>
<PopoverMenu
onClose={hidePopoverMenu}
isVisible={isPopupMenuVisible}
isVisible={isPopupMenuVisible && !isBehindModal}
anchorPosition={anchorPosition}
anchorAlignment={anchorAlignment}
onItemSelected={hidePopoverMenu}
Expand All @@ -135,4 +153,8 @@ function ThreeDotsMenu({

ThreeDotsMenu.displayName = 'ThreeDotsMenu';

export default ThreeDotsMenu;
export default withOnyx<ThreeDotsMenuProps, ThreeDotsMenuOnyxProps>({
modal: {
key: ONYXKEYS.MODAL,
},
})(ThreeDotsMenu);
5 changes: 3 additions & 2 deletions src/libs/actions/Modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ function setModalVisibility(isVisible: boolean) {
/**
* Allows other parts of app to know that an alert modal is about to open.
* This will trigger as soon as a modal is opened but not yet visible while animation is running.
* isPopover indicates that the next open modal is popover or bottom docked
*/
function willAlertModalBecomeVisible(isVisible: boolean) {
Onyx.merge(ONYXKEYS.MODAL, {willAlertModalBecomeVisible: isVisible});
function willAlertModalBecomeVisible(isVisible: boolean, isPopover = false) {

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.

Please add comment for why this param isPopover is required.

Onyx.merge(ONYXKEYS.MODAL, {willAlertModalBecomeVisible: isVisible, isPopover});
}

export {setCloseModal, close, onModalDidClose, setModalVisibility, willAlertModalBecomeVisible, closeTop};
2 changes: 2 additions & 0 deletions src/types/onyx/Modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ type Modal = {

/** Indicates if there is a modal currently visible or not */
isVisible?: boolean;

isPopover?: boolean;
};

export default Modal;