Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146import React from 'react';import { View, Text, Pressable, StyleSheet, KeyboardAvoidingView, ScrollView, Platform,} from 'react-native';import { SafeAreaView } from 'react-native-safe-area-context';import Constants from 'expo-constants';import { ArrowLeft, X } from '../../components/icons';import { spacing, type Typography, componentSizes, type ThemePalette } from '../../theme/tokens';import { useTypography } from '../../theme/dynamic';import { useColors } from '../../theme/colors';import ComailBackdrop from '../../components/ComailBackdrop';import type { Rect } from '../../lib/comail-particles';import { useLocaleStore } from '../../stores/locale-store';
const APP_VERSION = Constants.expoConfig?.version ?? '0.0.0';
interface LoginShellProps { children: React.ReactNode; /** Renders a back chevron. Omit on the first step of the flow. */ onBack?: () => void; /** Renders a close X on the right — add-account mode only. */ onClose?: () => void; showFooter?: boolean; ambient?: boolean; quietRects?: Rect[]; scrollEnabled?: boolean; centerContent?: boolean;}
/** * Shared chrome for every sign-in step: safe area, keyboard avoidance, the * back/close affordances, and the version footer. Steps supply only their own * content so they all sit on the same grid. */export default function LoginShell({ children, onBack, onClose, showFooter = false, ambient = false, quietRects, scrollEnabled = true, centerContent = false,}: LoginShellProps) { const c = useColors(); const typography = useTypography(); const styles = React.useMemo(() => makeStyles(c, typography), [c, typography]); const t = useLocaleStore((s) => s.t); const [content, setContent] = React.useState({ x: 0, y: 0 }); const headerHeight = onBack || onClose ? componentSizes.headerHeight : 0; const regions = React.useMemo(() => quietRects?.map(rect => ({ ...rect, x: rect.x + content.x, y: rect.y + content.y + headerHeight, })), [quietRects, content, headerHeight]);
const body = ( <KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} style={styles.flex} > {headerHeight > 0 && <View style={styles.header}> {onBack ? ( <Pressable onPress={onBack} hitSlop={12} style={styles.headerButton} accessibilityRole="button" accessibilityLabel={t('common.back', 'Back')} > <ArrowLeft size={22} color={c.textSecondary} /> </Pressable> ) : ( <View style={styles.headerButton} /> )} {onClose ? ( <Pressable onPress={onClose} hitSlop={12} style={styles.headerButton} accessibilityRole="button" accessibilityLabel={t('common.close', 'Close')} > <X size={22} color={c.textSecondary} /> </Pressable> ) : ( <View style={styles.headerButton} /> )} </View>}
<ScrollView style={styles.flex} keyboardShouldPersistTaps="handled" scrollEnabled={scrollEnabled} bounces={scrollEnabled} contentContainerStyle={[styles.content, centerContent && styles.centeredContent]}> <View onLayout={event => { const { x, y } = event.nativeEvent.layout; setContent(previous => previous.x === x && previous.y === y ? previous : { x, y }); }}> {children} </View> </ScrollView>
{showFooter ? ( <View style={styles.footer}> <Text style={styles.footerText}>Comail v{APP_VERSION}</Text> </View> ) : null} </KeyboardAvoidingView> ); return ( <SafeAreaView style={styles.container}> {ambient ? <ComailBackdrop quietRects={regions}>{body}</ComailBackdrop> : body} </SafeAreaView> );}
function makeStyles(c: ThemePalette, typography: Typography) { return StyleSheet.create({ container: { flex: 1, backgroundColor: c.background }, flex: { flex: 1 }, header: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingHorizontal: spacing.lg, height: componentSizes.headerHeight, }, headerButton: { width: componentSizes.buttonLg, height: componentSizes.buttonLg, alignItems: 'center', justifyContent: 'center' }, // One readable column, centred on a tablet or a phone in landscape. content: { flexGrow: 1, width: '100%', maxWidth: 480 + spacing.lg * 2, alignSelf: 'center', paddingHorizontal: spacing.lg, paddingTop: spacing.lg, paddingBottom: spacing.xxxl, }, centeredContent: { justifyContent: 'center', paddingVertical: spacing.lg }, footer: { alignItems: 'center', paddingBottom: spacing.lg, gap: spacing.xs }, footerText: { ...typography.caption, color: c.textMuted }, });}