From 756ceaa4364b26131228bb19de8ff6d476cda04a Mon Sep 17 00:00:00 2001 From: Linus Rath <139418639+rathlinus@users.noreply.github.com> Date: Thu, 15 Oct 2026 02:35:21 +0200 Subject: [PATCH] fix: leave contact selection and search with back before leaving the tab --- src/screens/ContactsScreen.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/screens/ContactsScreen.tsx b/src/screens/ContactsScreen.tsx index 0d0c3f86..93ed0685 100644 --- a/src/screens/ContactsScreen.tsx +++ b/src/screens/ContactsScreen.tsx @@ -16,6 +16,8 @@ import * as FileSystem from 'expo-file-system/legacy'; import * as Sharing from 'expo-sharing'; import { SafeAreaView } from 'react-native-safe-area-context'; import { useNavigation } from '@react-navigation/native'; +import { useBackWhileFocused } from '../lib/use-back-while-focused'; +import { listBackStep } from '../lib/list-back'; import type { NativeStackNavigationProp } from '@react-navigation/native-stack'; import { Search, Plus, UserCircle, X, Menu, Trash2, Tag, FolderInput, Upload, CheckSquare, Share2, @@ -232,6 +234,17 @@ export default function ContactsScreen({ onOpenContact, activeContactId = null } const clearSelection = () => setSelection(new Set()); + // Back leaves selection mode, then the search, before it leaves the tab. + const backStep = listBackStep({ selecting: selectionMode, searching: searchActive || searchQuery.length > 0 }); + useBackWhileFocused(backStep !== 'leave', () => { + if (backStep === 'clear-selection') { + clearSelection(); + } else { + setSearchQuery(''); + setSearchActive(false); + } + }); + const doBulkDelete = async () => { const ids = Array.from(selection); setConfirmBulkDelete(false);