Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

sidebar-navigation-shell.tsx

69 lines3.1 KB

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