File size: 1,505 Bytes
68465df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import {View, ActivityIndicator, ViewStyle, TextStyle} from "react-native"

import {Text} from "@/components/ignite"
import {useAppTheme} from "@/contexts/ThemeContext"
import {ThemedStyle} from "@/theme"

interface LoadingOverlayProps {
  message?: string
}

/**

 * A consistent loading overlay component to be used across the app

 * for loading states, especially during transitions between screens.

 */
const LoadingOverlay = ({message = "Loading..."}: LoadingOverlayProps) => {
  const {themed, theme} = useAppTheme()

  return (
    <View style={themed($container)}>

      <View style={themed($contentContainer)}>

        <ActivityIndicator size="large" color={theme.colors.foreground} style={themed($spinner)} />

        <Text text={message} style={themed($message)} />

      </View>

    </View>
  )
}

const $container: ThemedStyle<ViewStyle> = ({colors}) => ({
  alignItems: "center",
  bottom: 0,
  justifyContent: "center",
  left: 0,
  position: "absolute",
  right: 0,
  top: 0,
  zIndex: 1000,
  backgroundColor: colors.background,
})

const $contentContainer: ThemedStyle<ViewStyle> = () => ({
  alignItems: "center",
  borderRadius: 10,
  justifyContent: "center",
  padding: 20,
})

const $message: ThemedStyle<TextStyle> = ({colors}) => ({
  fontSize: 16,
  fontWeight: "500",
  textAlign: "center",
  color: colors.text,
})

const $spinner: ThemedStyle<ViewStyle> = () => ({
  marginBottom: 12,
})

export default LoadingOverlay