import React from 'react'; import { View, Text, StyleSheet, ScrollView, Pressable, Modal, Animated, Easing, } from 'react-native'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { X, Check, Mail } from './icons'; import { spacing, radius, typography, type ThemePalette } from '../theme/tokens'; import { useColors } from '../theme/colors'; import { useSheetDrag } from '../lib/use-sheet-drag'; import type { Identity } from '../api/types'; import { useLocaleStore } from '../stores/locale-store'; import { MODAL_ORIENTATIONS } from '../lib/modal-orientations'; import { useSheetInsets } from '../lib/use-layout'; interface IdentitySheetProps { visible: boolean; onClose: () => void; identities: Identity[]; selectedIdentityId: string | null; onPick: (identity: Identity) => void; } export function IdentitySheet({ visible, onClose, identities, selectedIdentityId, onPick, }: IdentitySheetProps) { const c = useColors(); const styles = React.useMemo(() => makeStyles(c), [c]); const insets = useSafeAreaInsets(); const slideY = React.useRef(new Animated.Value(500)).current; // Centred on a wide window, clear of side insets in landscape. const sheetInsets = useSheetInsets(); const overlayOpacity = React.useRef(new Animated.Value(0)).current; const dragHandlers = useSheetDrag({ slideY, closedY: 500, onClose }); const { t } = useLocaleStore(); React.useEffect(() => { if (visible) { Animated.parallel([ Animated.timing(slideY, { toValue: 0, duration: 220, easing: Easing.out(Easing.cubic), useNativeDriver: true }), Animated.timing(overlayOpacity, { toValue: 1, duration: 220, useNativeDriver: true }), ]).start(); } else { Animated.parallel([ Animated.timing(slideY, { toValue: 500, duration: 180, easing: Easing.in(Easing.cubic), useNativeDriver: true }), Animated.timing(overlayOpacity, { toValue: 0, duration: 180, useNativeDriver: true }), ]).start(); } }, [visible, slideY, overlayOpacity]); return ( {t('email_composer.from', 'From')} {identities.map((identity) => { const isSelected = identity.id === selectedIdentityId; return ( { onPick(identity); onClose(); }} style={({ pressed }) => [ styles.identityRow, pressed && styles.identityRowPressed, ]} > {!!identity.name && ( {identity.name} )} {identity.email} {isSelected && ( )} ); })} ); } function makeStyles(c: ThemePalette) { return StyleSheet.create({ sheetOverlay: { ...StyleSheet.absoluteFillObject, backgroundColor: 'rgba(0,0,0,0.5)', }, sheetOverlayPress: { flex: 1 }, sheet: { position: 'absolute', left: 0, right: 0, bottom: 0, maxHeight: '60%', backgroundColor: c.popover, borderTopLeftRadius: radius.lg, borderTopRightRadius: radius.lg, borderTopWidth: 1, borderColor: c.border, paddingTop: spacing.sm, }, sheetHandleHit: { alignItems: 'center', paddingTop: spacing.xs, paddingBottom: spacing.sm, }, sheetHandle: { width: 36, height: 4, borderRadius: 2, backgroundColor: c.border, }, sheetHeader: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingHorizontal: spacing.lg, paddingBottom: spacing.sm, borderBottomWidth: 1, borderBottomColor: c.border, }, sheetTitle: { ...typography.bodySemibold, color: c.text, }, sheetClose: { width: 28, height: 28, alignItems: 'center', justifyContent: 'center', borderRadius: radius.xs, }, scrollList: { paddingVertical: spacing.xs, }, identityRow: { flexDirection: 'row', alignItems: 'center', paddingHorizontal: spacing.lg, paddingVertical: spacing.md, minHeight: 52, }, identityRowPressed: { backgroundColor: c.surfaceHover, }, iconWrap: { marginRight: spacing.md, width: 28, height: 28, borderRadius: radius.xs, backgroundColor: c.surface, alignItems: 'center', justifyContent: 'center', }, identityDetails: { flex: 1, justifyContent: 'center', }, identityName: { ...typography.bodyMedium, color: c.text, }, identityEmail: { ...typography.caption, color: c.textSecondary, marginTop: 2, }, identityEmailOnly: { ...typography.bodyMedium, color: c.text, marginTop: 0, }, checkWrap: { marginLeft: spacing.md, }, }); }