loadingDots.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { useEffect, useRef } from 'react';
  2. import { View, Animated, StyleSheet } from 'react-native';
  3. const LoadingDots = () => {
  4. const fadeAnim1 = useRef(new Animated.Value(1)).current;
  5. const fadeAnim2 = useRef(new Animated.Value(0)).current;
  6. const fadeAnim3 = useRef(new Animated.Value(0)).current;
  7. useEffect(() => {
  8. const animateSequence = () => {
  9. Animated.sequence([
  10. Animated.timing(fadeAnim1, {
  11. toValue: 1,
  12. duration: 500,
  13. useNativeDriver: true
  14. }),
  15. Animated.timing(fadeAnim1, {
  16. toValue: 0,
  17. duration: 0,
  18. useNativeDriver: true
  19. }),
  20. Animated.timing(fadeAnim2, {
  21. toValue: 1,
  22. duration: 500,
  23. useNativeDriver: true
  24. }),
  25. Animated.timing(fadeAnim2, {
  26. toValue: 0,
  27. duration: 0,
  28. useNativeDriver: true
  29. }),
  30. Animated.timing(fadeAnim3, {
  31. toValue: 1,
  32. duration: 500,
  33. useNativeDriver: true
  34. }),
  35. Animated.timing(fadeAnim3, {
  36. toValue: 0,
  37. duration: 0,
  38. useNativeDriver: true
  39. })
  40. ]).start(() => {
  41. animateSequence();
  42. });
  43. };
  44. animateSequence();
  45. }, [fadeAnim1, fadeAnim2, fadeAnim3]);
  46. return (
  47. <View className="flex-row items-center">
  48. <Animated.Text style={[styles.text, { opacity: fadeAnim1 }]}>
  49. </Animated.Text>
  50. <Animated.Text style={[styles.text, { opacity: fadeAnim2 }]}>
  51. </Animated.Text>
  52. <Animated.Text style={[styles.text, { opacity: fadeAnim3 }]}>
  53. </Animated.Text>
  54. </View>
  55. );
  56. };
  57. const styles = StyleSheet.create({
  58. text: {
  59. fontSize: 16,
  60. color: '#02677D'
  61. }
  62. });
  63. export default LoadingDots;