-
Notifications
You must be signed in to change notification settings - Fork 0
/
Placeholder.tsx
98 lines (93 loc) · 2.42 KB
/
Placeholder.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import React from "react";
import { Pressable, Platform, ColorValue } from "react-native";
import Animated, {
Extrapolate,
SharedValue,
interpolate,
useAnimatedStyle,
} from "react-native-reanimated";
import { TabItemProps } from "./TabItem";
type PlaceholderProps = {
translateX: number;
tabTranslation: SharedValue<number>;
index: number;
onPress?: (translateX: number) => void;
tabWidth: TabItemProps["tabWidth"];
tabHeight: TabItemProps["tabHeight"];
renderText: () => React.ReactNode;
backgroundColor: ColorValue;
containerPadding: number;
borderRadius: number;
};
const AnimatedTouchable = Animated.createAnimatedComponent(Pressable);
export const Placeholder: React.FC<PlaceholderProps> = ({
translateX,
tabTranslation,
index,
onPress,
tabHeight,
tabWidth,
renderText,
backgroundColor,
containerPadding,
borderRadius,
}) => {
const animatedStyle = useAnimatedStyle(() => {
const opacity = interpolate(
tabTranslation.value,
[(index - 1) * translateX, index * translateX, (index + 1) * translateX],
[0.2, 0, 0.2],
Extrapolate.CLAMP
);
return { opacity };
});
const textAnimatedStyle = useAnimatedStyle(() => {
const opacity = interpolate(
tabTranslation.value,
[(index - 1) * translateX, index * translateX, (index + 1) * translateX],
[0, 1, 0],
Extrapolate.CLAMP
);
return { opacity };
});
return (
<>
<AnimatedTouchable
onPress={onPress?.bind("", translateX * index)}
style={[
{
backgroundColor,
zIndex: Platform.OS === "ios" ? -1 : 1,
position: "absolute",
width: tabWidth,
height: tabHeight,
borderRadius,
top: containerPadding,
start: containerPadding,
transform: [{ translateX: translateX * index }],
},
animatedStyle,
]}
/>
<Animated.View
pointerEvents="none"
style={[
{
zIndex: 2,
position: "absolute",
width: tabWidth,
height: tabHeight,
top: containerPadding,
start: containerPadding,
transform: [{ translateX: translateX * index }],
justifyContent: "center",
alignItems: "center",
},
textAnimatedStyle,
]}
>
{renderText()}
</Animated.View>
</>
);
};