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 | 1x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 1x 9x 1x | import { cn } from '@sb/libs/utils';
import { colors } from '@sb/styles/colors';
import { Path, Svg } from 'react-native-svg';
import { FC, useEffect, useRef } from 'react';
import { useThemeColors } from '@sb/hooks/Utilities/useThemeColors';
import { calculateLoaderSize, gapWidthMap, radius, strokeWidthMap } from '../utils';
import { SizeMapProps, SplitLoaderProps, SplitLoaderSize } from '../SplitLoader.types';
import { AccessibilityProps, Animated, Easing, StyleSheet, Text, View } from 'react-native';
const SplitLoader: FC<SplitLoaderProps> = ({
id,
className,
size = 'medium',
text = 'Lädt...',
showLoaderText = true,
showLoaderShadow = true,
}) => {
const { themedColors } = useThemeColors();
const sizeMap: Record<SplitLoaderSize, SizeMapProps> = {
small: {
loaderContainer: 'size-20',
svgSize: 60,
},
medium: {
loaderContainer: 'size-24',
svgSize: 80,
},
large: {
loaderContainer: 'size-28',
svgSize: 100,
},
};
const loaderSize = sizeMap[size];
const gapAngle = gapWidthMap[size];
const strokeWidth = strokeWidthMap[size];
const gapRadians = (gapAngle * Math.PI) / 180;
const { startX1, startY1, endX1, endX2, startX2, startY2, endY1, endY2 } =
calculateLoaderSize(gapRadians);
const accessibilityProps: AccessibilityProps = {
accessibilityRole: 'progressbar',
accessibilityLiveRegion: 'polite',
accessibilityLabel: 'Loading indicator',
};
const spinAnim = useRef(new Animated.Value(0)).current;
useEffect(() => {
Animated.loop(
Animated.timing(spinAnim, {
toValue: 1,
duration: 2000,
easing: Easing.linear,
useNativeDriver: true,
})
).start();
}, [spinAnim]);
const spin = spinAnim.interpolate({
inputRange: [0, 1],
outputRange: ['0deg', '360deg'],
});
return (
<View
id={id}
{...accessibilityProps}
testID="split-loader"
className={cn(
'flex w-full flex-col items-center justify-center',
className,
loaderSize.loaderContainer
)}
>
<Text className="sr-only">Animated spinning loading indicator</Text>
{showLoaderShadow && <DropShadow />}
<Animated.View
className="flex flex-col items-center justify-center"
style={{ transform: [{ rotate: spin }] }}
>
<Svg
width={loaderSize.svgSize}
height={loaderSize.svgSize}
viewBox="0 0 100 100"
role="img"
testID="svg-loader"
>
<Path
d={`M${startX1},${startY1} A${radius},${radius} 0 0,1 ${endX1},${endY1}`}
stroke={colors.light.colorLoader_Primary_Bracket}
strokeWidth={strokeWidth}
fill="none"
strokeLinecap="round"
/>
<Path
d={`M${startX2},${startY2} A${radius},${radius} 0 0,1 ${endX2},${endY2}`}
stroke={colors.light.colorLoader_Secondary_Bracket}
strokeWidth={strokeWidth}
fill="none"
strokeLinecap="round"
/>
</Svg>
</Animated.View>
{showLoaderText && (
<View
className="absolute inset-0 flex flex-col items-center justify-center"
pointerEvents="none"
>
<Text
style={{
color: themedColors.colorText_Main,
}}
className={cn('', {
'text-sm font-normal': size === 'small',
'text-base font-semibold': size === 'medium',
'font-Bold text-lg': size === 'large',
})}
>
{text}
</Text>
</View>
)}
</View>
);
};
export default SplitLoader;
const DropShadow = () => {
return (
<Svg
testID="sr-only-text"
style={styles.container}
width={50}
height="10"
viewBox="0 0 40 10"
fill="none"
>
<Path
opacity="0.4"
d="M21 0.5C26.7718 0.5 31.9811 1.05777 35.7334 1.95117C37.6134 2.3988 39.1001 2.92389 40.1045 3.48926C41.1497 4.0776 41.5 4.60761 41.5 5C41.5 5.39239 41.1497 5.9224 40.1045 6.51074C39.1001 7.07611 37.6134 7.6012 35.7334 8.04883C31.9811 8.94223 26.7718 9.5 21 9.5C15.2282 9.5 10.0189 8.94223 6.2666 8.04883C4.38656 7.6012 2.89988 7.07611 1.89551 6.51074C0.850348 5.9224 0.5 5.39239 0.5 5C0.5 4.60761 0.850348 4.0776 1.89551 3.48926C2.89988 2.92389 4.38656 2.3988 6.2666 1.95117C10.0189 1.05777 15.2282 0.5 21 0.5Z"
fill={colors.light.colorStatus_Closed}
/>
</Svg>
);
};
const styles = StyleSheet.create({
container: {
width: '50%',
flex: 1,
justifyContent: 'center',
alignItems: 'center',
position: 'absolute',
bottom: -40,
},
});
|