import React, { useRef, useState, useEffect } from "react"; import { View, ActivityIndicator } from "react-native"; import ScreenWrapper from "~/components/ui/ScreenWrapper"; import { Text } from "~/components/ui/text"; import { Button } from "~/components/ui/button"; import LottieView from "lottie-react-native"; import * as Network from "expo-network"; import { router } from "expo-router"; import { HOME } from "~/lib/routes"; import ModalToast from "~/components/ui/toast"; export default function NoInternetScreen() { const [checking, setChecking] = useState(false); const [error, setError] = useState(null); const [toastVisible, setToastVisible] = useState(false); const [toastTitle, setToastTitle] = useState("Can't connect to network"); const [toastDescription, setToastDescription] = useState( undefined ); const [toastVariant, setToastVariant] = useState< "success" | "error" | "warning" | "info" >("error"); const toastTimeoutRef = useRef | null>(null); const showToast = () => { if (toastTimeoutRef.current) { clearTimeout(toastTimeoutRef.current); } setToastTitle("Can't connect to network"); setToastDescription(undefined); setToastVariant("error"); setToastVisible(true); toastTimeoutRef.current = setTimeout(() => { setToastVisible(false); toastTimeoutRef.current = null; }, 2500); }; useEffect(() => { return () => { if (toastTimeoutRef.current) { clearTimeout(toastTimeoutRef.current); } }; }, []); const handleRetry = async () => { setChecking(true); setError(null); try { const state = await Network.getNetworkStateAsync(); const isOffline = !state.isConnected || state.isInternetReachable === false; if (!isOffline) { router.replace(HOME); } else { setError("Still offline. Please check your connection."); showToast(); } } catch (e) { setError("Unable to check connection. Please try again."); showToast(); } finally { setChecking(false); } }; return ( No Internet Please reconnect the application to the internet. ); }