Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add skeleton loading animations (#771)

Leendert de Borste11c647f5048
diff --git a/apps/mobile-app/app/(tabs)/credentials/index.tsx b/apps/mobile-app/app/(tabs)/credentials/index.tsx
index 6efbc011a..195507549 100644
--- a/apps/mobile-app/app/(tabs)/credentials/index.tsx
+++ b/apps/mobile-app/app/(tabs)/credentials/index.tsx
@@ -1,4 +1,4 @@
-import { StyleSheet, Text, FlatList, ActivityIndicator, TouchableOpacity, TextInput, RefreshControl, Platform, Animated } from 'react-native';
+import { StyleSheet, Text, FlatList, TouchableOpacity, TextInput, RefreshControl, Platform, Animated, View } from 'react-native';
import { useState, useEffect, useCallback, useRef } from 'react';
import { useNavigation } from '@react-navigation/native';
import { useRouter } from 'expo-router';
@@ -16,7 +16,9 @@ import { useColors } from '@/hooks/useColorScheme';
import { CredentialCard } from '@/components/credentials/CredentialCard';
import { TitleContainer } from '@/components/ui/TitleContainer';
import { CollapsibleHeader } from '@/components/ui/CollapsibleHeader';
+import { SkeletonLoader } from '@/components/ui/SkeletonLoader';
import emitter from '@/utils/EventEmitter';
+import { useMinDurationLoading } from '@/hooks/useMinDurationLoading';
/**
* Credentials screen.
@@ -32,7 +34,7 @@ export default function CredentialsScreen() : React.ReactNode {
const [isTabFocused, setIsTabFocused] = useState(false);
const router = useRouter();
const [credentialsList, setCredentialsList] = useState<Credential[]>([]);
- const [isLoadingCredentials, setIsLoadingCredentials] = useState(false);
+ const [isLoadingCredentials, setIsLoadingCredentials] = useMinDurationLoading(false, 300);
const authContext = useAuth();
const dbContext = useDb();
@@ -47,6 +49,7 @@ export default function CredentialsScreen() : React.ReactNode {
try {
const credentials = await dbContext.sqliteClient!.getAllCredentials();
setCredentialsList(credentials);
+ setIsLoadingCredentials(false);
} catch (err) {
// Error loading credentials, show error toast
Toast.show({
@@ -54,8 +57,9 @@ export default function CredentialsScreen() : React.ReactNode {
text1: 'Error loading credentials',
text2: err instanceof Error ? err.message : 'Unknown error',
});
+ setIsLoadingCredentials(false);
}
- }, [dbContext.sqliteClient]);
+ }, [dbContext.sqliteClient, setIsLoadingCredentials]);
const headerButtons = [{
icon: 'add' as const,
@@ -101,9 +105,6 @@ export default function CredentialsScreen() : React.ReactNode {
setRefreshing(true);
try {
- // Record start time
- const startTime = Date.now();
-
// Sync vault and load credentials
await syncVault({
/**
@@ -111,15 +112,9 @@ export default function CredentialsScreen() : React.ReactNode {
*/
onSuccess: async (hasNewVault) => {
// Calculate remaining time needed to reach minimum duration
- const elapsedTime = Date.now() - startTime;
- const remainingDelay = Math.max(0, 350 - elapsedTime);
-
- // Only delay if needed to reach minimum duration
- if (remainingDelay > 0) {
- await new Promise(resolve => setTimeout(resolve, remainingDelay));
- }
-
+ setIsLoadingCredentials(true);
await loadCredentials();
+ setIsLoadingCredentials(false);
setRefreshing(false);
Toast.show({
type: 'success',
@@ -150,7 +145,7 @@ export default function CredentialsScreen() : React.ReactNode {
text2: err instanceof Error ? err.message : 'Unknown error',
});
}
- }, [syncVault, loadCredentials]);
+ }, [syncVault, loadCredentials, setIsLoadingCredentials]);
useEffect(() => {
if (!isAuthenticated || !isDatabaseAvailable) {
@@ -159,8 +154,7 @@ export default function CredentialsScreen() : React.ReactNode {
setIsLoadingCredentials(true);
loadCredentials();
- setIsLoadingCredentials(false);
- }, [isAuthenticated, isDatabaseAvailable, loadCredentials]);
+ }, [isAuthenticated, isDatabaseAvailable, loadCredentials, setIsLoadingCredentials]);
const filteredCredentials = credentialsList.filter(credential => {
const searchLower = searchQuery.toLowerCase();
@@ -209,8 +203,7 @@ export default function CredentialsScreen() : React.ReactNode {
searchIcon: {
left: 12,
position: 'absolute',
- top: '50%',
- transform: [{ translateY: -17 }],
+ top: 11,
zIndex: 1,
},
searchInput: {
@@ -218,6 +211,7 @@ export default function CredentialsScreen() : React.ReactNode {
borderRadius: 8,
color: colors.text,
fontSize: 16,
+ height: 40,
marginBottom: 16,
padding: 12,
paddingLeft: 40,
@@ -242,7 +236,10 @@ export default function CredentialsScreen() : React.ReactNode {
<ThemedView style={styles.content}>
<ThemedView style={styles.stepContainer}>
{isLoadingCredentials ? (
- <ActivityIndicator size="large" color={colors.primary} />
+ <View style={styles.contentContainer}>
+ <TitleContainer title="Credentials" />
+ <SkeletonLoader count={4} height={60} parts={2} />
+ </View>
) : (
<Animated.FlatList
ref={flatListRef}
@@ -295,9 +292,7 @@ export default function CredentialsScreen() : React.ReactNode {
tintColor={colors.primary}
/>
}
- renderItem={({ item }) => (
- <CredentialCard credential={item} />
- )}
+ renderItem={({ item }) => <CredentialCard credential={item} />}
ListEmptyComponent={
<Text style={styles.emptyText}>
{searchQuery ? 'No matching credentials found' : 'No credentials found'}
diff --git a/apps/mobile-app/app/(tabs)/emails/index.tsx b/apps/mobile-app/app/(tabs)/emails/index.tsx
index f0468c1e7..d2c154d7d 100644
--- a/apps/mobile-app/app/(tabs)/emails/index.tsx
+++ b/apps/mobile-app/app/(tabs)/emails/index.tsx
@@ -1,5 +1,5 @@
import React, { useEffect, useState, useCallback, useRef } from 'react';
-import { StyleSheet, View, ActivityIndicator, ScrollView, RefreshControl, Animated } from 'react-native';
+import { StyleSheet, View, ScrollView, RefreshControl, Animated } from 'react-native';
import { useNavigation } from 'expo-router';
import { MailboxEmail } from '@/utils/types/webapi/MailboxEmail';
@@ -14,42 +14,9 @@ import { useColors } from '@/hooks/useColorScheme';
import { ThemedView } from '@/components/themed/ThemedView';
import { ThemedSafeAreaView } from '@/components/themed/ThemedSafeAreaView';
import { EmailCard } from '@/components/EmailCard';
+import { SkeletonLoader } from '@/components/ui/SkeletonLoader';
import emitter from '@/utils/EventEmitter';
-
-/**
- * Hook for minimum duration loading state.
- */
-const useMinDurationLoading = (
- initialState: boolean,
- minDuration: number
-): [boolean, (newState: boolean) => void] => {
- const [state, setState] = useState(initialState);
- const timerRef = useRef<NodeJS.Timeout | null>(null);
-
- const setStateWithMinDuration = useCallback(
- (newState: boolean) => {
- if (newState) {
- setState(true);
- } else {
- if (timerRef.current) {
- clearTimeout(timerRef.current);
- }
- timerRef.current = setTimeout(() => setState(false), minDuration);
- }
- },
- [minDuration] // ✅ No dependency on timerRef, it won't change
- );
-
- useEffect(() => {
- return () : void => {
- if (timerRef.current) {
- clearTimeout(timerRef.current);
- }
- };
- }, []);
-
- return [state, setStateWithMinDuration];
-};
+import { useMinDurationLoading } from '@/hooks/useMinDurationLoading';
/**
* Emails screen.
@@ -63,7 +30,7 @@ export default function EmailsScreen() : React.ReactNode {
const scrollViewRef = useRef<ScrollView>(null);
const [error, setError] = useState<string | null>(null);
const [emails, setEmails] = useState<MailboxEmail[]>([]);
- const [isLoading, setIsLoading] = useMinDurationLoading(true, 100);
+ const [isLoading, setIsLoading] = useMinDurationLoading(true, 300);
const [isRefreshing, setIsRefreshing] = useState(false);
const [isTabFocused, setIsTabFocused] = useState(false);
@@ -148,10 +115,12 @@ export default function EmailsScreen() : React.ReactNode {
* Refresh the emails on pull to refresh.
*/
const onRefresh = useCallback(async () : Promise<void> => {
+ setIsLoading(true);
setIsRefreshing(true);
await loadEmails();
setIsRefreshing(false);
- }, [loadEmails]);
+ setIsLoading(false);
+ }, [loadEmails, setIsLoading]);
const styles = StyleSheet.create({
centerContainer: {
@@ -188,8 +157,8 @@ export default function EmailsScreen() : React.ReactNode {
const renderContent = () : React.ReactNode => {
if (isLoading) {
return (
- <View style={styles.centerContainer}>
- <ActivityIndicator size="large" />
+ <View style={styles.container}>
+ <SkeletonLoader count={4} height={90} parts={3} />
</View>
);
}
diff --git a/apps/mobile-app/app/_layout.tsx b/apps/mobile-app/app/_layout.tsx
index 61b205ce6..1b623c621 100644
--- a/apps/mobile-app/app/_layout.tsx
+++ b/apps/mobile-app/app/_layout.tsx
@@ -82,9 +82,9 @@ function RootLayoutNav() : React.ReactNode {
setStatus('Unlocking vault');
const isUnlocked = await dbContext.unlockVault();
if (isUnlocked) {
- await new Promise(resolve => setTimeout(resolve, 1000));
+ await new Promise(resolve => setTimeout(resolve, 750));
setStatus('Decrypting vault');
- await new Promise(resolve => setTimeout(resolve, 1000));
+ await new Promise(resolve => setTimeout(resolve, 750));
// The vault is successfully unlocked, so we let the native code handle the default routing.
setBootComplete(true);
diff --git a/apps/mobile-app/components/ui/SkeletonLoader.tsx b/apps/mobile-app/components/ui/SkeletonLoader.tsx
new file mode 100644
index 000000000..8e7838c18
--- /dev/null
+++ b/apps/mobile-app/components/ui/SkeletonLoader.tsx
@@ -0,0 +1,110 @@
+import { StyleSheet, View, Animated, ViewStyle } from 'react-native';
+import { useEffect, useRef } from 'react';
+import { LinearGradient } from 'expo-linear-gradient';
+
+import { useColors } from '@/hooks/useColorScheme';
+
+interface ISkeletonLoaderProps {
+ /** Number of skeleton items to render */
+ count?: number;
+ /** Height of each skeleton item */
+ height?: number;
+ /** Number of parts (lines) in each skeleton item */
+ parts?: number;
+ /** Additional styles to apply to the skeleton item */
+ style?: ViewStyle;
+}
+
+/**
+ * A reusable skeleton loader component that displays animated loading placeholders.
+ * @param props - The component props
+ * @returns A React node containing the skeleton loader
+ */
+export const SkeletonLoader = ({
+ count = 1,
+ height = 60,
+ parts = 2,
+ style,
+}: ISkeletonLoaderProps): React.ReactNode => {
+ const colors = useColors();
+ const animatedValue = useRef(new Animated.Value(0)).current;
+
+ useEffect(() => {
+ Animated.loop(
+ Animated.sequence([
+ Animated.timing(animatedValue, {
+ toValue: 1,
+ duration: 1000,
+ useNativeDriver: true,
+ }),
+ Animated.timing(animatedValue, {
+ toValue: 0,
+ duration: 1000,
+ useNativeDriver: true,
+ }),
+ ])
+ ).start();
+ }, [animatedValue]);
+
+ const translateX = animatedValue.interpolate({
+ inputRange: [0, 1],
+ outputRange: [-100, 100],
+ });
+
+ const skeletonStyles = StyleSheet.create({
+ card: {
+ backgroundColor: colors.accentBackground,
+ borderRadius: 12,
+ height,
+ marginBottom: 12,
+ overflow: 'hidden',
+ },
+ content: {
+ gap: 8,
+ padding: 16,
+ },
+ part: {
+ backgroundColor: colors.accentBorder,
+ borderRadius: 4,
+ height: 12,
+ width: `${100 / parts}%`,
+ },
+ });
+
+ /**
+ * Renders a single skeleton item with the specified number of parts
+ * @returns A React node containing a single skeleton item
+ */
+ const renderSkeletonItem = (): React.ReactNode => (
+ <View style={[skeletonStyles.card, style]}>
+ <Animated.View
+ style={[
+ StyleSheet.absoluteFill,
+ {
+ transform: [{ translateX }],
+ },
+ ]}
+ >
+ <LinearGradient
+ colors={['transparent', colors.accentBorder, 'transparent']}
+ start={{ x: 0, y: 0 }}
+ end={{ x: 1, y: 0 }}
+ style={StyleSheet.absoluteFill}
+ />
+ </Animated.View>
+ <View style={skeletonStyles.content}>
+ {Array.from({ length: parts }).map((_, index) => (
+ <View key={index} style={skeletonStyles.part} />
+ ))}
+ </View>
+ </View>
+ );
+
+ return (
+ <>
+ {Array.from({ length: count }).map((_, index) => (
+ <View key={index}>{renderSkeletonItem()}</View>
+ ))}
+ </>
+ );
+};
\ No newline at end of file
diff --git a/apps/mobile-app/hooks/useMinDurationLoading.ts b/apps/mobile-app/hooks/useMinDurationLoading.ts
new file mode 100644
index 000000000..8d4ac01dd
--- /dev/null
+++ b/apps/mobile-app/hooks/useMinDurationLoading.ts
@@ -0,0 +1,40 @@
+import { useState, useCallback, useRef, useEffect } from 'react';
+
+/**
+ * Hook for minimum duration loading state.
+ * Ensures loading state stays active for at least the specified duration.
+ * @param initialState - Initial loading state
+ * @param minDuration - Minimum duration in milliseconds
+ * @returns [loadingState, setLoadingState] - Loading state and setter function
+ */
+export const useMinDurationLoading = (
+ initialState: boolean,
+ minDuration: number
+): [boolean, (newState: boolean) => void] => {
+ const [state, setState] = useState(initialState);
+ const timerRef = useRef<NodeJS.Timeout | null>(null);
+
+ const setStateWithMinDuration = useCallback(
+ (newState: boolean) => {
+ if (newState) {
+ setState(true);
+ } else {
+ if (timerRef.current) {
+ clearTimeout(timerRef.current);
+ }
+ timerRef.current = setTimeout(() => setState(false), minDuration);
+ }
+ },
+ [minDuration]
+ );
+
+ useEffect(() => {
+ return () : void => {
+ if (timerRef.current) {
+ clearTimeout(timerRef.current);
+ }
+ };
+ }, []);
+
+ return [state, setStateWithMinDuration];
+};
\ No newline at end of file