All files / apps/host/src/screens/Profile/Skeleton RequestChartSkeleton.tsx

100% Statements 17/17
100% Branches 0/0
100% Functions 5/5
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191                2x 2x           2x 4x 4x 4x   4x 4x                 4x   4x 4x 4x       4x         4x                                             8x                                               4x                                                                                                                                                                                                        
import { useEffect, useRef } from 'react';
import { Animated, Easing, type StyleProp, View, type ViewStyle } from 'react-native';
 
import { makeStyles } from '@repo/ui/themes/makeStyles';
import { useTheme } from '@repo/ui/themes/ThemeContext';
 
import { SCREEN_WIDTH } from '@/utils/dimensions';
 
const DONUT_SIZE_RATIO = 0.55;
const DONUT_STROKE_WIDTH = 26;
 
interface RequestChartSkeletonProps {
  style?: StyleProp<ViewStyle>;
}
 
export const RequestChartSkeleton = ({ style }: RequestChartSkeletonProps) => {
  const { theme } = useTheme();
  const styles = useStyles();
  const pulse = useRef(new Animated.Value(0)).current;
 
  useEffect(() => {
    const pulseAnimation = Animated.loop(
      Animated.timing(pulse, {
        toValue: 1,
        duration: 1000,
        easing: Easing.inOut(Easing.ease),
        useNativeDriver: true,
      }),
    );
 
    pulseAnimation.start();
 
    return () => {
      pulseAnimation.stop();
      pulse.setValue(0);
    };
  }, [pulse]);
 
  const opacity = pulse.interpolate({
    inputRange: [0, 1],
    outputRange: [theme.metrics.opacity[40], theme.metrics.opacity[100]],
  });
 
  return (
    <View
      style={[styles.container, style]}
      accessibilityRole="progressbar"
      accessibilityLabel="Loading"
    >
      <View style={styles.chartWrap}>
        <Animated.View style={[styles.chartRing, { opacity }]} />
 
        <View style={styles.chartCenter}>
          <Animated.View style={[styles.chartCenterLabel, { opacity }]} />
          <Animated.View style={[styles.chartCenterValue, { opacity }]} />
        </View>
      </View>
 
      <View style={styles.periodSummary}>
        <View style={styles.periodSwitch}>
          <Animated.View style={[styles.periodButton, { opacity }]} />
          <Animated.View style={[styles.periodButton, { opacity }]} />
        </View>
 
        <View style={styles.activityWrap}>
          {[0, 1].map(row => (
            <View key={`request-skeleton-row-${row}`} style={styles.activityRow}>
              <View style={styles.activityItem}>
                <Animated.View style={[styles.activityBar, { opacity }]} />
                <View style={styles.activityTextWrap}>
                  <Animated.View style={[styles.activityValue, { opacity }]} />
                  <Animated.View style={[styles.activityLabel, { opacity }]} />
                </View>
              </View>
 
              <View style={styles.activityItem}>
                <Animated.View style={[styles.activityBar, { opacity }]} />
                <View style={styles.activityTextWrap}>
                  <Animated.View style={[styles.activityValue, { opacity }]} />
                  <Animated.View style={[styles.activityLabel, { opacity }]} />
                </View>
              </View>
            </View>
          ))}
        </View>
      </View>
    </View>
  );
};
 
const useStyles = makeStyles(theme => ({
  container: {
    backgroundColor: theme.colors.background.secondary,
    borderRadius: theme.metrics.borderRadius[6],
    width: theme.metrics.sizing.full,
    paddingHorizontal: theme.metrics.spacing[2.5],
    paddingTop: theme.metrics.spacing[5.5],
    paddingBottom: theme.metrics.spacing[5],
    alignItems: 'center',
    gap: theme.metrics.spacing[3],
  },
  chartWrap: {
    width: Math.floor(SCREEN_WIDTH * DONUT_SIZE_RATIO),
    height: Math.floor(SCREEN_WIDTH * DONUT_SIZE_RATIO),
    marginTop: -theme.metrics.spacing[2],
    marginBottom: theme.metrics.spacing[6],
    alignItems: 'center',
    justifyContent: 'center',
  },
  chartRing: {
    width: theme.metrics.sizing.full,
    height: theme.metrics.sizing.full,
    borderRadius: theme.metrics.borderRadius.circle,
    borderWidth: DONUT_STROKE_WIDTH,
    borderColor: theme.colors.skeleton.default,
  },
  chartCenter: {
    position: 'absolute',
    alignItems: 'center',
    justifyContent: 'center',
    gap: theme.metrics.spacing[0.5],
  },
  chartCenterLabel: {
    width: theme.metrics.spacing[16],
    height: theme.metrics.spacing[4],
    borderRadius: theme.metrics.borderRadius[1],
    backgroundColor: theme.colors.skeleton.default,
  },
  chartCenterValue: {
    width: theme.metrics.spacing[12],
    height: theme.metrics.spacing[8],
    borderRadius: theme.metrics.borderRadius[1.5],
    backgroundColor: theme.colors.skeleton.default,
  },
  periodSummary: {
    width: theme.metrics.sizing.full,
    gap: theme.metrics.spacing[7.5],
  },
  periodSwitch: {
    width: theme.metrics.sizing.full,
    flexDirection: 'row',
    gap: theme.metrics.spacing[0.5],
    backgroundColor: theme.colors.background.tertiary,
    borderRadius: theme.metrics.borderRadius[2.5],
    padding: theme.metrics.spacing[0.75],
  },
  periodButton: {
    flex: 1,
    minHeight: theme.metrics.spacing[10],
    borderRadius: theme.metrics.borderRadius[2],
    backgroundColor: theme.colors.skeleton.default,
  },
  activityWrap: {
    width: theme.metrics.sizing.full,
    gap: theme.metrics.spacing[8.75],
  },
  activityRow: {
    flexDirection: 'row',
    gap: theme.metrics.spacing[8.75],
    marginLeft: theme.metrics.spacing[9],
    alignItems: 'flex-start',
  },
  activityItem: {
    flex: 1,
    flexDirection: 'row',
    gap: theme.metrics.spacing[1.5],
    alignItems: 'flex-start',
  },
  activityBar: {
    width: theme.metrics.spacing[1.5],
    height: theme.metrics.spacing[12.5],
    borderRadius: theme.metrics.borderRadius[1],
    backgroundColor: theme.colors.skeleton.default,
  },
  activityTextWrap: {
    gap: theme.metrics.spacing[0.25],
  },
  activityValue: {
    width: theme.metrics.spacing[8],
    height: theme.metrics.spacing[8.5],
    borderRadius: theme.metrics.borderRadius[1],
    backgroundColor: theme.colors.skeleton.default,
  },
  activityLabel: {
    width: theme.metrics.spacing[20],
    height: theme.metrics.spacing[4.5],
    borderRadius: theme.metrics.borderRadius[2],
    backgroundColor: theme.colors.skeleton.default,
  },
}));