Send files directly between devices over the internet - no cloud storage, no size limits.
TypeScript cross-platformdata-transferdecentralizedfile-sharingfile-transferhole-punchingopen-sourcep2ppeer-to-peerprivacyprivacy-tools
Use native bottom sheet for mobile
Denis Lupookovfa2c5d26bc7b
diff --git a/apps/mobile/assets/icons/arrow-left.xml b/apps/mobile/assets/icons/arrow-left.xmlnew file mode 100644index 0000000..bdae060--- /dev/null+++ b/apps/mobile/assets/icons/arrow-left.xml@@ -0,0 +1,10 @@+<vector xmlns:android="http://schemas.android.com/apk/res/android"+ android:width="24dp"+ android:height="24dp"+ android:viewportWidth="24"+ android:viewportHeight="24"+ android:tint="#FFFFFF">+ <path+ android:fillColor="@android:color/white"+ android:pathData="M15.41,7.41L14,6l-6,6 6,6 1.41,-1.41L10.83,12z"/>+</vector>diff --git a/apps/mobile/assets/icons/close.xml b/apps/mobile/assets/icons/close.xmlnew file mode 100644index 0000000..57638bb--- /dev/null+++ b/apps/mobile/assets/icons/close.xml@@ -0,0 +1,10 @@+<vector xmlns:android="http://schemas.android.com/apk/res/android"+ android:width="24dp"+ android:height="24dp"+ android:viewportWidth="24"+ android:viewportHeight="24"+ android:tint="#FFFFFF">+ <path+ android:fillColor="@android:color/white"+ android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>+</vector>diff --git a/apps/mobile/src/components/AddPairDeviceSheet/index.tsx b/apps/mobile/src/components/AddPairDeviceSheet/index.tsxindex 12f3ed7..5825831 100644--- a/apps/mobile/src/components/AddPairDeviceSheet/index.tsx+++ b/apps/mobile/src/components/AddPairDeviceSheet/index.tsx@@ -30,7 +30,6 @@ export function AddPairDeviceSheet({open={open}onClose={onClose}onDismiss={onDismiss}- title={t('settings:pairing.pairNewDevice')}sheetStyle={styles.sheet}><View style={styles.actionList}>diff --git a/apps/mobile/src/components/BottomSheet/index.tsx b/apps/mobile/src/components/BottomSheet/index.tsxindex e8ff087..7c3e0a4 100644--- a/apps/mobile/src/components/BottomSheet/index.tsx+++ b/apps/mobile/src/components/BottomSheet/index.tsx@@ -1,19 +1,7 @@-import { useCallback, useEffect, useRef, useState, type ReactNode } from 'react'-import {- Animated,- Dimensions,- Easing,- Keyboard,- Modal,- Platform,- Pressable,- StyleSheet,- View,- type LayoutChangeEvent,- type StyleProp,- type ViewStyle-} from 'react-native'-import { useTheme, withAlpha } from '@altersend/components'+import { useEffect, useRef, type ReactNode } from 'react'+import { StyleSheet, View, type StyleProp, type ViewStyle } from 'react-native'+import { BottomSheetModal, BottomSheetView } from '@expo/ui/community/bottom-sheet'+import { useTheme } from '@altersend/components'import { BottomSheetHeader } from '../BottomSheetHeader'interface BottomSheetProps {@@ -22,172 +10,59 @@ interface BottomSheetProps {title?: stringsubtitle?: stringonBack?: () => void- keyboardAvoiding?: booleanonDismiss?: () => voidsheetStyle?: StyleProp<ViewStyle>children: ReactNode}-const BACKDROP_DURATION = 220-const EXIT_DURATION = 200-const OFFSCREEN_FALLBACK = Dimensions.get('window').height-export function BottomSheet({open,onClose,title,subtitle,onBack,- keyboardAvoiding,onDismiss,sheetStyle,children}: BottomSheetProps) {const { theme } = useTheme()const c = theme.colors- const [mounted, setMounted] = useState(open)- const [sheetHeight, setSheetHeight] = useState(0)- const backdropOpacity = useRef(new Animated.Value(0)).current- const sheetTranslate = useRef(new Animated.Value(OFFSCREEN_FALLBACK)).current- const keyboardOffset = useRef(new Animated.Value(0)).current- const hasOpenedRef = useRef(open)-- const onSheetLayout = useCallback((e: LayoutChangeEvent) => {- const h = e.nativeEvent.layout.height- if (h > 0) setSheetHeight((prev) => (prev === h ? prev : h))- }, [])+ const sheetRef = useRef<BottomSheetModal>(null)useEffect(() => {- if (open) hasOpenedRef.current = true- if (!hasOpenedRef.current) return-- if (open) setMounted(true)-- const distance = sheetHeight || OFFSCREEN_FALLBACK+ if (open) sheetRef.current?.present()+ else sheetRef.current?.dismiss()+ }, [open])- const animation = Animated.parallel([- Animated.timing(backdropOpacity, {- toValue: open ? 1 : 0,- duration: open ? BACKDROP_DURATION : EXIT_DURATION,- easing: open ? Easing.out(Easing.cubic) : Easing.in(Easing.cubic),- useNativeDriver: true- }),- open- ? Animated.spring(sheetTranslate, {- toValue: 0,- damping: 24,- stiffness: 260,- mass: 1,- overshootClamping: true,- useNativeDriver: true- })- : Animated.timing(sheetTranslate, {- toValue: distance,- duration: EXIT_DURATION,- easing: Easing.in(Easing.cubic),- useNativeDriver: true- })- ])- animation.start(({ finished }) => {- if (finished && !open) {- setMounted(false)+ return (+ <BottomSheetModal+ ref={sheetRef}+ enableDynamicSizing+ enablePanDownToClose+ keyboardBehavior='interactive'+ onClose={() => {+ onClose()onDismiss?.()- }- })- return () => animation.stop()- }, [open, sheetHeight, backdropOpacity, sheetTranslate, onDismiss])-- useEffect(() => {- if (!keyboardAvoiding) return-- const showEvent = Platform.OS === 'ios' ? 'keyboardWillShow' : 'keyboardDidShow'- const hideEvent = Platform.OS === 'ios' ? 'keyboardWillHide' : 'keyboardDidHide'-- const showSub = Keyboard.addListener(showEvent, (e) => {- Animated.timing(keyboardOffset, {- toValue: e.endCoordinates.height,- duration: e.duration || 220,- useNativeDriver: false- }).start()- })- const hideSub = Keyboard.addListener(hideEvent, (e) => {- Animated.timing(keyboardOffset, {- toValue: 0,- duration: e?.duration || 200,- useNativeDriver: false- }).start()- })-- return () => {- showSub.remove()- hideSub.remove()- }- }, [keyboardAvoiding, keyboardOffset])-- if (!mounted) return null-- const sheet = (- <Animated.View- onLayout={onSheetLayout}- style={[- styles.sheet,- !keyboardAvoiding && styles.sheetAnchored,- { backgroundColor: c.colorBackground, borderColor: c.colorBorderPrimary },- { transform: [{ translateY: sheetTranslate }] },- sheetStyle- ]}+ }}+ backgroundStyle={{ backgroundColor: c.colorBackground }}+ handleIndicatorStyle={{ backgroundColor: c.colorBorderStrong }}>- <View style={[styles.grabber, { backgroundColor: c.colorBorderStrong }]} />- {(title || onBack) && (+ <BottomSheetView style={[styles.body, sheetStyle]}><View style={styles.header}><BottomSheetHeadertitle={title ?? ''}subtitle={subtitle}onBack={onBack}- onClose={onClose}+ onClose={() => sheetRef.current?.dismiss()}/></View>- )}- {children}- </Animated.View>- )-- return (- <Modal visible={mounted} transparent animationType='none' onRequestClose={onClose}>- <Animated.View- style={[- styles.backdrop,- { backgroundColor: withAlpha(c.colorScrim, 0.55), opacity: backdropOpacity }- ]}- >- <Pressable style={StyleSheet.absoluteFill} onPress={onClose} />- </Animated.View>- {keyboardAvoiding ? (- <Animated.View- pointerEvents='box-none'- style={[styles.keyboardAvoider, { paddingBottom: keyboardOffset }]}- >- {sheet}- </Animated.View>- ) : (- sheet- )}- </Modal>+ {children}+ </BottomSheetView>+ </BottomSheetModal>)}const styles = StyleSheet.create({- backdrop: { ...StyleSheet.absoluteFill },- keyboardAvoider: { ...StyleSheet.absoluteFill, justifyContent: 'flex-end' },- sheet: {- borderTopLeftRadius: 24,- borderTopRightRadius: 24,- borderWidth: StyleSheet.hairlineWidth,- paddingTop: 12,- paddingBottom: 44,- gap: 16- },- sheetAnchored: { position: 'absolute', left: 0, right: 0, bottom: 0 },- header: { paddingHorizontal: 20 },- grabber: { alignSelf: 'center', width: 36, height: 4, borderRadius: 999, marginBottom: 8 }+ body: { paddingBottom: 44, gap: 16 },+ header: { paddingHorizontal: 20, paddingTop: 12 }})diff --git a/apps/mobile/src/components/BottomSheetHeader/index.tsx b/apps/mobile/src/components/BottomSheetHeader/index.tsxindex 2d2c569..526c641 100644--- a/apps/mobile/src/components/BottomSheetHeader/index.tsx+++ b/apps/mobile/src/components/BottomSheetHeader/index.tsx@@ -1,6 +1,7 @@-import { Pressable, StyleSheet, View } from 'react-native'+import { StyleSheet, View } from 'react-native'import { useTheme } from '@altersend/components'-import { ArrowLeftIcon, CloseIcon } from '@altersend/components/icons'+import { useTranslation } from '@altersend/locales'+import { IconButton } from '../IconButton'import { Text } from '../ThemedText'interface BottomSheetHeaderProps {@@ -12,19 +13,14 @@ interface BottomSheetHeaderProps {export function BottomSheetHeader({ title, subtitle, onBack, onClose }: BottomSheetHeaderProps) {const { theme } = useTheme()+ const { t } = useTranslation(['common'])const c = theme.colorsreturn (<View style={styles.header}>{onBack ? (- <Pressable- accessibilityRole='button'- accessibilityLabel='Back'- hitSlop={12}- onPress={onBack}- style={({ pressed }) => [styles.backButton, { opacity: pressed ? 0.6 : 1 }]}- >- <ArrowLeftIcon size={20} color={c.colorTextPrimary} />- </Pressable>+ <View style={styles.backSlot}>+ <IconButton icon='back' label={t('common:actions.back')} onPress={onBack} size='medium' />+ </View>) : null}<View style={styles.titleGroup}><Text style={[styles.title, { color: c.colorTextPrimary }]} numberOfLines={1}>@@ -32,30 +28,15 @@ export function BottomSheetHeader({ title, subtitle, onBack, onClose }: BottomSh</Text>{subtitle && <Text style={[styles.subtitle, { color: c.colorTextMuted }]}>{subtitle}</Text>}</View>- <Pressable- accessibilityRole='button'- accessibilityLabel='Close'- hitSlop={12}- onPress={onClose}- style={({ pressed }) => [styles.closeButton, { opacity: pressed ? 0.6 : 1 }]}- >- <CloseIcon size={20} color={c.colorTextPrimary} />- </Pressable>+ <IconButton icon='close' label={t('common:actions.close')} onPress={onClose} size='medium' /></View>)}const styles = StyleSheet.create({header: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' },- backButton: {- width: 32,- height: 32,- alignItems: 'center',- justifyContent: 'center',- marginRight: 4- },+ backSlot: { marginRight: 16 },titleGroup: { flex: 1, marginRight: 8 },- title: { fontSize: 16, fontWeight: '700' },- subtitle: { fontSize: 12, marginTop: 2 },- closeButton: { width: 32, height: 32, alignItems: 'center', justifyContent: 'center' }+ title: { fontSize: 18, fontWeight: '700' },+ subtitle: { fontSize: 13, marginTop: 2 }})diff --git a/apps/mobile/src/components/DeviceActionsSheet/index.tsx b/apps/mobile/src/components/DeviceActionsSheet/index.tsxindex 9655ad2..b9c5a74 100644--- a/apps/mobile/src/components/DeviceActionsSheet/index.tsx+++ b/apps/mobile/src/components/DeviceActionsSheet/index.tsx@@ -18,7 +18,6 @@ export function DeviceActionsSheet({ open, onClose, onRemove, onRename }: Device<BottomSheetopen={open}onClose={onClose}- title={t('settings:pairing.deviceActions')}sheetStyle={styles.sheet}><View style={styles.actionList}>diff --git a/apps/mobile/src/components/DeviceRenameSheet/index.tsx b/apps/mobile/src/components/DeviceRenameSheet/index.tsxindex 3dfa4d2..a91f0f7 100644--- a/apps/mobile/src/components/DeviceRenameSheet/index.tsx+++ b/apps/mobile/src/components/DeviceRenameSheet/index.tsx@@ -30,7 +30,6 @@ export function DeviceRenameSheet({open={open}onClose={onClose}title={t('settings:pairing.renameDevice')}- keyboardAvoidingsheetStyle={styles.sheet}><View style={styles.form}>diff --git a/apps/mobile/src/components/IconButton/IconButton.android.tsx b/apps/mobile/src/components/IconButton/IconButton.android.tsxindex f9eac88..d8fedb3 100644--- a/apps/mobile/src/components/IconButton/IconButton.android.tsx+++ b/apps/mobile/src/components/IconButton/IconButton.android.tsx@@ -1,18 +1,23 @@import { useTheme } from '@altersend/components'import { Host, Icon, IconButton as ComposeIconButton } from '@expo/ui/jetpack-compose'import type { ImageSourcePropType } from 'react-native'+import arrowLeftIcon from '@/assets/icons/arrow-left.xml'+import closeIcon from '@/assets/icons/close.xml'import settingsIcon from '@/assets/icons/settings.xml'-import { ICON_BUTTON_SIZE, type IconButtonIcon, type IconButtonProps } from './IconButton.types'+import { ICON_BUTTON_SIZES, type IconButtonIcon, type IconButtonProps } from './IconButton.types'const sources: Record<IconButtonIcon, ImageSourcePropType> = {- settings: settingsIcon+ settings: settingsIcon,+ back: arrowLeftIcon,+ close: closeIcon}-export function IconButton({ icon, onPress, size = ICON_BUTTON_SIZE }: IconButtonProps) {+export function IconButton({ icon, onPress, size = 'large' }: IconButtonProps) {const { theme } = useTheme()+ const dimension = ICON_BUTTON_SIZES[size]return (- <Host style={{ width: size, height: size }}>+ <Host style={{ width: dimension, height: dimension }}><ComposeIconButton onClick={onPress}><Icon source={sources[icon]} tint={theme.colors.colorTextPrimary} /></ComposeIconButton>diff --git a/apps/mobile/src/components/IconButton/IconButton.ios.tsx b/apps/mobile/src/components/IconButton/IconButton.ios.tsxindex ae8f7f3..09189f8 100644--- a/apps/mobile/src/components/IconButton/IconButton.ios.tsx+++ b/apps/mobile/src/components/IconButton/IconButton.ios.tsx@@ -8,25 +8,28 @@ import {imageScale,labelStyle} from '@expo/ui/swift-ui/modifiers'-import { ICON_BUTTON_SIZE, type IconButtonIcon, type IconButtonProps } from './IconButton.types'+import { ICON_BUTTON_SIZES, type IconButtonIcon, type IconButtonProps } from './IconButton.types'const symbols = {- settings: 'gear'+ settings: 'gear',+ back: 'chevron.left',+ close: 'xmark'} as const satisfies Record<IconButtonIcon, string>-export function IconButton({ icon, label, onPress, size = ICON_BUTTON_SIZE }: IconButtonProps) {+export function IconButton({ icon, label, onPress, size = 'large' }: IconButtonProps) {const { theme } = useTheme()+ const dimension = ICON_BUTTON_SIZES[size]return (- <Host style={{ width: size, height: size }}>+ <Host style={{ width: dimension, height: dimension }}><Buttonlabel={label}systemImage={symbols[icon]}modifiers={[labelStyle('iconOnly'),buttonStyle('plain'),- imageScale(size >= ICON_BUTTON_SIZE ? 'large' : 'medium'),- frame({ width: size, height: size }),+ imageScale(size),+ frame({ width: dimension, height: dimension }),glassEffect({ glass: { variant: 'regular', interactive: true }, shape: 'circle' }),foregroundStyle(theme.colors.colorTextPrimary)]}diff --git a/apps/mobile/src/components/IconButton/IconButton.types.ts b/apps/mobile/src/components/IconButton/IconButton.types.tsindex 1c09060..6e7180f 100644--- a/apps/mobile/src/components/IconButton/IconButton.types.ts+++ b/apps/mobile/src/components/IconButton/IconButton.types.ts@@ -1,10 +1,15 @@-export type IconButtonIcon = 'settings'+export type IconButtonIcon = 'settings' | 'back' | 'close'++export type IconButtonSize = 'medium' | 'large'export interface IconButtonProps {icon: IconButtonIconlabel: stringonPress: () => void- size?: number+ size?: IconButtonSize}-export const ICON_BUTTON_SIZE = 44+export const ICON_BUTTON_SIZES: Record<IconButtonSize, number> = {+ medium: 32,+ large: 44+}diff --git a/apps/mobile/src/components/PairingManualCodeSheet/index.tsx b/apps/mobile/src/components/PairingManualCodeSheet/index.tsxindex 0bc40ca..df51ef2 100644--- a/apps/mobile/src/components/PairingManualCodeSheet/index.tsx+++ b/apps/mobile/src/components/PairingManualCodeSheet/index.tsx@@ -79,7 +79,6 @@ export function PairingManualCodeSheet({onClose={onClose}onBack={onBack}title={t('settings:pairing.enterCode')}- keyboardAvoidingsheetStyle={styles.sheet}><View style={styles.form}>