diff --git a/mobile/src/app/(app)/(tabs)/(balances)/balances.tsx b/mobile/src/app/(app)/(tabs)/(balances)/balances.tsx index e690b50..50ccd70 100644 --- a/mobile/src/app/(app)/(tabs)/(balances)/balances.tsx +++ b/mobile/src/app/(app)/(tabs)/(balances)/balances.tsx @@ -1,11 +1,12 @@ -import { router } from 'expo-router'; +import { Stack, router } from 'expo-router'; import React, { useCallback, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { FlatList, RefreshControl, Share, StyleSheet } from 'react-native'; +import { FlatList, Platform, RefreshControl, Share, StyleSheet } from 'react-native'; import { AddExpenseAction } from '@/components/expense'; import { BalanceTotals } from '@/components/friend/BalanceTotals'; import { FriendBalanceRow } from '@/components/friend/FriendBalanceRow'; +import { NativeBalances } from '@/components/friend/NativeBalances'; import { EmptyState, FullScreenSpinner, Separator, icons, rowInset } from '@/components/ui'; import { api } from '@/lib/api'; import { API_URL } from '@/lib/config'; @@ -16,6 +17,7 @@ const Balances = () => { const { t } = useTranslation(); const balanceQuery = api.user.getBalances.useQuery(); const [refreshing, setRefreshing] = useState(false); + const [search, setSearch] = useState(''); const onRefresh = useCallback(() => { setRefreshing(true); @@ -98,10 +100,41 @@ const Balances = () => { return ( // No wrapping view: the list must be the screen's first view for the large title to collapse. <> - {body} - + {'ios' === Platform.OS ? ( + { + await balanceQuery.refetch(); + }} + /> + ) : ( + body + )} + {'ios' === Platform.OS ? ( + <> + setSearch(event.nativeEvent.text)} + onCancelButtonPress={() => setSearch('')} + hideWhenScrolling={false} + /> + + + {t('balances.share_app')} + + router.push('/add')}> + {t('balances.add_expense')} + + + + ) : ( + + )} ); }; diff --git a/mobile/src/components/friend/NativeBalances.ios.tsx b/mobile/src/components/friend/NativeBalances.ios.tsx new file mode 100644 index 0000000..ddd4f03 --- /dev/null +++ b/mobile/src/components/friend/NativeBalances.ios.tsx @@ -0,0 +1,312 @@ +import { + Button, + ContentUnavailableView, + ContextMenu, + HStack, + Host, + Image, + List, + ProgressView, + RNHostView, + Section, + Spacer, + Text, + VStack, +} from '@expo/ui/swift-ui'; +import { + accessibilityElement, + accessibilityHint, + accessibilityLabel, + buttonStyle, + contentShape, + font, + foregroundStyle, + frame, + listRowBackground, + listRowSeparator, + listStyle, + padding, + refreshable, + shapes, +} from '@expo/ui/swift-ui/modifiers'; +import { router } from 'expo-router'; +import React, { useCallback, useMemo } from 'react'; +import { useTranslation } from 'react-i18next'; +import { Platform, useWindowDimensions } from 'react-native'; + +import { Avatar } from '@/components/ui'; +import { type RouterOutputs } from '@/lib/api'; +import { haptics } from '@/lib/haptics'; +import { formatMoney } from '@/lib/money'; +import { colors } from '@/theme/tokens'; + +import { filterBalances } from './balanceSearch'; + +type Balances = RouterOutputs['user']['getBalances']; +type Balance = Balances['balances'][number]; + +const balanceKey = (row: Balance) => String(row.friendId); + +// The app still supports iOS 16.4; Expo's ContentUnavailableView is empty before iOS 17. +const Unavailable = (props: React.ComponentProps) => + 17 <= Number.parseInt(String(Platform.Version), 10) ? ( + + ) : ( + + + {props.title} + + {props.description} + + + ); + +const BalanceRow = React.memo(({ row, fontScale }: { row: Balance; fontScale: number }) => { + const { t } = useTranslation(); + const params = { friendId: String(row.friendId) }; + const add = () => { + haptics.light(); + router.push({ pathname: '/add', params }); + }; + const settle = () => { + haptics.light(); + router.push({ pathname: '/settle-up', params }); + }; + const open = () => router.push({ pathname: '/balances/[friendId]', params }); + const name = row.friend.name ?? row.friend.email ?? ''; + const direction = t( + 0 === row.amount + ? 'balances.settled_up' + : 0 < row.amount + ? 'balances.you_get_short' + : 'balances.you_owe_short', + ); + const amount = formatMoney(row.amount, row.currency); + const tone = + 0 === row.amount ? colors.secondaryLabel : 0 < row.amount ? colors.positive : colors.negative; + return ( + + + + + +