From 273e606f5574c5aa8874f5ca06701f11cbd670c5 Mon Sep 17 00:00:00 2001 From: KM Koushik Date: Tue, 10 Nov 2026 14:55:17 +1100 Subject: [PATCH 1/2] feat(mobile): native iOS Balances home --- .../app/(app)/(tabs)/(balances)/balances.tsx | 45 ++- .../components/friend/NativeBalances.ios.tsx | 321 ++++++++++++++++++ .../src/components/friend/NativeBalances.tsx | 8 + .../components/friend/balanceSearch.test.ts | 30 ++ mobile/src/components/friend/balanceSearch.ts | 10 + mobile/src/i18n/locales/en.json | 4 + 6 files changed, 412 insertions(+), 6 deletions(-) create mode 100644 mobile/src/components/friend/NativeBalances.ios.tsx create mode 100644 mobile/src/components/friend/NativeBalances.tsx create mode 100644 mobile/src/components/friend/balanceSearch.test.ts create mode 100644 mobile/src/components/friend/balanceSearch.ts 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..a76c948 --- /dev/null +++ b/mobile/src/components/friend/NativeBalances.ios.tsx @@ -0,0 +1,321 @@ +import { + Button, + ContentUnavailableView, + ContextMenu, + HStack, + Host, + Image, + List, + ProgressView, + RNHostView, + Section, + Spacer, + SwipeActions, + Text, + VStack, +} from '@expo/ui/swift-ui'; +import { + accessibilityElement, + accessibilityHint, + accessibilityLabel, + buttonStyle, + contentShape, + font, + foregroundStyle, + frame, + listRowBackground, + listRowSeparator, + listStyle, + padding, + refreshable, + shapes, + tint, +} from '@expo/ui/swift-ui/modifiers'; +import { router } from 'expo-router'; +import React 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']; + +// 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} + + + ); + +/** Genuine SwiftUI rows: system insets, separators, highlighting, swipe physics and menus. */ +export const NativeBalances = ({ + data, + search, + loading, + error, + onRefresh, +}: { + data?: Balances; + search: string; + loading: boolean; + error?: string; + onRefresh: () => Promise; +}) => { + const { t } = useTranslation(); + const { fontScale } = useWindowDimensions(); + const query = search.trim().toLocaleLowerCase(); + const rows = filterBalances(data?.balances ?? [], query); + + return ( + + + {data && !query && (data.youOwe.length || data.youGet.length) ? ( +
+ + {[ + { title: t('balances.you_owe'), totals: data.youOwe, color: colors.negative }, + { title: t('balances.you_get'), totals: data.youGet, color: colors.positive }, + ] + .filter(({ totals }) => totals.length) + .map(({ title, totals, color }) => ( + + + {title} + + {[...totals] + .sort((a, b) => a.currency.localeCompare(b.currency)) + .map((total) => ( + + {formatMoney(total.amount, total.currency)} + + ))} + + ))} + +
+ ) : null} +
+ {rows.map((row) => { + 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 ( + + + + + + +
+
+
+ ); +}; diff --git a/mobile/src/components/friend/NativeBalances.tsx b/mobile/src/components/friend/NativeBalances.tsx new file mode 100644 index 0000000..bb20971 --- /dev/null +++ b/mobile/src/components/friend/NativeBalances.tsx @@ -0,0 +1,8 @@ +/** iOS uses the platform-specific SwiftUI implementation; other platforms keep FlatList. */ +export const NativeBalances = (_props: { + data?: import('@/lib/api').RouterOutputs['user']['getBalances']; + search: string; + loading: boolean; + error?: string; + onRefresh: () => Promise; +}) => null; diff --git a/mobile/src/components/friend/balanceSearch.test.ts b/mobile/src/components/friend/balanceSearch.test.ts new file mode 100644 index 0000000..ed031d4 --- /dev/null +++ b/mobile/src/components/friend/balanceSearch.test.ts @@ -0,0 +1,30 @@ +import assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; + +import { filterBalances } from './balanceSearch'; + +// Only the name and email are read; keep the fixture independent of server profile fields. +const balances = [ + { friend: { name: 'Alice', email: 'alice@example.com' } }, + { friend: { name: null, email: 'bob@example.com' } }, + { friend: { name: null, email: null } }, +] as Parameters[0]; + +describe('filterBalances', () => { + it('should match names without case or surrounding whitespace', () => { + assert.deepEqual(filterBalances(balances, ' ALICE '), [balances[0]]); + }); + + it('should search email when the name is missing', () => { + assert.deepEqual(filterBalances(balances, 'BOB@'), [balances[1]]); + }); + + it('should preserve all balances and their order when search is cleared', () => { + assert.deepEqual(filterBalances(balances, ' '), balances); + }); + + it('should return no results safely with missing profile fields', () => { + assert.deepEqual(filterBalances(balances, 'nobody'), []); + assert.deepEqual(filterBalances([], 'alice'), []); + }); +}); diff --git a/mobile/src/components/friend/balanceSearch.ts b/mobile/src/components/friend/balanceSearch.ts new file mode 100644 index 0000000..a950123 --- /dev/null +++ b/mobile/src/components/friend/balanceSearch.ts @@ -0,0 +1,10 @@ +import { type RouterOutputs } from '@/lib/api'; + +type Balance = RouterOutputs['user']['getBalances']['balances'][number]; + +export const filterBalances = (balances: Balance[], search: string) => { + const query = search.trim().toLocaleLowerCase(); + return balances.filter((row) => + `${row.friend.name ?? ''} ${row.friend.email ?? ''}`.toLocaleLowerCase().includes(query), + ); +}; diff --git a/mobile/src/i18n/locales/en.json b/mobile/src/i18n/locales/en.json index 6d7008e..39f2fdf 100644 --- a/mobile/src/i18n/locales/en.json +++ b/mobile/src/i18n/locales/en.json @@ -120,6 +120,10 @@ "delete_done": "Your account was deleted" }, "balances": { + "search_friends": "Search friends", + "no_results": "No friends found", + "view_balance": "View balance", + "open_friend_hint": "Opens balances and expenses with this friend", "you_owe": "You owe", "you_get": "You get", "you_lent": "You lent", From d0fa5d276c0330d90cd9f701dfac5068f1b2c5ec Mon Sep 17 00:00:00 2001 From: KM Koushik Date: Tue, 10 Nov 2026 15:07:42 +1100 Subject: [PATCH 2/2] fix(mobile): recycle balance rows and remove swipe actions --- .../components/friend/NativeBalances.ios.tsx | 303 +++++++++--------- 1 file changed, 147 insertions(+), 156 deletions(-) diff --git a/mobile/src/components/friend/NativeBalances.ios.tsx b/mobile/src/components/friend/NativeBalances.ios.tsx index a76c948..ddd4f03 100644 --- a/mobile/src/components/friend/NativeBalances.ios.tsx +++ b/mobile/src/components/friend/NativeBalances.ios.tsx @@ -10,7 +10,6 @@ import { RNHostView, Section, Spacer, - SwipeActions, Text, VStack, } from '@expo/ui/swift-ui'; @@ -29,10 +28,9 @@ import { padding, refreshable, shapes, - tint, } from '@expo/ui/swift-ui/modifiers'; import { router } from 'expo-router'; -import React from 'react'; +import React, { useCallback, useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { Platform, useWindowDimensions } from 'react-native'; @@ -45,6 +43,9 @@ 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) => @@ -60,7 +61,136 @@ const Unavailable = (props: React.ComponentProps) ); -/** Genuine SwiftUI rows: system insets, separators, highlighting, swipe physics and menus. */ +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 ( + + + + + + - - -