Skip to content

Commit 28df4c3

Browse files
committed
fix(mobile): restore Duo search text without changing placement
1 parent b90878b commit 28df4c3

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

‎apps/mobile/src/features/home/HomeHeader.tsx‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NativeHeaderToolbar, NativeStackScreenOptions } from "../../native/StackHeader";
2-
import { use, useCallback, useEffect, useRef } from "react";
2+
import { use, useCallback, useEffect, useEffectEvent, useRef } from "react";
33
import { useNavigation, type ParamListBase } from "@react-navigation/native";
44
import type { NativeStackNavigationProp } from "@react-navigation/native-stack";
55
import { Platform } from "react-native";
@@ -21,14 +21,23 @@ export function HomeHeader(props: HomeHeaderProps) {
2121
const navigation = useNavigation<NativeStackNavigationProp<ParamListBase>>();
2222
const { panes, togglePrimarySidebar } = useAdaptiveWorkspaceLayout();
2323
const usesNativeMailSearchToolbar = useNativeMailSearchToolbar();
24-
const isPad = Platform.OS === "ios" && Platform.isPad;
2524
const primaryColumn = use(NativePrimaryColumnContext);
2625
const sidebarHeader =
2726
Platform.OS === "ios" &&
2827
primaryColumn !== null &&
2928
(Platform.isPad || !usesNativeMailSearchToolbar);
3029
const searchBarRef = useRef<SearchBarCommands>(null);
3130
const focusAfterReveal = useRef(false);
31+
const usesDuoWorkspace = Platform.OS === "ios" && !Platform.isPad && primaryColumn !== null;
32+
const restoreSearchText = useEffectEvent(() => {
33+
searchBarRef.current?.setText(props.searchQuery);
34+
});
35+
// UIKit swaps search fields when the Duo header changes modes. Restore the
36+
// current filter without reapplying text on each keystroke.
37+
useEffect(() => {
38+
if (usesDuoWorkspace) restoreSearchText();
39+
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- Header mode changes replace the native search field.
40+
}, [sidebarHeader, usesDuoWorkspace]);
3241
useEffect(
3342
() =>
3443
navigation.addListener("transitionEnd", (event) => {
@@ -93,11 +102,9 @@ export function HomeHeader(props: HomeHeaderProps) {
93102
autoCapitalize: "none" as const,
94103
hideNavigationBar: false,
95104
hideWhenScrolling: false,
96-
...(isPad ? { obscureBackground: false } : {}),
97-
// Duo keeps the integrated search presentation while UIKit
98-
// moves the header between horizontal and vertical bars.
99-
placement: isPad ? ("stacked" as const) : ("integrated" as const),
100-
allowToolbarIntegration: !isPad,
105+
obscureBackground: false,
106+
placement: "stacked" as const,
107+
allowToolbarIntegration: false,
101108
placeholder: "Search",
102109
onCancelButtonPress: () => props.onSearchQueryChange(""),
103110
onChangeText: (event) => props.onSearchQueryChange(event.nativeEvent.text),

0 commit comments

Comments
 (0)