Skip to content

Commit b2c9e51

Browse files
refactor(mobile): remove redundant platform resolution shims
1 parent 39ac3a9 commit b2c9e51

3 files changed

Lines changed: 195 additions & 197 deletions

File tree

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

Lines changed: 0 additions & 195 deletions
This file was deleted.
Lines changed: 194 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,195 @@
1-
export { HomeHeader } from "./HomeHeader.ios";
1+
import { NativeHeaderToolbar, NativeStackScreenOptions } from "../../native/StackHeader";
2+
import { useCallback, useRef } from "react";
3+
import type { SearchBarCommands } from "react-native-screens";
4+
import { useUniwindTheme } from "../../lib/useUniwindTheme";
5+
import { useThreadListV2Enabled } from "../threads/use-thread-list-v2-enabled";
6+
import { useHardwareKeyboardCommand } from "../keyboard/hardwareKeyboardCommands";
7+
import { withNativeGlassHeaderItem } from "../layout/native-glass-header-items";
8+
import {
9+
createNativeMailSearchToolbarItem,
10+
NATIVE_MAIL_SEARCH_TOOLBAR_SUPPORTED,
11+
} from "../layout/native-mail-search-toolbar";
12+
import { buildHomeListFilterMenu } from "./home-list-filter-menu";
13+
import {
14+
hasCustomHomeListOptions,
15+
PROJECT_SORT_OPTIONS,
16+
THREAD_SORT_OPTIONS,
17+
} from "./home-list-options";
18+
import type { HomeHeaderProps } from "./HomeHeader.types";
19+
220
export type { HomeHeaderEnvironment } from "./HomeHeader.types";
21+
22+
export function HomeHeader(props: HomeHeaderProps) {
23+
const searchBarRef = useRef<SearchBarCommands>(null);
24+
const iconColor = useUniwindTheme()["--color-icon"];
25+
// Thread List v2 lays the list out in fixed creation order, so the
26+
// sort/group filter controls would be silently ignored — hide them and
27+
// key the "customized" icon state off the environment filter alone.
28+
const threadListV2Enabled = useThreadListV2Enabled();
29+
const hasCustomListOptions = threadListV2Enabled
30+
? props.selectedEnvironmentId !== null || props.selectedProjectKey !== null
31+
: hasCustomHomeListOptions(props);
32+
const focusSearch = useCallback(() => {
33+
searchBarRef.current?.focus();
34+
return searchBarRef.current !== null;
35+
}, []);
36+
useHardwareKeyboardCommand("focusSearch", focusSearch);
37+
const filterMenu = buildHomeListFilterMenu({
38+
...props,
39+
listOrganization: !threadListV2Enabled,
40+
});
41+
42+
return (
43+
<>
44+
<NativeStackScreenOptions
45+
optionsVersion={filterMenu.items}
46+
options={{
47+
// Static header config (glass, title, fonts) lives in Stack.tsx
48+
// (GLASS_HEADER_OPTIONS). Only dynamic values are set here.
49+
headerTintColor: iconColor,
50+
unstable_headerRightItems: () => [
51+
withNativeGlassHeaderItem({
52+
accessibilityLabel: "Open settings",
53+
icon: { name: "ellipsis", type: "sfSymbol" } as const,
54+
identifier: "home-settings",
55+
label: "",
56+
onPress: props.onOpenSettings,
57+
type: "button",
58+
}),
59+
],
60+
// The keys below are set per-branch (not `undefined`) so a later
61+
// reapply cannot clobber options owned by NativeHeaderToolbar.
62+
...(NATIVE_MAIL_SEARCH_TOOLBAR_SUPPORTED
63+
? {
64+
unstable_headerToolbarItems: () => [
65+
createNativeMailSearchToolbarItem({
66+
composeButtonId: "home-new-task",
67+
composeSystemImageName: "square.and.pencil",
68+
filterMenu,
69+
filterButtonId: "home-filter",
70+
filterSystemImageName: hasCustomListOptions
71+
? "line.3.horizontal.decrease.circle.fill"
72+
: "line.3.horizontal.decrease",
73+
onComposePress: props.onStartNewTask,
74+
onSearchTextChange: props.onSearchQueryChange,
75+
placeholder: "Search",
76+
searchTextChangeId: "home-search-text",
77+
showsSearchDismissButton: true,
78+
}),
79+
],
80+
}
81+
: {
82+
// Pre-Liquid-Glass iOS: standard pull-down search in the nav
83+
// bar; create + sort live in the plain bottom toolbar below.
84+
headerSearchBarOptions: {
85+
ref: searchBarRef,
86+
autoCapitalize: "none" as const,
87+
hideNavigationBar: false,
88+
placeholder: "Search",
89+
onCancelButtonPress: () => {
90+
props.onSearchQueryChange("");
91+
},
92+
onChangeText: (event) => {
93+
props.onSearchQueryChange(event.nativeEvent.text);
94+
},
95+
},
96+
}),
97+
}}
98+
/>
99+
100+
{NATIVE_MAIL_SEARCH_TOOLBAR_SUPPORTED ? null : (
101+
<NativeHeaderToolbar placement="bottom">
102+
<NativeHeaderToolbar.Menu
103+
accessibilityLabel="Filter and sort threads"
104+
icon={
105+
hasCustomListOptions
106+
? "line.3.horizontal.decrease.circle.fill"
107+
: "line.3.horizontal.decrease.circle"
108+
}
109+
title="Thread list options"
110+
separateBackground
111+
>
112+
<NativeHeaderToolbar.Menu title="Environment">
113+
<NativeHeaderToolbar.Label>Environment</NativeHeaderToolbar.Label>
114+
<NativeHeaderToolbar.MenuAction
115+
isOn={props.selectedEnvironmentId === null}
116+
onPress={() => props.onEnvironmentChange(null)}
117+
subtitle="Show threads from every environment"
118+
>
119+
<NativeHeaderToolbar.Label>All environments</NativeHeaderToolbar.Label>
120+
</NativeHeaderToolbar.MenuAction>
121+
{props.environments.map((environment) => (
122+
<NativeHeaderToolbar.MenuAction
123+
key={environment.environmentId}
124+
isOn={props.selectedEnvironmentId === environment.environmentId}
125+
onPress={() => props.onEnvironmentChange(environment.environmentId)}
126+
>
127+
<NativeHeaderToolbar.Label>{environment.label}</NativeHeaderToolbar.Label>
128+
</NativeHeaderToolbar.MenuAction>
129+
))}
130+
</NativeHeaderToolbar.Menu>
131+
132+
{props.projects.length > 0 ? (
133+
<NativeHeaderToolbar.Menu title="Project">
134+
<NativeHeaderToolbar.Label>Project</NativeHeaderToolbar.Label>
135+
<NativeHeaderToolbar.MenuAction
136+
isOn={props.selectedProjectKey === null}
137+
onPress={() => props.onProjectChange(null)}
138+
subtitle="Show threads from every project"
139+
>
140+
<NativeHeaderToolbar.Label>All projects</NativeHeaderToolbar.Label>
141+
</NativeHeaderToolbar.MenuAction>
142+
{props.projects.map((project) => (
143+
<NativeHeaderToolbar.MenuAction
144+
key={project.key}
145+
isOn={props.selectedProjectKey === project.key}
146+
onPress={() => props.onProjectChange(project.key)}
147+
>
148+
<NativeHeaderToolbar.Label>{project.label}</NativeHeaderToolbar.Label>
149+
</NativeHeaderToolbar.MenuAction>
150+
))}
151+
</NativeHeaderToolbar.Menu>
152+
) : null}
153+
154+
{threadListV2Enabled ? null : (
155+
<NativeHeaderToolbar.Menu title="Sort projects">
156+
<NativeHeaderToolbar.Label>Sort projects</NativeHeaderToolbar.Label>
157+
{PROJECT_SORT_OPTIONS.map((option) => (
158+
<NativeHeaderToolbar.MenuAction
159+
key={option.value}
160+
isOn={props.projectSortOrder === option.value}
161+
onPress={() => props.onProjectSortOrderChange(option.value)}
162+
>
163+
<NativeHeaderToolbar.Label>{option.label}</NativeHeaderToolbar.Label>
164+
</NativeHeaderToolbar.MenuAction>
165+
))}
166+
</NativeHeaderToolbar.Menu>
167+
)}
168+
169+
{threadListV2Enabled ? null : (
170+
<NativeHeaderToolbar.Menu title="Sort threads">
171+
<NativeHeaderToolbar.Label>Sort threads</NativeHeaderToolbar.Label>
172+
{THREAD_SORT_OPTIONS.map((option) => (
173+
<NativeHeaderToolbar.MenuAction
174+
key={option.value}
175+
isOn={props.threadSortOrder === option.value}
176+
onPress={() => props.onThreadSortOrderChange(option.value)}
177+
>
178+
<NativeHeaderToolbar.Label>{option.label}</NativeHeaderToolbar.Label>
179+
</NativeHeaderToolbar.MenuAction>
180+
))}
181+
</NativeHeaderToolbar.Menu>
182+
)}
183+
</NativeHeaderToolbar.Menu>
184+
<NativeHeaderToolbar.Spacer flexible />
185+
<NativeHeaderToolbar.Button
186+
accessibilityLabel="New task"
187+
icon="square.and.pencil"
188+
onPress={props.onStartNewTask}
189+
separateBackground
190+
/>
191+
</NativeHeaderToolbar>
192+
)}
193+
</>
194+
);
195+
}

0 commit comments

Comments
 (0)