Skip to content

Commit 9053dda

Browse files
committed
fix(mobile): prevent auth screen flash and improve filter performance
- Add splash screen control to prevent flash of sign-in/master password screens on app launch for already authenticated users - Fix Sheet filter to use content-based detection (isWorkbookContent) - Update Note filter to exclude sheets from regular notes - Optimize FilterSortSheet with memoized components and useCallback - Replace TouchableOpacity with Pressable for faster filter toggles
1 parent 5d3e6eb commit 9053dda

File tree

3 files changed

+143
-162
lines changed

3 files changed

+143
-162
lines changed

apps/mobile/v1/src/components/AppWrapper.tsx

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useAuth, useUser } from '@clerk/clerk-expo';
2-
import React, { useEffect, useRef,useState } from 'react';
3-
import { ActivityIndicator,View } from 'react-native';
2+
import * as SplashScreen from 'expo-splash-screen';
3+
import React, { useEffect, useRef, useState } from 'react';
4+
import { ActivityIndicator, View } from 'react-native';
45

56
import { useMasterPassword } from '../hooks/useMasterPassword';
67
import { logger } from '../lib/logger';
@@ -31,6 +32,7 @@ export const AppWrapper: React.FC<AppWrapperProps> = ({ children }) => {
3132
const [showLoading, setShowLoading] = useState(false);
3233
const lastUserIdRef = useRef<string | undefined>(undefined);
3334
const [userChanging, setUserChanging] = useState(false);
35+
const splashHiddenRef = useRef(false);
3436

3537
// Automatically sync pending mutations when device comes back online
3638
useSyncOnReconnect();
@@ -59,6 +61,25 @@ export const AppWrapper: React.FC<AppWrapperProps> = ({ children }) => {
5961
}
6062
}, [userChanging, isChecking]);
6163

64+
// Hide splash screen when auth state is fully determined
65+
// This prevents the flash of sign-in/master password screens
66+
useEffect(() => {
67+
// Don't hide splash until we know exactly what screen to show:
68+
// 1. Clerk must be loaded
69+
// 2. If not signed in - show auth screen (hide splash)
70+
// 3. If signed in - must wait for master password check to complete
71+
const clerkReady = isLoaded;
72+
const notSignedIn = clerkReady && !isSignedIn;
73+
const signedInAndReady = clerkReady && isSignedIn && userLoaded && !isChecking;
74+
75+
const shouldHideSplash = notSignedIn || signedInAndReady;
76+
77+
if (shouldHideSplash && !splashHiddenRef.current) {
78+
splashHiddenRef.current = true;
79+
SplashScreen.hideAsync();
80+
}
81+
}, [isLoaded, isSignedIn, userLoaded, isChecking]);
82+
6283
// Simple logic: show loading only for initial Clerk loading, nothing else
6384
const isLoading = !isLoaded || (isSignedIn && !userLoaded) || (isSignedIn && userLoaded && !user);
6485

@@ -127,9 +148,11 @@ export const AppWrapper: React.FC<AppWrapperProps> = ({ children }) => {
127148
}
128149

129150
// User is signed in - check master password state
130-
// IMPORTANT: If we're checking OR need unlock OR user just changed, show master password screen
131-
// This prevents notes from loading prematurely
132-
if (needsUnlock || isChecking || userChanging) {
151+
// Show master password screen if:
152+
// 1. Still checking (isChecking) - we don't know the state yet
153+
// 2. Needs unlock (needsUnlock) - user must enter password
154+
// Note: Don't show just for userChanging - if user is already unlocked, go straight to app
155+
if (isChecking || needsUnlock) {
133156
return (
134157
<MasterPasswordScreen
135158
key={userId} // Force remount when userId changes to reset all state

0 commit comments

Comments
 (0)