Live video on the AT Protocol
1import { useEffect } from "react";
2import { StyleSheet, View } from "react-native";
3import Animated, {
4 useAnimatedStyle,
5 useSharedValue,
6 withRepeat,
7 withTiming,
8} from "react-native-reanimated";
9
10export default function LiveDot() {
11 // Use useSharedValue for the animation value
12 const pulseAnim = useSharedValue(1);
13 const opacityAnim = useSharedValue(1);
14
15 useEffect(() => {
16 pulseAnim.value = withRepeat(withTiming(2.25, { duration: 1000 }), -1);
17 opacityAnim.value = withRepeat(withTiming(0, { duration: 1000 }), -1);
18 }, [pulseAnim, opacityAnim]);
19
20 const animatedPulseStyle = useAnimatedStyle(() => {
21 return {
22 transform: [{ scale: pulseAnim.value }],
23 opacity: opacityAnim.value,
24 };
25 });
26
27 return (
28 <View style={styles.container}>
29 {/* Apply the animated style to the Animated.View */}
30 <Animated.View
31 style={[
32 styles.pulseDot,
33 animatedPulseStyle, // Apply the animated style
34 ]}
35 />
36 <View style={styles.solidDot} />
37 </View>
38 );
39}
40
41const styles = StyleSheet.create({
42 container: {
43 width: 24,
44 height: 24,
45 justifyContent: "center",
46 alignItems: "center",
47 },
48 solidDot: {
49 width: 12,
50 height: 12,
51 borderRadius: 999,
52 backgroundColor: "red",
53 position: "absolute",
54 },
55 pulseDot: {
56 width: 10,
57 height: 10,
58 borderRadius: 5,
59 backgroundColor: "red",
60 position: "absolute",
61 },
62});