-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathLoadingOverlay.tsx
More file actions
63 lines (59 loc) · 2.18 KB
/
LoadingOverlay.tsx
File metadata and controls
63 lines (59 loc) · 2.18 KB
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
import React, { useMemo } from 'react';
import { YStack, Spinner, Text, useTheme } from 'tamagui';
import LinearGradient from 'react-native-linear-gradient';
interface LoadingOverlayProps {
visible: boolean;
text?: string;
spinnerSize?: number | string;
spinnerColor?: string;
textColor?: string;
bgColor?: string;
overlayOpacity?: number;
}
const LoadingOverlay: React.FC<LoadingOverlayProps> = ({
visible = false,
text,
spinnerSize = 'lg',
spinnerColor = '$textPrimary',
textColor = '$textPrimary',
bgColor = 'gray',
overlayOpacity = 0.85,
numberOfLines = 1,
}) => {
const theme = useTheme();
const gradientColors = useMemo(() => {
try {
return [theme[`$black`].val, theme[`$${bgColor}-900`].val, theme[`$${bgColor}-800`].val, theme[`$${bgColor}-900`].val, theme[`$black`].val];
} catch (e) {
// Fallback static colors if theme lookup fails.
return ['#111827', '#1f2937', '#374151', '#4b5563'];
}
}, [bgColor, theme]);
if (!visible) return <YStack />;
return (
<YStack position='absolute' top={0} left={0} right={0} bottom={0} justifyContent='center' alignItems='center' zIndex={9999}>
<LinearGradient
colors={gradientColors}
start={{ x: 0, y: 0 }}
end={{ x: 0, y: 1 }}
style={{ position: 'absolute', opacity: overlayOpacity, top: 0, left: 0, right: 0, bottom: 0 }}
/>
<YStack flex={1} alignItems='center' justifyContent='center'>
<Spinner size={spinnerSize} color={spinnerColor} />
{text && (
<Text
marginTop='$2'
fontSize={16}
color={textColor}
numberOfLines={numberOfLines}
mt='$5'
style={{ textShadowColor: 'rgba(0, 0, 0, 0.9)', textShadowOffset: { width: -1, height: 1 }, textShadowRadius: 10 }}
>
{text}
</Text>
)}
</YStack>
</YStack>
);
};
export default LoadingOverlay;