Skip to content

Commit 2e204b9

Browse files
committed
fix: misaligned highlighting
1 parent 4c3f5f7 commit 2e204b9

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

src/react-native/grab-overlay.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
Dimensions,
55
NativeTouchEvent,
66
PanResponder,
7+
Platform,
78
Pressable,
89
StyleSheet,
910
Text,
@@ -157,13 +158,25 @@ export const ReactNativeGrabOverlay = () => {
157158
const appRootBoundingClientRect = measureInWindow(appRootShadowNode);
158159
const focusedScreenBoundingClientRect = measureInWindow(focusedScreenShadowNode);
159160

160-
let focusedScreenOffsetY = focusedScreenBoundingClientRect[1];
161-
let focusedScreenHeight = focusedScreenBoundingClientRect[3];
162-
let appRootHeight = appRootBoundingClientRect[3];
161+
const focusedScreenOffsetY = focusedScreenBoundingClientRect[1];
162+
const focusedScreenHeight = focusedScreenBoundingClientRect[3];
163+
const appRootHeight = appRootBoundingClientRect[3];
164+
const appRootOffsetY = appRootBoundingClientRect[1];
165+
166+
const overlayOffset = Platform.select({
167+
ios: appRootHeight - focusedScreenHeight - focusedScreenOffsetY,
168+
android: focusedScreenOffsetY - (appRootOffsetY + focusedScreenOffsetY),
169+
default: 0,
170+
});
171+
172+
const pageOffset = Platform.select({
173+
ios: focusedScreenHeight - appRootHeight,
174+
android: appRootOffsetY - focusedScreenOffsetY,
175+
default: 0,
176+
});
163177

164-
const offset = appRootHeight - focusedScreenHeight - focusedScreenOffsetY;
165178
const pageX = nativePageX;
166-
const pageY = nativePageY - (appRootHeight - focusedScreenHeight);
179+
const pageY = nativePageY + pageOffset;
167180

168181
const internalNode = findNodeAtPoint(focusedScreenShadowNode, pageX, pageY);
169182
const shadowNode = internalNode?.stateNode?.node;
@@ -173,7 +186,7 @@ export const ReactNativeGrabOverlay = () => {
173186
}
174187

175188
const rect = nativeFabricUIManager.getBoundingClientRect(shadowNode, true);
176-
return { fiberNode: internalNode, rect: [rect[0], rect[1] + offset, rect[2], rect[3]] };
189+
return { fiberNode: internalNode, rect: [rect[0], rect[1] + overlayOffset, rect[2], rect[3]] };
177190
};
178191

179192
const handleTouch = (nativeEvent: NativeTouchEvent) => {

0 commit comments

Comments
 (0)