Skip to content

Commit 84eef08

Browse files
committed
fix: separate PointerWrapper component from TooltipWrapper
1 parent f4a4b7c commit 84eef08

File tree

6 files changed

+53
-17
lines changed

6 files changed

+53
-17
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React, { useMemo } from 'react';
2+
import { StyleSheet, View } from 'react-native';
3+
4+
import { getPointerWrapperStyle } from '../../utils';
5+
import type { PointerWrapperProps } from '../../types';
6+
7+
import Pointer from '../Pointer';
8+
9+
import styles from './styles';
10+
11+
const PointerWrapper: React.FC<PointerWrapperProps> = ({
12+
tooltipLayout,
13+
...pointerProps
14+
}) => {
15+
const pointerStyles = useMemo(
16+
() =>
17+
StyleSheet.flatten([
18+
styles.wrapper,
19+
getPointerWrapperStyle(pointerProps, tooltipLayout),
20+
]),
21+
[pointerProps, tooltipLayout]
22+
);
23+
24+
return (
25+
<View style={pointerStyles}>
26+
<Pointer {...pointerProps} />
27+
</View>
28+
);
29+
};
30+
31+
export default PointerWrapper;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './PointerWrapper';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { StyleSheet } from 'react-native';
2+
3+
const pointerWrapperStyles = StyleSheet.create({
4+
wrapper: {
5+
position: 'absolute',
6+
},
7+
});
8+
9+
export default pointerWrapperStyles;

src/components/TooltipWrapper/TooltipWrapper.tsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import React, { useMemo } from 'react';
2-
import { StyleSheet, View, ViewStyle } from 'react-native';
32
import Animated, { useAnimatedStyle } from 'react-native-reanimated';
43

54
import { useLayout } from '../../hooks';
5+
import { getPositionStyles } from '../../utils';
66
import type { TooltipWrapperProps } from '../../types';
7-
import { getPointerWrapperStyle, getPositionStyles } from '../../utils';
87

9-
import Pointer from '../Pointer';
8+
import PointerWrapper from '../PointerWrapper';
109

1110
import styles from './styles';
1211

@@ -37,22 +36,17 @@ const TooltipWrapperComponent: React.FC<TooltipWrapperProps> = (props) => {
3736
});
3837
}, [layout, position, props]);
3938

40-
const pointerStyles = useMemo(() => {
41-
return StyleSheet.flatten<ViewStyle>([
42-
styles.pointer,
43-
getPointerWrapperStyle({ position, ...pointerProps }, layout),
44-
]);
45-
}, [position, pointerProps, layout]);
46-
4739
return (
4840
<Animated.View
4941
onLayout={onLayout}
5042
style={[styles.tooltipWrapper, positionStyles, stylez]}
5143
>
5244
{children}
53-
<View style={pointerStyles}>
54-
<Pointer {...pointerProps} position={position} />
55-
</View>
45+
<PointerWrapper
46+
{...pointerProps}
47+
tooltipLayout={layout}
48+
position={position}
49+
/>
5650
</Animated.View>
5751
);
5852
};

src/components/TooltipWrapper/styles.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ const tooltipWrapperStyles = StyleSheet.create({
55
position: 'absolute',
66
opacity: 0,
77
},
8-
pointer: {
9-
position: 'absolute',
10-
},
118
});
129

1310
export default tooltipWrapperStyles;

src/types/ComponentsProps.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ export interface OverlayProps
2020
overlayStyle?: ViewStyle;
2121
}
2222

23+
export interface PointerWrapperProps extends PointerProps {
24+
tooltipLayout?: LayoutRectangle;
25+
}
26+
2327
export interface TooltipWrapperProps
2428
extends RequiredChildrenProp,
2529
AnimatedPresenceProp,
26-
PointerProps {
30+
Omit<PointerWrapperProps, 'tooltipLayout'> {
2731
offset?: number;
2832
childrenLayout?: LayoutRectangle;
2933
}

0 commit comments

Comments
 (0)