Skip to content

Commit 31120ce

Browse files
committed
refactor: replace measureOffsetY with androidOffsetY in HighlightToolTip for better clarity and usage
1 parent b4d40cf commit 31120ce

File tree

2 files changed

+6
-29
lines changed

2 files changed

+6
-29
lines changed

README.md

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ 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 |
8281

8382
### TooltipPosition Types
8483

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

10099
## Advanced Usage
101100

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-
126101
### Custom Styling
127102

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

src/HighLightToolTip.tsx

Lines changed: 6 additions & 4 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,7 +30,7 @@ type HighlightOverlayProps = {
2930
tooltipPosition?: TooltipPosition;
3031
offset?: { x?: number; y?: number };
3132
allowOverlap?: boolean;
32-
measureOffsetY?: number;
33+
androidOffsetY?: number;
3334
};
3435

3536
export const HighlightToolTip: React.FC<HighlightOverlayProps> = ({
@@ -39,7 +40,7 @@ export const HighlightToolTip: React.FC<HighlightOverlayProps> = ({
3940
tooltipPosition = 'bottom',
4041
offset = { x: 0, y: 0 },
4142
allowOverlap = false,
42-
measureOffsetY = 0,
43+
androidOffsetY = 0,
4344
}) => {
4445
const [hole, setHole] = useState<LayoutRectangle | null>(null);
4546
const { width: screenWidth, height: screenHeight } = Dimensions.get('window');
@@ -50,15 +51,16 @@ export const HighlightToolTip: React.FC<HighlightOverlayProps> = ({
5051
UIManager.measureInWindow(
5152
handle!,
5253
(x: number, y: number, width: number, height: number) => {
54+
const isAndroid = Platform.OS === 'android';
5355
setHole({
5456
x,
55-
y: y + measureOffsetY,
57+
y: isAndroid ? y + androidOffsetY : y,
5658
width,
5759
height,
5860
});
5961
}
6062
);
61-
}, [targetRef, measureOffsetY]);
63+
}, [targetRef, androidOffsetY]);
6264

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

0 commit comments

Comments
 (0)