Open History to see the last commit
1import { NavigationContainer, NavigationIndependentTree } from "@react-navigation/native";
2import {
3 createNativeStackNavigator,
4 type NativeStackNavigationOptions,
5} from "@react-navigation/native-stack";
6import type { ReactNode } from "react";
7import { Platform } from "react-native";
8
9import { getCompactBrandHeaderOptions } from "../../components/CompactBrandTitle";
10import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass";
11import { nativeHeaderScrollEdgeEffects } from "../../native/StackHeader";
12import { useMobileNavigationTheme } from "../../lib/useMobileNavigationTheme";
13import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
14
15const SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);
16
17type SidebarScreenOptions = NativeStackNavigationOptions & {
18 // Same patched RNS option the GLASS/SOLID presets in Stack.tsx use — the
19 // iOS 26 "editor" navigation-item style leading-aligns the inline title.
20 readonly unstable_navigationItemStyle?: "editor";
21};
22
23/**
24 * Static chrome for the sidebar column: a real UINavigationBar with a fixed
25 * inline title (no large title — saves vertical space, left-aligned via the
26 * editor item style) and the search bar pinned below it, scroll-edge blur
27 * sampling the list. Only genuinely dynamic values (search callbacks, header
28 * items) are set by the screen content via NativeStackScreenOptions.
29 */
30const SIDEBAR_SCREEN_OPTIONS: SidebarScreenOptions = {
31 contentStyle: { backgroundColor: "transparent" },
32 headerLargeTitle: false,
33 headerShadowVisible: false,
34 headerShown: true,
35 headerStyle: NATIVE_LIQUID_GLASS_SUPPORTED ? { backgroundColor: "transparent" } : undefined,
36 ...getCompactBrandHeaderOptions({ fontSize: 18, fontWeight: "800" }),
37 headerTransparent: NATIVE_LIQUID_GLASS_SUPPORTED,
38 scrollEdgeEffects: NATIVE_LIQUID_GLASS_SUPPORTED ? SCROLL_EDGE_EFFECTS : undefined,
39 unstable_navigationItemStyle: NATIVE_LIQUID_GLASS_SUPPORTED ? "editor" : undefined,
40};
41
42const SidebarStack = createNativeStackNavigator();
43
44/**
45 * Hosts the iPad sidebar pane inside its own single-screen native stack.
46 *
47 * The stack is navigation-inert — nothing is ever pushed onto it. It exists so
48 * the sidebar column owns a real UINavigationBar (large title, native bar
49 * button items, UISearchController), mirroring how each column of a
50 * UISplitViewController has its own UINavigationController. All real
51 * navigation still flows through the root stack via callbacks minted in
52 * AdaptiveWorkspaceLayout; NavigationIndependentTree only isolates the
53 * navigation hooks used for header configuration inside the pane.
54 */
55export function SidebarNavigationShell(props: { readonly children: ReactNode }) {
56 const { themeAppearance } = useAppearancePreferences();
57 const navigationTheme = useMobileNavigationTheme(themeAppearance);
58
59 return (
60 <NavigationIndependentTree>
61 <NavigationContainer theme={navigationTheme}>
62 <SidebarStack.Navigator
63 screenOptions={SIDEBAR_SCREEN_OPTIONS}
64 initialRouteName="SidebarThreads"
65 >
66 <SidebarStack.Screen name="SidebarThreads">{() => props.children}</SidebarStack.Screen>
67 </SidebarStack.Navigator>
68 </NavigationContainer>
69 </NavigationIndependentTree>
70 );
71}