Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Pin & Delete request appear on Receipt image when quickly tap on receipt and 3-Dot menu #34720

Merged
merged 8 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 5 additions & 4 deletions src/components/Modal/BaseModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function BaseModal(
onLayout,
avoidKeyboard = false,
children,
isPopover = false,
shouldUseCustomBackdrop = false,
}: BaseModalProps,
ref: React.ForwardedRef<View>,
Expand All @@ -59,7 +60,7 @@ function BaseModal(
*/
const hideModal = useCallback(
(callHideCallback = true) => {
Modal.willAlertModalBecomeVisible(false);
Modal.willAlertModalBecomeVisible(false, isPopover);
if (shouldSetModalVisibility) {
Modal.setModalVisibility(false);
}
Expand All @@ -71,14 +72,14 @@ function BaseModal(
ComposerFocusManager.setReadyToFocus();
}
},
[shouldSetModalVisibility, onModalHide, fullscreen],
[shouldSetModalVisibility, onModalHide, fullscreen, isPopover],
);

useEffect(() => {
isVisibleRef.current = isVisible;
let removeOnCloseListener: () => void;
if (isVisible) {
Modal.willAlertModalBecomeVisible(true);
Modal.willAlertModalBecomeVisible(true, isPopover);
// To handle closing any modal already visible when this modal is mounted, i.e. PopoverReportActionContextMenu
removeOnCloseListener = Modal.setCloseModal(onClose);
}
Expand All @@ -89,7 +90,7 @@ function BaseModal(
}
removeOnCloseListener();
};
}, [isVisible, wasVisible, onClose]);
}, [isVisible, wasVisible, onClose, isPopover]);

useEffect(
() => () => {
Expand Down
3 changes: 3 additions & 0 deletions src/components/Modal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ type BaseModalProps = Partial<ModalProps> & {
* */
hideModalContentWhileAnimating?: boolean;

/** Whether the modal is popover or not */
isPopover?: boolean;

/** Should we use a custom backdrop for the modal? (This prevents focus issues on desktop) */
shouldUseCustomBackdrop?: boolean;
};
Expand Down
2 changes: 2 additions & 0 deletions src/components/Popover/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function Popover(props: PopoverWithWindowDimensionsProps) {
onLayout={onLayout}
animationIn={animationIn}
animationOut={animationOut}
isPopover
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this new prop? Isn't it redundant with the type prop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yah, I think we can remove it and use type. Thank you

/>,
document.body,
);
Expand Down Expand Up @@ -100,6 +101,7 @@ function Popover(props: PopoverWithWindowDimensionsProps) {
onLayout={onLayout}
animationIn={animationIn}
animationOut={animationOut}
isPopover
/>
);
}
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 {AnchorAlignment} from '@components/Popover/types';
Expand All @@ -14,10 +16,17 @@ 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 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(null);
const {translate} = useLocalize();
const isBehindModal = modal?.willAlertModalBecomeVisible && !modal?.isPopover && !shouldOverlay;
Copy link
Contributor

@c3024 c3024 Jan 25, 2024

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
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

Copy link
Contributor

@c3024 c3024 Jan 31, 2024

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 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 @@ -119,7 +137,7 @@ function ThreeDotsMenu({
</View>
<PopoverMenu
onClose={hidePopoverMenu}
isVisible={isPopupMenuVisible}
isVisible={isPopupMenuVisible && !isBehindModal}
anchorPosition={anchorPosition}
anchorAlignment={anchorAlignment}
onItemSelected={hidePopoverMenu}
Expand All @@ -134,4 +152,8 @@ function ThreeDotsMenu({

ThreeDotsMenu.displayName = 'ThreeDotsMenu';

export default ThreeDotsMenu;
export default withOnyx<ThreeDotsMenuProps, ThreeDotsMenuOnyxProps>({
modal: {
key: ONYXKEYS.MODAL,
},
})(ThreeDotsMenu);
4 changes: 2 additions & 2 deletions src/libs/actions/Modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ 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.
*/
function willAlertModalBecomeVisible(isVisible: boolean) {
Onyx.merge(ONYXKEYS.MODAL, {willAlertModalBecomeVisible: isVisible});
function willAlertModalBecomeVisible(isVisible: boolean, isPopover = false) {
Copy link
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};
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;
Loading