mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React from 'react'
2import {Pressable, View} from 'react-native'
3import Animated, {
4 runOnJS,
5 useAnimatedStyle,
6 useSharedValue,
7 withTiming,
8} from 'react-native-reanimated'
9import {msg} from '@lingui/macro'
10import {useLingui} from '@lingui/react'
11
12import {ScaleAndFadeIn} from '#/lib/custom-animations/ScaleAndFade'
13import {ShrinkAndPop} from '#/lib/custom-animations/ShrinkAndPop'
14import {useHaptics} from '#/lib/haptics'
15import {isWeb} from '#/platform/detection'
16import {atoms as a, useTheme} from '#/alf'
17import {Text} from '#/components/Typography'
18
19const AnimatedPressable = Animated.createAnimatedComponent(Pressable)
20
21let lastIndex = 0
22
23export function ChatEmptyPill() {
24 const t = useTheme()
25 const {_} = useLingui()
26 const playHaptic = useHaptics()
27 const [promptIndex, setPromptIndex] = React.useState(lastIndex)
28
29 const scale = useSharedValue(1)
30
31 const prompts = React.useMemo(() => {
32 return [
33 _(msg`Say hello!`),
34 _(msg`Share your favorite feed!`),
35 _(msg`Tell a joke!`),
36 _(msg`Share a fun fact!`),
37 _(msg`Share a cool story!`),
38 _(msg`Send a neat website!`),
39 _(msg`Clip 🐴 clop 🐴`),
40 ]
41 }, [_])
42
43 const onPressIn = React.useCallback(() => {
44 if (isWeb) return
45 scale.set(() => withTiming(1.075, {duration: 100}))
46 }, [scale])
47
48 const onPressOut = React.useCallback(() => {
49 if (isWeb) return
50 scale.set(() => withTiming(1, {duration: 100}))
51 }, [scale])
52
53 const onPress = React.useCallback(() => {
54 runOnJS(playHaptic)()
55 let randomPromptIndex = Math.floor(Math.random() * prompts.length)
56 while (randomPromptIndex === lastIndex) {
57 randomPromptIndex = Math.floor(Math.random() * prompts.length)
58 }
59 setPromptIndex(randomPromptIndex)
60 lastIndex = randomPromptIndex
61 }, [playHaptic, prompts.length])
62
63 const animatedStyle = useAnimatedStyle(() => ({
64 transform: [{scale: scale.get()}],
65 }))
66
67 return (
68 <View
69 style={[
70 a.absolute,
71 a.w_full,
72 a.z_10,
73 a.align_center,
74 {
75 top: -50,
76 },
77 ]}>
78 <AnimatedPressable
79 style={[
80 a.px_xl,
81 a.py_md,
82 a.rounded_full,
83 t.atoms.bg_contrast_25,
84 a.align_center,
85 animatedStyle,
86 ]}
87 entering={ScaleAndFadeIn}
88 exiting={ShrinkAndPop}
89 onPress={onPress}
90 onPressIn={onPressIn}
91 onPressOut={onPressOut}>
92 <Text
93 style={[a.font_semi_bold, a.pointer_events_none]}
94 selectable={false}>
95 {prompts[promptIndex]}
96 </Text>
97 </AnimatedPressable>
98 </View>
99 )
100}