Skip to content

Commit a662aa0

Browse files
committed
feat: add androidOffsetY prop to HighlightToolTip for improved positioning on Android
1 parent 53d4154 commit a662aa0

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/HighLightToolTip.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
UIManager,
88
type LayoutRectangle,
99
Dimensions,
10+
Platform,
1011
} from 'react-native';
1112

1213
type TooltipPosition =
@@ -29,6 +30,7 @@ type HighlightOverlayProps = {
2930
tooltipPosition?: TooltipPosition;
3031
offset?: { x?: number; y?: number };
3132
allowOverlap?: boolean;
33+
androidOffsetY?: number;
3234
};
3335

3436
export const HighlightToolTip: React.FC<HighlightOverlayProps> = ({
@@ -38,6 +40,7 @@ export const HighlightToolTip: React.FC<HighlightOverlayProps> = ({
3840
tooltipPosition = 'bottom',
3941
offset = { x: 0, y: 0 },
4042
allowOverlap = false,
43+
androidOffsetY = 0,
4144
}) => {
4245
const [hole, setHole] = useState<LayoutRectangle | null>(null);
4346
const { width: screenWidth, height: screenHeight } = Dimensions.get('window');
@@ -48,10 +51,16 @@ export const HighlightToolTip: React.FC<HighlightOverlayProps> = ({
4851
UIManager.measureInWindow(
4952
handle!,
5053
(x: number, y: number, width: number, height: number) => {
51-
setHole({ x, y, width, height });
54+
const isAndroid = Platform.OS === 'android';
55+
setHole({
56+
x,
57+
y: isAndroid ? y + androidOffsetY : y,
58+
width,
59+
height,
60+
});
5261
}
5362
);
54-
}, [targetRef]);
63+
}, [targetRef, androidOffsetY]);
5564

5665
const getTooltipPosition = () => {
5766
if (!hole) return { top: 0, left: 0 };

0 commit comments

Comments
 (0)