@devries-cameron20 / t3code-1 / commits / 543af770b4
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(android): keep the split view and menus off the fold crease (#19988)

Alex committed Oct 16, 2026 at 15:30 UTC 543af770b4136bd30222861bbb8a00be7802b4c4
13 files changed +445 -114
apps/mobile/modules/t3-native-controls/android/build.gradle
+1
@@ -27,4 +27,5 @@ dependencies {
27 implementation project(':expo-modules-core')
28 implementation 'androidx.compose.ui:ui-android:1.10.6'
29 implementation 'androidx.compose.material3:material3-android:1.5.0-alpha17'
30 + implementation 'androidx.window:window:1.5.1'
31 }
apps/mobile/modules/t3-native-controls/android/src/main/java/expo/modules/t3nativecontrols/T3FoldPostureModule.kt new
+122
@@ -0,0 +1,122 @@
1 +package expo.modules.t3nativecontrols
2 +
3 +import android.content.Context
4 +import android.hardware.Sensor
5 +import android.hardware.SensorEvent
6 +import android.hardware.SensorEventListener
7 +import android.hardware.SensorManager
8 +import android.os.Build
9 +import androidx.window.layout.FoldingFeature
10 +import androidx.window.layout.WindowInfoTracker
11 +import expo.modules.kotlin.AppContext
12 +import expo.modules.kotlin.modules.Module
13 +import expo.modules.kotlin.modules.ModuleDefinition
14 +import expo.modules.kotlin.viewevent.EventDispatcher
15 +import expo.modules.kotlin.views.ExpoView
16 +import kotlinx.coroutines.CoroutineScope
17 +import kotlinx.coroutines.MainScope
18 +import kotlinx.coroutines.cancel
19 +import kotlinx.coroutines.launch
20 +
21 +class T3FoldPostureModule : Module() {
22 + override fun definition() = ModuleDefinition {
23 + Name("T3FoldPosture")
24 +
25 + View(T3FoldPostureView::class) {
26 + Events("onHingeChange")
27 + }
28 + }
29 +}
30 +
31 +/**
32 + * Reports a vertical hinge, in this view's dp coordinates, while the device is bent like a book.
33 + * The hinge sensor is only registered while a vertical fold is on screen.
34 + */
35 +class T3FoldPostureView(
36 + context: Context,
37 + appContext: AppContext
38 +) : ExpoView(context, appContext), SensorEventListener {
39 + private val onHingeChange by EventDispatcher()
40 + private val sensorManager = context.getSystemService(SensorManager::class.java)
41 + private val hingeSensor =
42 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
43 + sensorManager?.getDefaultSensor(Sensor.TYPE_HINGE_ANGLE)
44 + } else {
45 + null
46 + }
47 + private var scope: CoroutineScope? = null
48 + private var fold: FoldingFeature? = null
49 + private var listening = false
50 + private var bent = false
51 + private var reported: Map<String, Any>? = null
52 +
53 + override fun onAttachedToWindow() {
54 + super.onAttachedToWindow()
55 + val activity = appContext.currentActivity ?: return
56 + scope = MainScope().also { scope ->
57 + scope.launch {
58 + WindowInfoTracker.getOrCreate(activity).windowLayoutInfo(activity).collect { info ->
59 + fold = info.displayFeatures.filterIsInstance<FoldingFeature>().firstOrNull {
60 + it.orientation == FoldingFeature.Orientation.VERTICAL
61 + }
62 + listen(fold != null)
63 + report()
64 + }
65 + }
66 + }
67 + }
68 +
69 + override fun onDetachedFromWindow() {
70 + scope?.cancel()
71 + scope = null
72 + listen(false)
73 + super.onDetachedFromWindow()
74 + }
75 +
76 + override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
77 + super.onLayout(changed, left, top, right, bottom)
78 + if (changed) report()
79 + }
80 +
81 + override fun onSensorChanged(event: SensorEvent) {
82 + // Pixel foldables report the hinge in 5° steps and rest at 175° when nearly flat. Snapping at
83 + // 170° and releasing at 175° keeps a resting hinge from flapping the layout.
84 + val angle = event.values[0]
85 + bent = if (bent) angle < 175f else angle <= 170f
86 + report()
87 + }
88 +
89 + override fun onAccuracyChanged(sensor: Sensor, accuracy: Int) = Unit
90 +
91 + private fun listen(enabled: Boolean) {
92 + if (enabled == listening || hingeSensor == null) return
93 + listening = enabled
94 + if (enabled) {
95 + sensorManager.registerListener(this, hingeSensor, SensorManager.SENSOR_DELAY_UI)
96 + } else {
97 + sensorManager.unregisterListener(this)
98 + bent = false
99 + }
100 + }
101 +
102 + private fun report() {
103 + val feature = fold
104 + // Without a hinge sensor, the platform's half-opened posture is the closest signal.
105 + val aligned = feature != null &&
106 + if (hingeSensor != null) bent else feature.state == FoldingFeature.State.HALF_OPENED
107 + val hinge = if (aligned && feature != null) {
108 + val origin = IntArray(2).also { getLocationInWindow(it) }
109 + val density = resources.displayMetrics.density
110 + mapOf(
111 + "x" to (feature.bounds.left - origin[0]) / density,
112 + "windowX" to feature.bounds.left / density,
113 + "width" to feature.bounds.width() / density
114 + )
115 + } else {
116 + emptyMap()
117 + }
118 + if (hinge == reported) return
119 + reported = hinge
120 + onHingeChange(hinge)
121 + }
122 +}
apps/mobile/modules/t3-native-controls/expo-module.config.json
+2 -1
@@ -11,7 +11,8 @@
11 "modules": [
12 "expo.modules.t3nativecontrols.T3NativeControlsModule",
13 "expo.modules.t3nativecontrols.T3WorkspaceNavigationModule",
14 - "expo.modules.t3nativecontrols.T3KeyboardCommandsModule"
14 + "expo.modules.t3nativecontrols.T3KeyboardCommandsModule",
15 + "expo.modules.t3nativecontrols.T3FoldPostureModule"
16 ]
17 }
18 }
apps/mobile/src/components/ui/AndroidAnchoredMenu.tsx
+17 -15
@@ -1,11 +1,13 @@
1 import type { MenuAction, MenuComponentProps } from "@react-native-menu/menu";
2 import type { ReactNode } from "react";
3 -import { useCallback, useEffect, useRef, useState } from "react";
3 +import { use, useCallback, useEffect, useRef, useState } from "react";
4 import type { StyleProp, ViewInstance, ViewStyle } from "react-native";
5 import { BackHandler, Pressable, ScrollView, View } from "react-native";
6 import { useKeyboardState } from "react-native-keyboard-controller";
7 import Animated, { FadeIn } from "react-native-reanimated";
8
9 +import { deriveMenuHorizontalPlacement } from "../../lib/menu-placement";
10 +import { WindowHingeContext } from "../../native/window-hinge-context";
11 import { OverlayPortal } from "./OverlayPortal";
12 import { useAndroidControlSizing } from "./useAndroidControlSizing";
13 import { MenuPopup } from "./MenuPopup";
@@ -46,10 +48,7 @@ export function AndroidAnchoredMenu(props: AndroidAnchoredMenuProps) {
48 const [path, setPath] = useState<readonly MenuAction[]>([]);
49 const [rootHeight, setRootHeight] = useState<number | null>(null);
50 const [overlay, setOverlay] = useState<OverlayFrame | null>(null);
49 - const menuWidth =
50 - overlay === null
51 - ? desiredMenuWidth
52 - : Math.min(desiredMenuWidth, Math.max(0, overlay.width - 2 * SCREEN_MARGIN));
51 + const windowHinge = use(WindowHingeContext);
52 const anchorRef = useRef<ViewInstance>(null);
53 const overlayRef = useRef<ViewInstance>(null);
54
@@ -105,16 +104,17 @@ export function AndroidAnchoredMenu(props: AndroidAnchoredMenuProps) {
104 width: anchor.width,
105 height: anchor.height,
106 };
108 - const preferredLeft =
107 + const { left, width: menuWidth } =
108 local === null || overlay === null
110 - ? 0
111 - : local.x + local.width / 2 <= overlay.width / 2
112 - ? local.x
113 - : local.x + local.width - menuWidth;
114 - const left =
115 - overlay === null
116 - ? 0
117 - : Math.min(Math.max(preferredLeft, SCREEN_MARGIN), overlay.width - menuWidth - SCREEN_MARGIN);
109 + ? { left: 0, width: desiredMenuWidth }
110 + : deriveMenuHorizontalPlacement({
111 + anchorX: local.x,
112 + anchorWidth: local.width,
113 + overlayWidth: overlay.width,
114 + desiredWidth: desiredMenuWidth,
115 + margin: SCREEN_MARGIN,
116 + hinge: windowHinge && { x: windowHinge.x - overlay.x, width: windowHinge.width },
117 + });
118 // The keyboard stays up while the menu is open (in-window overlay, no
119 // focus change), so the space it covers is not usable — without this the
120 // composer-pill menus "open down" into the IME and can't be tapped.
@@ -174,7 +174,9 @@ export function AndroidAnchoredMenu(props: AndroidAnchoredMenuProps) {
174 <Pressable accessible={false} className="absolute inset-0" onPress={close} />
175 {!placeable || local === null ? null : !anchor.keyboardWasVisible ? (
176 <MenuPopup
177 - anchor={local}
177 + // Compose aligns its dropdown to the trigger's start whenever it fits, so a
178 + // trigger at the hinge-safe position keeps the menu on the anchor's side.
179 + anchor={windowHinge ? { ...local, x: left, width: menuWidth } : local}
180 menuWidth={menuWidth}
181 actions={levelActions}
182 title={props.title}
apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
+148 -97
@@ -34,7 +34,9 @@ import { AsyncResult } from "effect/reactivity";
34
35 import {
36 deriveFileInspectorPaneLayout,
37 + alignListPaneToHinge,
38 deriveLayout,
39 + type VerticalHinge,
40 deriveWorkspacePaneLayout,
41 type FileInspectorPaneLayout,
42 type Layout,
@@ -76,6 +78,8 @@ import {
78 } from "../../native/v5-workspace-context";
79
80 import { useNativeLayoutMetrics } from "../../native/native-layout-metrics";
81 +import { AndroidHingeObserver } from "../../native/AndroidHingeObserver";
82 +import { WindowHingeContext } from "../../native/window-hinge-context";
83
84 interface AdaptiveWorkspaceContextValue {
85 readonly layout: Layout;
@@ -257,12 +261,30 @@ function AdaptiveWorkspaceLayoutContent(
261 () => deriveLayout({ width: viewportWidth, height, nativeMetrics }),
262 [height, viewportWidth, nativeMetrics],
263 );
260 - const layout = baseLayout;
261 - const shouldRenderNavigationRail = Platform.OS === "android" && layout.usesSplitView;
264 + const shouldRenderNavigationRail = Platform.OS === "android" && baseLayout.usesSplitView;
265 const navigationRailWidth =
266 shouldRenderNavigationRail && showPrimarySidebar
267 ? ANDROID_WORKSPACE_RAIL_WIDTH * Math.max(1, androidControlScale)
268 : 0;
269 + const [hinge, setHinge] = useState<VerticalHinge | null>(null);
270 + const [windowHinge, setWindowHinge] = useState<VerticalHinge | null>(null);
271 + const handleHingeChange = useCallback(
272 + (next: VerticalHinge | null, nextWindow: VerticalHinge | null) => {
273 + setHinge(next);
274 + setWindowHinge(nextWindow);
275 + },
276 + [],
277 + );
278 + const layout = useMemo(
279 + () =>
280 + alignListPaneToHinge({
281 + layout: baseLayout,
282 + hinge,
283 + viewportWidth,
284 + leadingWidth: navigationRailWidth,
285 + }),
286 + [baseLayout, hinge, viewportWidth, navigationRailWidth],
287 + );
288 const width = viewportWidth - navigationRailWidth;
289 const shouldRenderPrimarySidebar = layout.usesSplitView;
290 const fileInspector = useMemo(
@@ -481,38 +503,55 @@ function AdaptiveWorkspaceLayoutContent(
503 target: contentTargetWidth,
504 sidebarVisible: panes.primarySidebarVisible,
505 width: contentTargetWidth,
506 + listPaneTarget: layout.listPaneWidth,
507 + listPaneFrom: layout.listPaneWidth,
508 revision: 0,
509 });
510 if (
511 Platform.OS === "android" &&
512 (contentSizing.viewportWidth !== viewportWidth ||
513 contentSizing.target !== contentTargetWidth ||
490 - contentSizing.sidebarVisible !== panes.primarySidebarVisible)
514 + contentSizing.sidebarVisible !== panes.primarySidebarVisible ||
515 + contentSizing.listPaneTarget !== layout.listPaneWidth)
516 ) {
517 + const sameViewport = contentSizing.viewportWidth === viewportWidth;
518 const openingSidebar =
493 - Platform.OS === "android" &&
494 - contentSizing.viewportWidth === viewportWidth &&
495 - !contentSizing.sidebarVisible &&
519 + sameViewport && !contentSizing.sidebarVisible && panes.primarySidebarVisible;
520 + // A book-posture hinge resizes the visible list pane instead of revealing it.
521 + const resizingSidebar =
522 + sameViewport &&
523 + contentSizing.sidebarVisible &&
524 panes.primarySidebarVisible &&
525 + contentSizing.listPaneTarget !== layout.listPaneWidth;
526 + const keepWide =
527 + (openingSidebar || resizingSidebar) &&
528 contentSizing.width !== null &&
529 contentTargetWidth !== null;
530 setContentSizing({
531 viewportWidth,
532 target: contentTargetWidth,
533 sidebarVisible: panes.primarySidebarVisible,
503 - width: openingSidebar
534 + // Clip the wide navigator while the sidebar opens or widens, then reflow once at the
535 + // end. Narrowing it first exposes an empty strip before the sidebar arrives.
536 + width: keepWide
537 ? Math.max(contentSizing.width ?? 0, contentTargetWidth ?? 0)
538 : contentTargetWidth,
539 + listPaneTarget: layout.listPaneWidth,
540 + // While a hinge resizes the list, its width follows the pane edge between these two.
541 + listPaneFrom: resizingSidebar ? contentSizing.listPaneTarget : layout.listPaneWidth,
542 revision: contentSizing.revision + 1,
543 });
544 }
545 const settleContentWidth = useCallback((revision: number) => {
546 setContentSizing((current) =>
511 - current.revision !== revision || current.width === current.target
547 + current.revision !== revision ||
548 + (current.width === current.target && current.listPaneFrom === current.listPaneTarget)
549 ? current
513 - : { ...current, width: current.target },
550 + : { ...current, width: current.target, listPaneFrom: current.listPaneTarget },
551 );
552 }, []);
553 + const listPaneFloor = Math.min(contentSizing.listPaneFrom ?? 0, layout.listPaneWidth ?? 0);
554 + const listPaneCeiling = Math.max(contentSizing.listPaneFrom ?? 0, layout.listPaneWidth ?? 0);
555 const contentSettledWidth = Platform.OS === "android" ? contentSizing.width : contentTargetWidth;
556 const contentRevision = contentSizing.revision;
557
@@ -541,6 +580,15 @@ function AdaptiveWorkspaceLayoutContent(
580 contentRevision,
581 ]);
582 const railAnimatedStyle = useAnimatedStyle(() => ({ width: renderedRailWidth.value }));
583 + // Showing or hiding the sidebar clips a fixed-width list. A hinge resize instead tracks the
584 + // animated edge, so the header actions slide with it rather than jumping or being covered.
585 + const listPaneGap = layout.listPaneGap ?? 0;
586 + const listPaneAnimatedStyle = useAnimatedStyle(() => ({
587 + width: Math.min(
588 + listPaneCeiling,
589 + Math.max(listPaneFloor, renderedSidebarWidth.value - listPaneGap),
590 + ),
591 + }));
592 const sidebarAnimatedStyle = useAnimatedStyle(() => ({
593 // Fading a UIKit glass ancestor can leave remounted header effects missing.
594 opacity: Platform.OS === "ios" ? 1 : Math.min(1, renderedSidebarWidth.value / 80),
@@ -667,102 +715,105 @@ function AdaptiveWorkspaceLayoutContent(
715 savedFilters={props.savedThreadListFilters}
716 >
717 <AdaptiveWorkspaceContext.Provider value={contextValue}>
670 - <View
671 - testID="adaptive-workspace-layout"
672 - className={Platform.OS === "android" ? "flex-1 flex-row bg-header" : "flex-1 flex-row"}
673 - >
674 - {shouldRenderNavigationRail ? (
675 - <Animated.View
676 - className="self-stretch overflow-hidden"
677 - accessibilityElementsHidden={navigationRailWidth === 0}
678 - importantForAccessibility={navigationRailWidth > 0 ? "auto" : "no-hide-descendants"}
679 - pointerEvents={navigationRailWidth > 0 ? "auto" : "none"}
680 - style={railAnimatedStyle}
681 - >
682 - <AndroidWorkspaceNavigation rail onSelect={revealPrimarySidebar} />
683 - </Animated.View>
684 - ) : null}
685 - {shouldRenderPrimarySidebar && layout.listPaneWidth !== null ? (
686 - <Animated.View
687 - className="self-stretch overflow-hidden"
688 - accessibilityElementsHidden={!panes.primarySidebarVisible}
689 - collapsable={false}
690 - importantForAccessibility={
691 - panes.primarySidebarVisible ? "auto" : "no-hide-descendants"
692 - }
693 - pointerEvents={panes.primarySidebarVisible ? "auto" : "none"}
694 - style={sidebarAnimatedStyle}
695 - >
696 - <View className="flex-1" style={{ width: layout.listPaneWidth }}>
697 - <RenderErrorBoundary
698 - renderFallback={(fallback) => (
699 - <RenderFailureView
700 - {...fallback}
701 - title="The sidebar couldn't be displayed"
702 - exit={{ label: "Open settings", onPress: handleOpenSettings }}
703 - />
704 - )}
705 - >
706 - <AndroidWorkspaceSidebar
707 - onRequestVisibility={revealPrimarySidebar}
708 - selectedPullRequestKey={props.selectedPullRequestKey ?? null}
709 - >
710 - <AndroidHomeFabLayout sidebar onStartNewTask={handleStartNewTask}>
711 - <ThreadNavigationSidebar
712 - width={layout.listPaneWidth}
713 - visible={panes.primarySidebarVisible}
714 - onRequestVisibility={revealPrimarySidebar}
715 - selectedThreadKey={selectedThreadKey}
716 - onOpenSettings={handleOpenSettings}
717 - onOpenEnvironmentSettings={handleOpenEnvironmentSettings}
718 - onNewThreadInProject={handleNewThreadInProject}
719 - onNewThreadOnBranch={handleNewThreadOnBranch}
720 - onSelectThread={handleSelectThread}
721 - onSearchQueryChange={setPrimarySidebarSearchQuery}
722 - searchQuery={primarySidebarSearchQuery}
723 - />
724 - </AndroidHomeFabLayout>
725 - </AndroidWorkspaceSidebar>
726 - </RenderErrorBoundary>
727 - </View>
728 - </Animated.View>
729 - ) : null}
718 + <WindowHingeContext value={windowHinge}>
719 <View
731 - className={
732 - Platform.OS === "android"
733 - ? "flex-1 overflow-hidden bg-header"
734 - : "flex-1 overflow-hidden bg-screen"
735 - }
736 - collapsable={false}
720 + testID="adaptive-workspace-layout"
721 + className={Platform.OS === "android" ? "flex-1 flex-row bg-header" : "flex-1 flex-row"}
722 >
723 + <AndroidHingeObserver onChange={handleHingeChange} />
724 + {shouldRenderNavigationRail ? (
725 + <Animated.View
726 + className="self-stretch overflow-hidden"
727 + accessibilityElementsHidden={navigationRailWidth === 0}
728 + importantForAccessibility={navigationRailWidth > 0 ? "auto" : "no-hide-descendants"}
729 + pointerEvents={navigationRailWidth > 0 ? "auto" : "none"}
730 + style={railAnimatedStyle}
731 + >
732 + <AndroidWorkspaceNavigation rail onSelect={revealPrimarySidebar} />
733 + </Animated.View>
734 + ) : null}
735 + {shouldRenderPrimarySidebar && layout.listPaneWidth !== null ? (
736 + <Animated.View
737 + className="self-stretch overflow-hidden"
738 + accessibilityElementsHidden={!panes.primarySidebarVisible}
739 + collapsable={false}
740 + importantForAccessibility={
741 + panes.primarySidebarVisible ? "auto" : "no-hide-descendants"
742 + }
743 + pointerEvents={panes.primarySidebarVisible ? "auto" : "none"}
744 + style={sidebarAnimatedStyle}
745 + >
746 + <Animated.View className="flex-1" style={listPaneAnimatedStyle}>
747 + <RenderErrorBoundary
748 + renderFallback={(fallback) => (
749 + <RenderFailureView
750 + {...fallback}
751 + title="The sidebar couldn't be displayed"
752 + exit={{ label: "Open settings", onPress: handleOpenSettings }}
753 + />
754 + )}
755 + >
756 + <AndroidWorkspaceSidebar
757 + onRequestVisibility={revealPrimarySidebar}
758 + selectedPullRequestKey={props.selectedPullRequestKey ?? null}
759 + >
760 + <AndroidHomeFabLayout sidebar onStartNewTask={handleStartNewTask}>
761 + <ThreadNavigationSidebar
762 + width={layout.listPaneWidth}
763 + visible={panes.primarySidebarVisible}
764 + onRequestVisibility={revealPrimarySidebar}
765 + selectedThreadKey={selectedThreadKey}
766 + onOpenSettings={handleOpenSettings}
767 + onOpenEnvironmentSettings={handleOpenEnvironmentSettings}
768 + onNewThreadInProject={handleNewThreadInProject}
769 + onNewThreadOnBranch={handleNewThreadOnBranch}
770 + onSelectThread={handleSelectThread}
771 + onSearchQueryChange={setPrimarySidebarSearchQuery}
772 + searchQuery={primarySidebarSearchQuery}
773 + />
774 + </AndroidHomeFabLayout>
775 + </AndroidWorkspaceSidebar>
776 + </RenderErrorBoundary>
777 + </Animated.View>
778 + </Animated.View>
779 + ) : null}
780 <View
739 - collapsable={false}
740 - style={
741 - contentSettledWidth !== null
742 - ? {
743 - flex: 1,
744 - width: contentSettledWidth,
745 - }
746 - : { flex: 1 }
781 + className={
782 + Platform.OS === "android"
783 + ? "flex-1 overflow-hidden bg-header"
784 + : "flex-1 overflow-hidden bg-screen"
785 }
786 + collapsable={false}
787 >
749 - <WorkspaceContentWidthContext
750 - value={layout.usesSplitView ? renderedContentWidth : null}
788 + <View
789 + collapsable={false}
790 + style={
791 + contentSettledWidth !== null
792 + ? {
793 + flex: 1,
794 + width: contentSettledWidth,
795 + }
796 + : { flex: 1 }
797 + }
798 >
752 - {props.children}
753 - </WorkspaceContentWidthContext>
799 + <WorkspaceContentWidthContext
800 + value={layout.usesSplitView ? renderedContentWidth : null}
801 + >
802 + {props.children}
803 + </WorkspaceContentWidthContext>
804 + </View>
805 </View>
806 + <WorkspaceInspectorPane
807 + pathname={props.pathname}
808 + renderedInspectorWidth={renderedInspectorWidth}
809 + active={workspaceInspector?.active ?? false}
810 + panes={panes}
811 + renderInspector={workspaceInspector?.render}
812 + setAuxiliaryPaneWidth={setAuxiliaryPaneWidth}
813 + onClosed={handleWorkspaceInspectorClosed}
814 + />
815 </View>
756 - <WorkspaceInspectorPane
757 - pathname={props.pathname}
758 - renderedInspectorWidth={renderedInspectorWidth}
759 - active={workspaceInspector?.active ?? false}
760 - panes={panes}
761 - renderInspector={workspaceInspector?.render}
762 - setAuxiliaryPaneWidth={setAuxiliaryPaneWidth}
763 - onClosed={handleWorkspaceInspectorClosed}
764 - />
765 - </View>
816 + </WindowHingeContext>
817 </AdaptiveWorkspaceContext.Provider>
818 </HomeListOptionsProvider>
819 );
apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx
+2 -1
@@ -929,7 +929,8 @@ function ThreadNavigationSidebarPane(
929 className={
930 Platform.OS === "android" ? "flex-1 bg-header" : "flex-1 border-r border-border bg-drawer"
931 }
932 - style={{ width: props.width }}
932 + // Android fills its pane, which animates its width while a hinge resizes the split.
933 + style={Platform.OS === "android" ? undefined : { width: props.width }}
934 >
935 <View
936 className="flex-1"
apps/mobile/src/lib/layout.test.ts
+33
@@ -1,6 +1,7 @@
1 import { describe, expect, it } from "vite-plus/test";
2
3 import {
4 + alignListPaneToHinge,
5 constrainAuxiliaryPaneWidth,
6 deriveCenteredContentHorizontalPadding,
7 deriveFileInspectorPaneLayout,
@@ -384,3 +385,35 @@ describe("deriveWorkspacePaneLayout", () => {
385 });
386 });
387 });
388 +
389 +describe("alignListPaneToHinge", () => {
390 + const layout = deriveLayout({ width: 852, height: 880 });
391 +
392 + it("ends the list pane at a book-posture hinge after the rail", () => {
393 + expect(
394 + alignListPaneToHinge({
395 + layout,
396 + hinge: { x: 426, width: 0 },
397 + viewportWidth: 852,
398 + leadingWidth: 96,
399 + }),
400 + ).toMatchObject({ listPaneWidth: 330, listPaneGap: 0 });
401 + });
402 +
403 + it("keeps the default split when either side of the hinge would be too narrow", () => {
404 + const narrowList = {
405 + layout,
406 + hinge: { x: 300, width: 0 },
407 + viewportWidth: 852,
408 + leadingWidth: 96,
409 + };
410 + const narrowDetail = {
411 + layout,
412 + hinge: { x: 600, width: 0 },
413 + viewportWidth: 852,
414 + leadingWidth: 0,
415 + };
416 + expect(alignListPaneToHinge(narrowList)).toBe(layout);
417 + expect(alignListPaneToHinge(narrowDetail)).toBe(layout);
418 + });
419 +});
apps/mobile/src/lib/layout.ts
+27
@@ -131,6 +131,33 @@ export function deriveLayout(input: {
131 };
132 }
133
134 +export interface VerticalHinge {
135 + readonly x: number;
136 + readonly width: number;
137 +}
138 +
139 +/**
140 + * Moves the list/detail split onto a book-posture hinge so neither pane straddles the crease.
141 + * `leadingWidth` is chrome left of the list pane, such as the Android navigation rail.
142 + */
143 +export function alignListPaneToHinge(input: {
144 + readonly layout: Layout;
145 + readonly hinge: VerticalHinge | null;
146 + readonly viewportWidth: number;
147 + readonly leadingWidth: number;
148 +}): Layout {
149 + const { layout, hinge } = input;
150 + if (!hinge || !layout.usesSplitView) return layout;
151 + const listPaneWidth = hinge.x - input.leadingWidth;
152 + if (
153 + listPaneWidth < SPLIT_SIDEBAR_MIN_WIDTH ||
154 + input.viewportWidth - hinge.x - hinge.width < 320
155 + ) {
156 + return layout;
157 + }
158 + return { ...layout, listPaneWidth, listPaneGap: hinge.width };
159 +}
160 +
161 export function deriveWorkspacePaneLayout(input: {
162 readonly layout: Layout;
163 readonly viewportWidth: number;
apps/mobile/src/lib/menu-placement.test.ts new
+24
@@ -0,0 +1,24 @@
1 +import { describe, expect, it } from "vite-plus/test";
2 +
3 +import { deriveMenuHorizontalPlacement } from "./menu-placement";
4 +
5 +const base = { anchorWidth: 48, overlayWidth: 852, desiredWidth: 224, margin: 12 };
6 +
7 +describe("deriveMenuHorizontalPlacement", () => {
8 + it("opens toward the roomier side of the whole screen without a hinge", () => {
9 + expect(deriveMenuHorizontalPlacement({ ...base, anchorX: 300, hinge: null })).toEqual({
10 + left: 300,
11 + width: 224,
12 + });
13 + });
14 +
15 + it("keeps a menu on its anchor's side of a creased hinge", () => {
16 + // The filter button sits near the crease, so the menu right-aligns to it instead of crossing.
17 + expect(
18 + deriveMenuHorizontalPlacement({ ...base, anchorX: 340, hinge: { x: 426, width: 0 } }),
19 + ).toEqual({ left: 164, width: 224 });
20 + expect(
21 + deriveMenuHorizontalPlacement({ ...base, anchorX: 430, hinge: { x: 426, width: 0 } }),
22 + ).toEqual({ left: 438, width: 224 });
23 + });
24 +});
apps/mobile/src/lib/menu-placement.ts new
+28
@@ -0,0 +1,28 @@
1 +import type { VerticalHinge } from "./layout";
2 +
3 +/**
4 + * Places a menu beside its anchor within the screen region that holds it. A creased hinge splits
5 + * the overlay into two regions, so a menu never straddles the fold.
6 + */
7 +export function deriveMenuHorizontalPlacement(input: {
8 + readonly anchorX: number;
9 + readonly anchorWidth: number;
10 + readonly overlayWidth: number;
11 + readonly desiredWidth: number;
12 + readonly margin: number;
13 + /** In the overlay's coordinates. */
14 + readonly hinge: VerticalHinge | null;
15 +}) {
16 + const center = input.anchorX + input.anchorWidth / 2;
17 + let start = 0;
18 + let end = input.overlayWidth;
19 + if (input.hinge) {
20 + if (center < input.hinge.x) end = input.hinge.x;
21 + else start = input.hinge.x + input.hinge.width;
22 + }
23 + const width = Math.min(input.desiredWidth, Math.max(0, end - start - 2 * input.margin));
24 + const preferredLeft =
25 + center <= (start + end) / 2 ? input.anchorX : input.anchorX + input.anchorWidth - width;
26 + const left = Math.min(Math.max(preferredLeft, start + input.margin), end - width - input.margin);
27 + return { left, width };
28 +}
apps/mobile/src/native/AndroidHingeObserver.android.tsx new
+29
@@ -0,0 +1,29 @@
1 +import { requireNativeView } from "expo";
2 +import type { NativeSyntheticEvent, ViewProps } from "react-native";
3 +import type { VerticalHinge } from "../lib/layout";
4 +
5 +interface ObserverProps extends ViewProps {
6 + readonly onHingeChange: (
7 + event: NativeSyntheticEvent<Partial<VerticalHinge & { readonly windowX: number }>>,
8 + ) => void;
9 +}
10 +
11 +const Observer = requireNativeView<ObserverProps>("T3FoldPosture");
12 +
13 +/** Reports a vertical hinge in this view's coordinates while the device is bent like a book. */
14 +export function AndroidHingeObserver(props: {
15 + /** Receives the hinge in this view's coordinates and in window coordinates. */
16 + readonly onChange: (hinge: VerticalHinge | null, windowHinge: VerticalHinge | null) => void;
17 +}) {
18 + return (
19 + <Observer
20 + pointerEvents="none"
21 + onHingeChange={({ nativeEvent: { x, width, windowX } }) =>
22 + x === undefined || width === undefined || windowX === undefined
23 + ? props.onChange(null, null)
24 + : props.onChange({ x, width }, { x: windowX, width })
25 + }
26 + style={{ position: "absolute", top: 0, bottom: 0, left: 0, right: 0 }}
27 + />
28 + );
29 +}
apps/mobile/src/native/AndroidHingeObserver.tsx new
+7
@@ -0,0 +1,7 @@
1 +import type { VerticalHinge } from "../lib/layout";
2 +
3 +export function AndroidHingeObserver(_props: {
4 + readonly onChange: (hinge: VerticalHinge | null, windowHinge: VerticalHinge | null) => void;
5 +}) {
6 + return null;
7 +}
apps/mobile/src/native/window-hinge-context.ts new
+5
@@ -0,0 +1,5 @@
1 +import { createContext } from "react";
2 +import type { VerticalHinge } from "../lib/layout";
3 +
4 +/** A creased vertical hinge in window coordinates, for overlays placed in window space. */
5 +export const WindowHingeContext = createContext<VerticalHinge | null>(null);