Skip to content

Commit c2d64d4

Browse files
committed
feat: add measureOffsetY prop to HighlightToolTip for Y-axis positioning correction
1 parent a7f983c commit c2d64d4

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ The `HighlightToolTip` component accepts the following props:
7878
| `tooltipPosition` | `TooltipPosition` | No | 'bottom' | Position of the tooltip relative to the target |
7979
| `offset` | `{ x?: number; y?: number }` | No | `{ x: 0, y: 0 }` | Offset for tooltip positioning |
8080
| `allowOverlap` | `boolean` | No | `false` | Whether to allow tooltip to overlap with the target |
81+
| `measureOffsetY` | `number` | No | `0` | Y-axis offset for coordinate measurement correction |
8182

8283
### TooltipPosition Types
8384

@@ -98,6 +99,30 @@ type TooltipPosition =
9899

99100
## Advanced Usage
100101

102+
### Coordinate Measurement Correction
103+
104+
If you notice that the highlight position is slightly off (especially on devices with status bars, notches, or navigation bars), you can use the `measureOffsetY` prop to correct the Y-axis positioning:
105+
106+
```jsx
107+
<HighlightToolTip
108+
targetRef={targetRef}
109+
measureOffsetY={-24} // Adjust by -24px if highlight appears too low
110+
tooltipPosition="bottom"
111+
onRequestClose={() => setShowTooltip(false)}
112+
>
113+
<View style={{ padding: 16, backgroundColor: 'white', borderRadius: 8 }}>
114+
<Text>Perfectly positioned tooltip!</Text>
115+
</View>
116+
</HighlightToolTip>
117+
```
118+
119+
**Common scenarios where `measureOffsetY` is useful:**
120+
121+
- Android devices with varying status bar heights
122+
- iOS devices with notches or Dynamic Island
123+
- Apps with custom navigation bars
124+
- Different screen densities and resolutions
125+
101126
### Custom Styling
102127

103128
You can customize the tooltip's appearance by wrapping your content in a styled View:

src/HighLightToolTip.tsx

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

1312
type TooltipPosition =
@@ -30,7 +29,7 @@ type HighlightOverlayProps = {
3029
tooltipPosition?: TooltipPosition;
3130
offset?: { x?: number; y?: number };
3231
allowOverlap?: boolean;
33-
androidOffsetY?: number;
32+
measureOffsetY?: number;
3433
};
3534

3635
export const HighlightToolTip: React.FC<HighlightOverlayProps> = ({
@@ -40,7 +39,7 @@ export const HighlightToolTip: React.FC<HighlightOverlayProps> = ({
4039
tooltipPosition = 'bottom',
4140
offset = { x: 0, y: 0 },
4241
allowOverlap = false,
43-
androidOffsetY = 0,
42+
measureOffsetY = 0,
4443
}) => {
4544
const [hole, setHole] = useState<LayoutRectangle | null>(null);
4645
const { width: screenWidth, height: screenHeight } = Dimensions.get('window');
@@ -51,16 +50,15 @@ export const HighlightToolTip: React.FC<HighlightOverlayProps> = ({
5150
UIManager.measureInWindow(
5251
handle!,
5352
(x: number, y: number, width: number, height: number) => {
54-
const isAndroid = Platform.OS === 'android';
5553
setHole({
5654
x,
57-
y: isAndroid ? y + androidOffsetY : y,
55+
y: y + measureOffsetY,
5856
width,
5957
height,
6058
});
6159
}
6260
);
63-
}, [targetRef, androidOffsetY]);
61+
}, [targetRef, measureOffsetY]);
6462

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

0 commit comments

Comments
 (0)