mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-02 21:24:20 -04:00
Cleanup splash screen handling
This commit is contained in:
parent
1c7c4d3ab2
commit
3d53693e68
@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
import { Icon } from "@kyoo/primitives";
|
import { Icon } from "@kyoo/primitives";
|
||||||
import { Tabs } from "expo-router";
|
import { Tabs } from "expo-router";
|
||||||
import { useTheme } from "yoshiki/native";
|
|
||||||
import Home from "@material-symbols/svg-400/rounded/home-fill.svg";
|
import Home from "@material-symbols/svg-400/rounded/home-fill.svg";
|
||||||
import Browse from "@material-symbols/svg-400/rounded/browse-fill.svg";
|
import Browse from "@material-symbols/svg-400/rounded/browse-fill.svg";
|
||||||
|
|
||||||
|
@ -19,10 +19,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { ConnectionErrorContext, useAccount } from "@kyoo/models";
|
import { ConnectionErrorContext, useAccount } from "@kyoo/models";
|
||||||
|
import { CircularProgress } from "@kyoo/primitives";
|
||||||
import { NavbarRight, NavbarTitle } from "@kyoo/ui";
|
import { NavbarRight, NavbarTitle } from "@kyoo/ui";
|
||||||
import { LoadingIndicator } from "@kyoo/ui/src/player/components/hover";
|
import { Redirect, SplashScreen, Stack } from "expo-router";
|
||||||
import { Redirect, Stack } from "expo-router";
|
import { useContext, useEffect } from "react";
|
||||||
import { useContext, useRef } from "react";
|
|
||||||
import { useTheme } from "yoshiki/native";
|
import { useTheme } from "yoshiki/native";
|
||||||
|
|
||||||
export default function SignGuard() {
|
export default function SignGuard() {
|
||||||
@ -30,12 +30,12 @@ export default function SignGuard() {
|
|||||||
// TODO: support guest accounts on mobile too.
|
// TODO: support guest accounts on mobile too.
|
||||||
const account = useAccount();
|
const account = useAccount();
|
||||||
const { loading, error } = useContext(ConnectionErrorContext);
|
const { loading, error } = useContext(ConnectionErrorContext);
|
||||||
const wasRendered = useRef(false);
|
|
||||||
|
|
||||||
// While loading, keep the splashcreen if possible. if not, display a spinner.
|
useEffect(() => {
|
||||||
if (loading) return wasRendered.current ? <LoadingIndicator /> : null;
|
if (!loading) SplashScreen.hideAsync();
|
||||||
wasRendered.current = true;
|
}, [loading]);
|
||||||
|
|
||||||
|
if (loading) return <CircularProgress />;
|
||||||
if (error) return <Redirect href={"/connection-error"} />;
|
if (error) return <Redirect href={"/connection-error"} />;
|
||||||
if (!account) return <Redirect href="/login" />;
|
if (!account) return <Redirect href="/login" />;
|
||||||
return (
|
return (
|
||||||
|
@ -34,7 +34,7 @@ import {
|
|||||||
Poppins_400Regular,
|
Poppins_400Regular,
|
||||||
Poppins_900Black,
|
Poppins_900Black,
|
||||||
} from "@expo-google-fonts/poppins";
|
} from "@expo-google-fonts/poppins";
|
||||||
import { ReactNode, useEffect, useState } from "react";
|
import { ReactNode, useState } from "react";
|
||||||
import { useColorScheme } from "react-native";
|
import { useColorScheme } from "react-native";
|
||||||
import { initReactI18next } from "react-i18next";
|
import { initReactI18next } from "react-i18next";
|
||||||
import { ThemeProvider as RNThemeProvider } from "@react-navigation/native";
|
import { ThemeProvider as RNThemeProvider } from "@react-navigation/native";
|
||||||
@ -61,8 +61,6 @@ i18next.use(initReactI18next).init({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
SplashScreen.preventAutoHideAsync();
|
|
||||||
|
|
||||||
const NavigationThemeProvider = ({ children }: { children: ReactNode }) => {
|
const NavigationThemeProvider = ({ children }: { children: ReactNode }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
return (
|
return (
|
||||||
@ -84,15 +82,13 @@ const NavigationThemeProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
SplashScreen.preventAutoHideAsync();
|
||||||
|
|
||||||
export default function Root() {
|
export default function Root() {
|
||||||
const [queryClient] = useState(() => createQueryClient());
|
const [queryClient] = useState(() => createQueryClient());
|
||||||
const theme = useColorScheme();
|
const theme = useColorScheme();
|
||||||
const [fontsLoaded] = useFonts({ Poppins_300Light, Poppins_400Regular, Poppins_900Black });
|
const [fontsLoaded] = useFonts({ Poppins_300Light, Poppins_400Regular, Poppins_900Black });
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (fontsLoaded) SplashScreen.hideAsync();
|
|
||||||
}, [fontsLoaded]);
|
|
||||||
|
|
||||||
if (!fontsLoaded) return null;
|
if (!fontsLoaded) return null;
|
||||||
return (
|
return (
|
||||||
<QueryClientProvider client={queryClient}>
|
<QueryClientProvider client={queryClient}>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user