Files
Folo/apps/mobile/src/lib/loading.tsx
T
Innei 2854255050 feat(mobile): enhance 2FA settings and loading experience
- Renamed `Setting2FA` to `TwoFASettingScreen` for clarity and consistency.
- Removed the deprecated `Setting2FAScreen` component.
- Updated loading behavior to support both promise-based and immediate loading states.
- Integrated `ActivityIndicator` for iOS and retained `RotateableLoading` for other platforms.
- Improved loading overlay with a `BlurView` for better visual feedback during operations.

Signed-off-by: Innei <tukon479@gmail.com>
2025-03-13 23:29:24 +08:00

81 lines
2.4 KiB
TypeScript

import { BlurView } from "expo-blur"
import type { FC } from "react"
import { useEffect, useRef, useState } from "react"
import {
ActivityIndicator,
Platform,
Pressable,
StyleSheet,
TouchableOpacity,
View,
} from "react-native"
import RootSiblings from "react-native-root-siblings"
import { FullWindowOverlay } from "../components/common/FullWindowOverlay"
import { RotateableLoading } from "../components/common/RotateableLoading"
import { CloseCuteReIcon } from "../icons/close_cute_re"
class LoadingStatic {
start(): { done: () => void }
start<T>(promise: Promise<T>): Promise<T>
start<T>(promise?: Promise<T>) {
const siblings = new RootSiblings(<LoadingContainer cancel={() => siblings.destroy()} />)
if (promise) {
promise.finally(() => siblings.destroy())
return promise
} else {
return {
done: () => {
siblings.destroy()
},
}
}
}
}
export const loading = new LoadingStatic()
const LoadingContainer: FC<{
cancel: () => void
}> = ({ cancel }) => {
const cancelTimerRef = useRef<NodeJS.Timeout | null>(null)
const [showCancelButton, setShowCancelButton] = useState(false)
useEffect(() => {
cancelTimerRef.current = setTimeout(() => {
setShowCancelButton(true)
}, 3000)
return () => {
if (cancelTimerRef.current) {
clearTimeout(cancelTimerRef.current)
}
}
}, [])
return (
<FullWindowOverlay>
{/* Pressable to prevent the overlay from being clicked */}
<Pressable style={StyleSheet.absoluteFillObject} className="items-center justify-center">
<View className="border-non-opaque-separator relative overflow-hidden rounded-2xl border p-12">
<BlurView style={StyleSheet.absoluteFillObject} tint="systemChromeMaterialDark" />
{Platform.OS === "ios" ? (
<ActivityIndicator size={"large"} color="white" />
) : (
<RotateableLoading />
)}
</View>
{showCancelButton && (
<View className="absolute inset-x-0 bottom-24 flex-row justify-center">
<TouchableOpacity onPress={cancel}>
<View className="border-opaque-separator rounded-full border-2 p-2">
<CloseCuteReIcon color="gray" height={20} width={20} />
</View>
</TouchableOpacity>
</View>
)}
</Pressable>
</FullWindowOverlay>
)
}