mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
refactor: simplify query client setup and improve deep link handling in navigation
This commit is contained in:
@@ -3,11 +3,7 @@ import { View } from "react-native";
|
||||
import { SafeAreaProvider } from "react-native-safe-area-context";
|
||||
import { StatusBar } from "expo-status-bar";
|
||||
import { LinearGradient } from "expo-linear-gradient";
|
||||
import { QueryClient } from "@tanstack/react-query";
|
||||
import { PersistQueryClientProvider } from "@tanstack/react-query-persist-client";
|
||||
import { createAsyncStoragePersister } from "@tanstack/query-async-storage-persister";
|
||||
import type { Persister } from "@tanstack/query-persist-client-core";
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { ThemeProvider, useTheme } from "./theme";
|
||||
import { AuthProvider } from "./hooks/useAuth";
|
||||
import { ProjectProvider } from "./hooks/useProject";
|
||||
@@ -22,11 +18,6 @@ const queryClient: QueryClient = new QueryClient({
|
||||
},
|
||||
});
|
||||
|
||||
const asyncStoragePersister: Persister = createAsyncStoragePersister({
|
||||
storage: AsyncStorage,
|
||||
throttleTime: 1000,
|
||||
});
|
||||
|
||||
function AppContent(): React.JSX.Element {
|
||||
const { theme } = useTheme();
|
||||
|
||||
@@ -73,10 +64,7 @@ function AppContent(): React.JSX.Element {
|
||||
export default function App(): React.JSX.Element {
|
||||
return (
|
||||
<SafeAreaProvider>
|
||||
<PersistQueryClientProvider
|
||||
client={queryClient}
|
||||
persistOptions={{ persister: asyncStoragePersister }}
|
||||
>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<ThemeProvider>
|
||||
<AuthProvider>
|
||||
<ProjectProvider>
|
||||
@@ -84,7 +72,7 @@ export default function App(): React.JSX.Element {
|
||||
</ProjectProvider>
|
||||
</AuthProvider>
|
||||
</ThemeProvider>
|
||||
</PersistQueryClientProvider>
|
||||
</QueryClientProvider>
|
||||
</SafeAreaProvider>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,14 @@ const prefix: string = Linking.createURL("/");
|
||||
|
||||
const linking: React.ComponentProps<typeof NavigationContainer>["linking"] = {
|
||||
prefixes: [prefix, "oneuptime://"],
|
||||
// Disable automatic deep link URL resolution via NavigationContainer.
|
||||
// On Android with React Native's new architecture (Fabric), the async
|
||||
// getInitialURL resolution inside NavigationContainer's useLinking hook
|
||||
// sets state inside a microtask callback which never triggers a re-render,
|
||||
// causing screens to never appear (blank screen after loading).
|
||||
// Deep link navigation from push notifications is handled separately in
|
||||
// usePushNotifications via Notifications.getLastNotificationResponseAsync().
|
||||
enabled: false,
|
||||
config: {
|
||||
screens: {
|
||||
Home: "home",
|
||||
@@ -52,34 +60,15 @@ export default function RootNavigator(): React.JSX.Element {
|
||||
const biometric: ReturnType<typeof useBiometric> = useBiometric();
|
||||
|
||||
const [biometricPassed, setBiometricPassed] = useState(false);
|
||||
const [biometricChecked, setBiometricChecked] = useState(false);
|
||||
|
||||
usePushNotifications(navigationRef);
|
||||
|
||||
// Hide the native splash screen once initial loading completes
|
||||
useEffect(() => {
|
||||
if (!isLoading && biometricChecked) {
|
||||
if (!isLoading) {
|
||||
SplashScreen.hideAsync();
|
||||
}
|
||||
}, [isLoading, biometricChecked]);
|
||||
|
||||
// Check biometric on app launch
|
||||
useEffect(() => {
|
||||
const checkBiometric: () => Promise<void> = async (): Promise<void> => {
|
||||
if (!isAuthenticated || !biometric.isEnabled) {
|
||||
setBiometricPassed(true);
|
||||
setBiometricChecked(true);
|
||||
return;
|
||||
}
|
||||
|
||||
setBiometricChecked(true);
|
||||
// Don't auto-pass — show lock screen
|
||||
};
|
||||
|
||||
if (!isLoading) {
|
||||
checkBiometric();
|
||||
}
|
||||
}, [isAuthenticated, isLoading, biometric.isEnabled]);
|
||||
}, [isLoading]);
|
||||
|
||||
const navigationTheme: Theme = {
|
||||
...DefaultTheme,
|
||||
@@ -96,10 +85,9 @@ export default function RootNavigator(): React.JSX.Element {
|
||||
fonts: DefaultTheme.fonts,
|
||||
};
|
||||
|
||||
if (isLoading || !biometricChecked) {
|
||||
if (isLoading) {
|
||||
return (
|
||||
<View
|
||||
className="flex-1 items-center justify-center bg-bg-primary"
|
||||
style={{
|
||||
flex: 1,
|
||||
alignItems: "center",
|
||||
|
||||
Reference in New Issue
Block a user