Skip to content

Commit

Permalink
Merge pull request #31184 from s-alves10/fix/issue-31069
Browse files Browse the repository at this point in the history
[CP Staging] Fix/issue 31069

(cherry picked from commit a6629d4)
  • Loading branch information
mountiny authored and OSBotify committed Nov 10, 2023
1 parent e8263aa commit c83ee6d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
13 changes: 13 additions & 0 deletions patches/react-native-web+0.19.9+003+measureInWindow.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/node_modules/react-native-web/dist/exports/UIManager/index.js b/node_modules/react-native-web/dist/exports/UIManager/index.js
index 15b71d5..46b9e01 100644
--- a/node_modules/react-native-web/dist/exports/UIManager/index.js
+++ b/node_modules/react-native-web/dist/exports/UIManager/index.js
@@ -77,7 +77,7 @@ var UIManager = {
measureInWindow(node, callback) {
if (node) {
setTimeout(() => {
- var _getRect2 = getRect(node),
+ var _getRect2 = node.getBoundingClientRect(),
height = _getRect2.height,
left = _getRect2.left,
top = _getRect2.top,
1 change: 0 additions & 1 deletion src/components/EmojiPicker/EmojiPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ const EmojiPicker = forwardRef((props, ref) => {
outerStyle={StyleUtils.getOuterModalStyle(windowHeight, props.viewportOffsetTop)}
innerContainerStyle={styles.popoverInnerContainer}
avoidKeyboard
shouldUseTargetLocation
>
<EmojiPickerMenu
onEmojiSelected={selectEmoji}
Expand Down
1 change: 0 additions & 1 deletion src/components/EmojiPicker/EmojiPickerButtonDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ function EmojiPickerButtonDropdown(props) {
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP,
shiftVertical: 4,
shouldUseTargetLocation: true,
});
};

Expand Down
19 changes: 3 additions & 16 deletions src/components/PopoverWithMeasuredContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, {useMemo, useState} from 'react';
import {View} from 'react-native';
import _ from 'underscore';
import useWindowDimensions from '@hooks/useWindowDimensions';
import getClickedTargetLocation from '@libs/getClickedTargetLocation';
import {computeHorizontalShift, computeVerticalShift} from '@styles/getPopoverWithMeasuredContentStyles';
import styles from '@styles/styles';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -37,9 +36,6 @@ const propTypes = {
height: PropTypes.number,
width: PropTypes.number,
}),

/** Whether we should use the target location from anchor element directly */
shouldUseTargetLocation: PropTypes.bool,
};

const defaultProps = {
Expand All @@ -55,7 +51,6 @@ const defaultProps = {
width: 0,
},
withoutOverlay: false,
shouldUseTargetLocation: false,
};

/**
Expand Down Expand Up @@ -95,9 +90,6 @@ function PopoverWithMeasuredContent(props) {
setIsContentMeasured(true);
};

const {x: horizontal, y: vertical} = props.anchorRef.current ? getClickedTargetLocation(props.anchorRef.current) : {};
const clickedTargetLocation = props.anchorRef.current && props.shouldUseTargetLocation ? {horizontal, vertical} : props.anchorPosition;

const adjustedAnchorPosition = useMemo(() => {
let horizontalConstraint;
switch (props.anchorAlignment.horizontal) {
Expand All @@ -111,18 +103,13 @@ function PopoverWithMeasuredContent(props) {
break;
case CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT:
default:
horizontalConstraint = {left: clickedTargetLocation.horizontal};
horizontalConstraint = {left: props.anchorPosition.horizontal};
}

let verticalConstraint;
const anchorLocationVertical = clickedTargetLocation.vertical;

switch (props.anchorAlignment.vertical) {
case CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM:
if (!anchorLocationVertical) {
break;
}
verticalConstraint = {top: anchorLocationVertical - popoverHeight};
verticalConstraint = {top: props.anchorPosition.vertical - popoverHeight};
break;
case CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.CENTER:
verticalConstraint = {
Expand All @@ -138,7 +125,7 @@ function PopoverWithMeasuredContent(props) {
...horizontalConstraint,
...verticalConstraint,
};
}, [props.anchorPosition, props.anchorAlignment, clickedTargetLocation.vertical, clickedTargetLocation.horizontal, popoverWidth, popoverHeight]);
}, [props.anchorPosition, props.anchorAlignment, popoverWidth, popoverHeight]);

const horizontalShift = computeHorizontalShift(adjustedAnchorPosition.left, popoverWidth, windowWidth);
const verticalShift = computeVerticalShift(adjustedAnchorPosition.top, popoverHeight, windowHeight);
Expand Down

0 comments on commit c83ee6d

Please sign in to comment.