Skip to content

Commit fcc682e

Browse files
fix(mobile): iOS search bar shows the reset Files query
The iOS AppBar never pushed search.value into the native search bar, so after a workspace switch reset the Files query the inspector's field still showed the old text and the next keystroke resent it. The bar now follows value changes the caller makes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent aa9236c commit fcc682e

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

‎apps/mobile/src/components/ui/AppBar.tsx‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Toolbar } from "./Toolbar";
22
import { AppActivityIndicator } from "./AppActivityIndicator";
3-
import type { HeaderBarButtonMailSearchToolbarItem } from "react-native-screens";
3+
import type { HeaderBarButtonMailSearchToolbarItem, SearchBarCommands } from "react-native-screens";
44
import { NavigationContext } from "@react-navigation/native";
5-
import { use, useId, useLayoutEffect } from "react";
5+
import { use, useId, useLayoutEffect, useRef } from "react";
66
import { View } from "react-native";
77
import { createNativeHeaderMenu } from "./nativeHeaderMenu.ios";
88
import { ScreenHeaderButton } from "./ScreenHeaderButton";
@@ -78,6 +78,19 @@ export function AppBar(props: AppBarProps) {
7878
const usesNativeMailSearchToolbar = useNativeMailSearchToolbar();
7979
const { search, menus } = props;
8080
const menu = menus?.[0];
81+
const searchBarRef = useRef<SearchBarCommands>(null);
82+
const nativeSearchText = useRef(search?.value ?? "");
83+
const searchValue = search?.value;
84+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- the native search bar keeps its own text; a value the caller changes (a reset) has to be pushed into it
85+
useLayoutEffect(() => {
86+
if (searchValue === undefined || searchValue === nativeSearchText.current) return;
87+
nativeSearchText.current = searchValue;
88+
searchBarRef.current?.setText(searchValue);
89+
}, [searchValue]);
90+
const reportSearchText = (text: string) => {
91+
nativeSearchText.current = text;
92+
search?.onChangeText(text);
93+
};
8194
const compactSearch =
8295
search !== undefined &&
8396
(search.compactToolbar ?? !layout.usesSplitView) &&
@@ -142,8 +155,9 @@ export function AppBar(props: AppBarProps) {
142155
? { obscureBackground: false }
143156
: undefined),
144157
placeholder: search.placeholder,
145-
onChangeText: (event) => search.onChangeText(event.nativeEvent.text),
146-
onCancelButtonPress: () => search.onChangeText(""),
158+
ref: searchBarRef,
159+
onChangeText: (event) => reportSearchText(event.nativeEvent.text),
160+
onCancelButtonPress: () => reportSearchText(""),
147161
},
148162
}
149163
: undefined),

0 commit comments

Comments
 (0)