Skip to content

armgit / papra

Public Imported from GitHub
0

The minimalistic document archiving platform.

fix(mobile): prevent layout shift in server selection screen (#1332)

Corentin Thomasset4f754e1f9f30
diff --git a/apps/mobile/src/modules/config/screens/server-selection.screen.tsx b/apps/mobile/src/modules/config/screens/server-selection.screen.tsx
index 6f41146e..ae5b16b2 100644
--- a/apps/mobile/src/modules/config/screens/server-selection.screen.tsx
+++ b/apps/mobile/src/modules/config/screens/server-selection.screen.tsx
@@ -13,7 +13,9 @@ import {
TouchableOpacity,
View,
} from 'react-native';
+import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { queryClient } from '@/modules/api/providers/query.provider';
+import { Icon } from '@/modules/ui/components/icon';
import { useAlert } from '@/modules/ui/providers/alert-provider';
import { useThemeColor } from '@/modules/ui/providers/use-theme-color';
import { MANAGED_SERVER_URL } from '../config.constants';
@@ -34,13 +36,19 @@ export function ServerSelectionScreen() {
const router = useRouter();
const themeColors = useThemeColor();
const { showAlert } = useAlert();
+ const insets = useSafeAreaInsets();
const styles = createStyles({ themeColors });
const [selectedOption, setSelectedOption] = useState<'managed' | 'self-hosted'>('managed');
const [customUrl, setCustomUrl] = useState(getDefaultCustomServerUrl());
const [isValidating, setIsValidating] = useState(false);
- const handleValidateCustomUrl = async ({ url: rawUrl }: { url: string }) => {
+ const isSelfHosted = selectedOption === 'self-hosted';
+ const canContinue = !isValidating && (!isSelfHosted || customUrl.trim() !== '');
+
+ const handleContinue = async () => {
+ const rawUrl = isSelfHosted ? customUrl : MANAGED_SERVER_URL;
+
setIsValidating(true);
const [url, urlValidationError] = safelySync(() => validateServerUrl({ url: rawUrl }));
@@ -57,14 +65,24 @@ export function ServerSelectionScreen() {
try {
await pingServer({ url });
+ } catch {
+ showAlert({
+ title: 'Connection Failed',
+ message: 'Could not reach the server.',
+ });
+ setIsValidating(false);
+ return;
+ }
+
+ try {
await configLocalStorage.setApiServerBaseUrl({ apiServerBaseUrl: url });
await queryClient.invalidateQueries({ queryKey: ['api-server-url'] });
router.replace('/auth/login');
} catch {
showAlert({
- title: 'Connection Failed',
- message: 'Could not reach the server.',
+ title: 'Something Went Wrong',
+ message: 'Could not save the server configuration. Please try again.',
});
} finally {
setIsValidating(false);
@@ -73,80 +91,89 @@ export function ServerSelectionScreen() {
return (
<KeyboardAvoidingView
- style={styles.container}
+ style={[styles.container, { paddingTop: insets.top }]}
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
>
<ScrollView contentContainerStyle={styles.scrollContent} keyboardShouldPersistTaps="handled">
- <View style={styles.header}>
- <Text style={styles.title}>Welcome to Papra</Text>
- <Text style={styles.subtitle}>Choose your server</Text>
+ <View style={styles.brandRow}>
+ <Icon name="file-text" size={28} color={themeColors.primary} />
+ <Text style={styles.brandName}>Papra</Text>
</View>
+ <Text style={styles.title}>Organize, secure &{'\n'}archive your documents.</Text>
+ <Text style={styles.subtitle}>First, choose where your documents live.</Text>
+
<View style={styles.options}>
<TouchableOpacity
style={[styles.optionCard, selectedOption === 'managed' && styles.optionCardSelected]}
onPress={() => setSelectedOption('managed')}
disabled={isValidating}
+ accessibilityRole="radio"
+ accessibilityState={{ checked: selectedOption === 'managed', disabled: isValidating }}
>
- <Text style={styles.optionTitle}>Managed Cloud</Text>
- <Text style={styles.optionDescription}>Use the official Papra cloud service</Text>
+ <Icon name="cloud" size={22} color={themeColors.foreground} style={styles.optionIcon} />
+ <View style={styles.optionContent}>
+ <Text style={styles.optionTitle}>Managed Cloud</Text>
+ <Text style={styles.optionDescription}>Use the official Papra cloud service</Text>
+ </View>
</TouchableOpacity>
<TouchableOpacity
- style={[
- styles.optionCard,
- selectedOption === 'self-hosted' && styles.optionCardSelected,
- ]}
+ style={[styles.optionCard, isSelfHosted && styles.optionCardSelected]}
onPress={() => setSelectedOption('self-hosted')}
disabled={isValidating}
+ accessibilityRole="radio"
+ accessibilityState={{ checked: isSelfHosted, disabled: isValidating }}
>
- <Text style={styles.optionTitle}>Self-Hosted</Text>
- <Text style={styles.optionDescription}>Connect to your own Papra server</Text>
+ <Icon
+ name="server"
+ size={22}
+ color={themeColors.foreground}
+ style={styles.optionIcon}
+ />
+ <View style={styles.optionContent}>
+ <Text style={styles.optionTitle}>Self-Hosted</Text>
+ <Text style={styles.optionDescription}>Connect to your own Papra server</Text>
+ </View>
</TouchableOpacity>
</View>
- {selectedOption === 'managed' && (
- <TouchableOpacity
- style={[styles.button, isValidating && styles.buttonDisabled]}
- onPress={async () => handleValidateCustomUrl({ url: MANAGED_SERVER_URL })}
- disabled={isValidating}
- >
- {isValidating ? (
- <ActivityIndicator color={themeColors.primaryForeground} />
- ) : (
- <Text style={styles.buttonText}>Continue with Managed</Text>
- )}
- </TouchableOpacity>
- )}
-
- {selectedOption === 'self-hosted' && (
- <View style={styles.customUrlContainer}>
- <Text style={styles.inputLabel}>Server URL</Text>
- <TextInput
- style={styles.input}
- placeholder="https://your-server.com"
- placeholderTextColor={themeColors.mutedForeground}
- value={customUrl}
- onChangeText={setCustomUrl}
- autoCapitalize="none"
- autoCorrect={false}
- keyboardType="url"
- editable={!isValidating}
- />
- <TouchableOpacity
- style={[styles.button, isValidating && styles.buttonDisabled]}
- onPress={async () => handleValidateCustomUrl({ url: customUrl })}
- disabled={isValidating}
- >
- {isValidating ? (
- <ActivityIndicator color={themeColors.primaryForeground} />
- ) : (
- <Text style={styles.buttonText}>Connect</Text>
- )}
- </TouchableOpacity>
- </View>
- )}
+ <View style={styles.customUrlZone}>
+ {isSelfHosted && (
+ <>
+ <Text style={styles.inputLabel}>Server URL</Text>
+ <TextInput
+ style={styles.input}
+ placeholder="https://your-server.com"
+ placeholderTextColor={themeColors.mutedForeground}
+ value={customUrl}
+ onChangeText={setCustomUrl}
+ autoCapitalize="none"
+ autoCorrect={false}
+ keyboardType="url"
+ editable={!isValidating}
+ />
+ </>
+ )}
+ </View>
</ScrollView>
+
+ <View style={[styles.footer, { paddingBottom: Math.max(insets.bottom, 16) }]}>
+ <TouchableOpacity
+ style={[styles.button, !canContinue && styles.buttonDisabled]}
+ onPress={handleContinue}
+ disabled={!canContinue}
+ >
+ {isValidating ? (
+ <ActivityIndicator color={themeColors.primaryForeground} />
+ ) : (
+ <>
+ <Text style={styles.buttonText}>Continue</Text>
+ <Icon name="arrow-right" size={18} color={themeColors.primaryForeground} />
+ </>
+ )}
+ </TouchableOpacity>
+ </View>
</KeyboardAvoidingView>
);
}
@@ -158,19 +185,26 @@ function createStyles({ themeColors }: { themeColors: ThemeColors }) {
backgroundColor: themeColors.background,
},
scrollContent: {
- flexGrow: 1,
padding: 24,
- justifyContent: 'center',
+ paddingTop: 32,
},
- header: {
- marginBottom: 40,
+ brandRow: {
+ flexDirection: 'row',
alignItems: 'center',
+ gap: 10,
+ marginBottom: 48,
+ },
+ brandName: {
+ fontSize: 24,
+ fontWeight: 'bold',
+ color: themeColors.foreground,
},
title: {
- fontSize: 32,
+ fontSize: 28,
fontWeight: 'bold',
+ lineHeight: 36,
color: themeColors.foreground,
- marginBottom: 8,
+ marginBottom: 12,
},
subtitle: {
fontSize: 16,
@@ -178,9 +212,12 @@ function createStyles({ themeColors }: { themeColors: ThemeColors }) {
},
options: {
gap: 16,
- marginBottom: 24,
+ marginBottom: 32,
+ marginTop: 48,
},
optionCard: {
+ flexDirection: 'row',
+ alignItems: 'center',
paddingHorizontal: 20,
paddingVertical: 14,
borderRadius: 12,
@@ -191,24 +228,29 @@ function createStyles({ themeColors }: { themeColors: ThemeColors }) {
optionCardSelected: {
borderColor: themeColors.primary,
},
+ optionIcon: {
+ marginRight: 16,
+ },
+ optionContent: {
+ flex: 1,
+ },
optionTitle: {
fontSize: 18,
fontWeight: '600',
color: themeColors.foreground,
- margin: 0,
},
optionDescription: {
fontSize: 14,
color: themeColors.mutedForeground,
},
- customUrlContainer: {
- gap: 12,
+ customUrlZone: {
+ minHeight: 88,
+ gap: 8,
},
inputLabel: {
fontSize: 14,
fontWeight: '600',
- color: themeColors.foreground,
- marginBottom: 4,
+ color: themeColors.mutedForeground,
},
input: {
height: 50,
@@ -220,8 +262,14 @@ function createStyles({ themeColors }: { themeColors: ThemeColors }) {
color: themeColors.foreground,
backgroundColor: themeColors.secondaryBackground,
},
+ footer: {
+ paddingHorizontal: 24,
+ paddingTop: 12,
+ },
button: {
height: 50,
+ flexDirection: 'row',
+ gap: 8,
backgroundColor: themeColors.primary,
borderRadius: 8,
justifyContent: 'center',