@@ -8,6 +8,7 @@ import { SafeAreaInsetsContext, useSafeAreaInsets } from "react-native-safe-area
88import { AdaptiveWorkspaceContext , useAdaptiveWorkspaceLayout } from "./adaptive-workspace-context" ;
99import { threadSelectionDeferral } from "./deferred-navigation" ;
1010import { uuidv4 } from "../../lib/uuid" ;
11+ import { useToolbarLayout } from "../../components/ui/useToolbarLayout" ;
1112import { EnvironmentId , ThreadId , type SidebarProjectGroupingMode } from "@t3tools/contracts" ;
1213import { useAtomValue } from "@effect/atom-react" ;
1314import { NavigationContext , NavigationRouteContext , useNavigation } from "@react-navigation/native" ;
@@ -29,7 +30,11 @@ import {
2930 useWindowDimensions ,
3031 View ,
3132} from "react-native" ;
32- import { KeyboardController , useKeyboardContext } from "react-native-keyboard-controller" ;
33+ import {
34+ KeyboardController ,
35+ useKeyboardContext ,
36+ useKeyboardState ,
37+ } from "react-native-keyboard-controller" ;
3338import Animated , {
3439 runOnJS ,
3540 useAnimatedStyle ,
@@ -312,15 +317,17 @@ function AdaptiveWorkspaceLayoutContent(
312317 ! sidebarFloats &&
313318 ( composerEditing || composerKeyboardActive ) ;
314319 const keyboardProgress = useKeyboardContext ( ) . reanimated . progress ;
320+ // From the moment the keyboard starts showing until it has fully hidden. The detail pane keeps
321+ // the sidebar's room for that whole span, so on the way back the sidebar pushes the wide pane
322+ // aside instead of arriving beside one that already shrank.
323+ const keyboardOnScreen = useKeyboardState ( ( state ) => state . isVisible ) ;
315324 const shouldRenderNavigationRail =
316325 Platform . OS === "android" && baseLayout . usesSplitView && ! floatingTabsEnabled ;
317326 const enabledTabs = useEnabledNavigationTabs ( ) ;
318327 const { scale, fabSize } = useAndroidControlSizing ( ) ;
319328 const floatingTabs = floatingTabsMetrics ( enabledTabs . length + 1 , scale , fabSize ) ;
320- const navigationRailWidth =
321- shouldRenderNavigationRail && ( showPrimarySidebar || workspacePage )
322- ? ANDROID_WORKSPACE_RAIL_WIDTH
323- : 0 ;
329+ // The rail stays whether or not the sidebar shows; only the list pane comes and goes.
330+ const navigationRailWidth = shouldRenderNavigationRail ? ANDROID_WORKSPACE_RAIL_WIDTH : 0 ;
324331 const [ hinge , setHinge ] = useState < VerticalHinge | null > ( null ) ;
325332 const [ windowHinge , setWindowHinge ] = useState < VerticalHinge | null > ( null ) ;
326333 const handleHingeChange = ( next : VerticalHinge | null , nextWindow : VerticalHinge | null ) => {
@@ -655,9 +662,58 @@ function AdaptiveWorkspaceLayoutContent(
655662 : 0 ;
656663 // Android's split content is a rounded card: keep it off the screen edge like the list card.
657664 const contentEndGap = Platform . OS === "android" && layout . usesSplitView ? 4 : 0 ;
658- const contentTargetWidth = layout . usesSplitView
659- ? Math . max ( 0 , panes . contentPaneWidth - inspectorColumnTargetWidth - contentEndGap )
660- : null ;
665+ // Android's split is one strip: a sidebar slot of fixed width, then the detail pane. The
666+ // sidebar never resizes; both slide by one offset, so together they always fill the width.
667+ // The pane spans the sidebar's room too unless the sidebar has finished arriving: a sidebar on
668+ // its way in pushes the wide pane past the edge, and one leaving uncovers it.
669+ const stripSidebar =
670+ Platform . OS === "android" &&
671+ layout . usesSplitView &&
672+ layout . listPaneWidth !== null &&
673+ ! workspacePage &&
674+ ! sidebarFloats ;
675+ const sidebarSlotWidth = ( layout . listPaneWidth ?? 0 ) + ( layout . listPaneGap ?? 0 ) ;
676+ const sidebarTargetOpen = keyboardHoldsSidebar ? sidebarRestsOpen : panes . primarySidebarVisible ;
677+ const [ sidebarMotion , setSidebarMotion ] = useState ( {
678+ strip : stripSidebar ,
679+ settledOpen : sidebarTargetOpen ,
680+ } ) ;
681+ if ( sidebarMotion . strip !== stripSidebar ) {
682+ // Entering or leaving the strip (a workspace page, a fold) snaps the sidebar into place.
683+ setSidebarMotion ( { strip : stripSidebar , settledOpen : sidebarTargetOpen } ) ;
684+ } else if ( sidebarMotion . settledOpen && ! sidebarTargetOpen ) {
685+ setSidebarMotion ( { strip : stripSidebar , settledOpen : false } ) ;
686+ }
687+ const sidebarSettledOpen =
688+ sidebarMotion . strip === stripSidebar ? sidebarMotion . settledOpen : sidebarTargetOpen ;
689+ const markSidebarSettled = ( open : boolean ) =>
690+ setSidebarMotion ( ( current ) =>
691+ current . settledOpen === open ? current : { ...current , settledOpen : open } ,
692+ ) ;
693+ // The keyboard covers the sidebar's share from the moment it starts showing until it is gone.
694+ const contentSpansSidebar =
695+ stripSidebar &&
696+ ( ! sidebarSettledOpen || ! sidebarTargetOpen || ( keyboardHoldsSidebar && keyboardOnScreen ) ) ;
697+ const contentTargetWidth = ! layout . usesSplitView
698+ ? null
699+ : Math . max (
700+ 0 ,
701+ ( contentSpansSidebar ? width : panes . contentPaneWidth ) -
702+ inspectorColumnTargetWidth -
703+ contentEndGap ,
704+ ) ;
705+ // A workspace page (Usage) lays out at this width even while hidden behind another tab, so
706+ // opening it widens nothing it measured.
707+ const workspacePageWidth = ! layout . usesSplitView
708+ ? null
709+ : workspacePage
710+ ? contentTargetWidth
711+ : Math . max (
712+ 0 ,
713+ viewportWidth -
714+ ( shouldRenderNavigationRail ? ANDROID_WORKSPACE_RAIL_WIDTH : 0 ) -
715+ contentEndGap ,
716+ ) ;
661717 const [ listPaneSizing , setListPaneSizing ] = useState ( {
662718 viewportWidth,
663719 workspacePage,
@@ -773,7 +829,10 @@ function AdaptiveWorkspaceLayoutContent(
773829 // The content beside it already took its final width when the page closed.
774830 renderedSidebarWidth . set (
775831 withTiming ( targetWidth , snap ? { duration : 0 } : WORKSPACE_PANE_TIMING , ( finished ) => {
776- if ( finished && Platform . OS === "android" ) runOnJS ( settleListPane ) ( listPaneRevision ) ;
832+ if ( finished && Platform . OS === "android" ) {
833+ runOnJS ( settleListPane ) ( listPaneRevision ) ;
834+ runOnJS ( markSidebarSettled ) ( targetWidth > 0 ) ;
835+ }
777836 } ) ,
778837 ) ;
779838 } , [
@@ -789,6 +848,7 @@ function AdaptiveWorkspaceLayoutContent(
789848 renderedSidebarWidth ,
790849 renderedRailWidth ,
791850 settleListPane ,
851+ markSidebarSettled ,
792852 listPaneRevision ,
793853 workspacePage ,
794854 ] ) ;
@@ -819,24 +879,45 @@ function AdaptiveWorkspaceLayoutContent(
819879 // Showing or hiding the sidebar clips a fixed-width list. A hinge resize instead tracks the
820880 // animated edge, so the header actions slide with it rather than jumping or being covered.
821881 const listPaneGap = layout . listPaneGap ?? 0 ;
882+ const keyboardSidebarRest = sidebarRestsOpen
883+ ? ( layout . listPaneWidth ?? 0 ) + ( layout . listPaneGap ?? 0 )
884+ : 0 ;
822885 const drawnSidebarWidth = useDerivedValue (
823886 ( ) => renderedSidebarWidth . value * ( keyboardHold . value ? 1 - keyboardProgress . value : 1 ) ,
824887 ) ;
825888 const listPaneAnimatedStyle = useAnimatedStyle ( ( ) => ( {
826889 width : Math . min (
827890 listPaneCeiling ,
828- Math . max ( listPaneFloor , drawnSidebarWidth . value - listPaneGap ) ,
891+ Math . max (
892+ listPaneFloor ,
893+ ( stripSidebar ? sidebarSlotWidth : drawnSidebarWidth . value ) - listPaneGap ,
894+ ) ,
829895 ) ,
830- // Following the keyboard, the list rides the sidebar's edge like the content beside it,
831- // instead of being uncovered in place.
832- transform : [ { translateX : drawnSidebarWidth . value - renderedSidebarWidth . value } ] ,
833896 } ) ) ;
897+ // How far the strip has slid: 0 with the sidebar shown, minus its width with it gone.
898+ const stripOffset = useDerivedValue ( ( ) =>
899+ stripSidebar ? drawnSidebarWidth . value - sidebarSlotWidth : 0 ,
900+ ) ;
834901 const sidebarAnimatedStyle = useAnimatedStyle ( ( ) => ( {
835902 // Fading a UIKit glass ancestor can leave remounted header effects missing.
836903 opacity :
837- Platform . OS === "ios" || floatingTabsEnabled ? 1 : Math . min ( 1 , drawnSidebarWidth . value / 80 ) ,
838- width : drawnSidebarWidth . value ,
904+ stripSidebar || Platform . OS === "ios" || floatingTabsEnabled
905+ ? 1
906+ : Math . min ( 1 , drawnSidebarWidth . value / 80 ) ,
907+ width : stripSidebar ? sidebarSlotWidth : drawnSidebarWidth . value ,
908+ flexShrink : stripSidebar ? 0 : 1 ,
909+ transform : [ { translateX : stripOffset . value } ] ,
839910 } ) ) ;
911+ // The content keeps the width React laid it out at and rides the sidebar's edge, so a keyboard
912+ // transition relays nothing out per frame, the way UIKit animates the iOS split view.
913+ // Until React commits the wider layout, the detail card continues past its right edge, so the
914+ // strip the narrower column leaves shows the card instead of the row behind it.
915+ const contentOverhangStyle = useAnimatedStyle ( ( ) => ( {
916+ opacity : keyboardHold . value && keyboardProgress . value > 0 ? 1 : 0 ,
917+ } ) ) ;
918+ const threadHeader = useToolbarLayout ( false , composerKeyboardActive ) ;
919+ const threadHeaderHeight =
920+ threadHeader . paddingTop + threadHeader . height + threadHeader . paddingBottom ;
840921
841922 // Clip the navigator at its settled width so native headers and markdown reflow only once per pane toggle.
842923 const renderedInspectorWidth = useSharedValue ( inspectorColumnTargetWidth ) ;
@@ -851,13 +932,33 @@ function AdaptiveWorkspaceLayoutContent(
851932 ) ;
852933 // Android can resize the native row before React removes its split panes on a fold.
853934 const androidSplit = Platform . OS === "android" && layout . usesSplitView ;
854- const androidContentSlotStyle = useAnimatedStyle ( ( ) => ( {
855- width : androidSplit ? renderedContentWidth . value : ( "100%" as const ) ,
856- } ) ) ;
935+ // In the strip the column itself slides with the sidebar: Android only delivers touches inside a
936+ // parent's bounds, so content may not slide out of its column.
937+ const androidContentSlotStyle = useAnimatedStyle ( ( ) =>
938+ ! androidSplit
939+ ? { width : "100%" as const }
940+ : stripSidebar
941+ ? {
942+ // Wide enough for the pane at either width; the margin gives the sidebar's share
943+ // back to the row, so a column after it stays put while the strip slides.
944+ width : Math . max (
945+ 0 ,
946+ viewportWidth - renderedRailWidth . value - renderedInspectorWidth . value ,
947+ ) ,
948+ marginRight : - sidebarSlotWidth ,
949+ transform : [ { translateX : stripOffset . value } ] ,
950+ }
951+ : { width : renderedContentWidth . value } ,
952+ ) ;
857953 // While the sidebar animates, clip the settled navigator instead of reflowing its text every frame.
954+ // In the strip it lifts entirely: the content outgrows its column, and a cap that follows
955+ // React's width would clip the wider layout for the frame it lands.
858956 const androidNavigatorLimit = useAnimatedStyle ( ( ) => ( {
859- maxWidth :
860- androidSplit && contentTargetWidth !== null && renderedContentWidth . value < contentTargetWidth
957+ maxWidth : stripSidebar
958+ ? viewportWidth
959+ : androidSplit &&
960+ contentTargetWidth !== null &&
961+ renderedContentWidth . value < contentTargetWidth
861962 ? contentTargetWidth
862963 : ( "100%" as const ) ,
863964 } ) ) ;
@@ -902,8 +1003,10 @@ function AdaptiveWorkspaceLayoutContent(
9021003 nativeInspectorColumnWidth ( viewportWidth , width / viewportWidth ) / viewportWidth ,
9031004 ) ,
9041005 composerKeyboardActive,
1006+ keyboardHoldsSidebar,
9051007 setComposerEditing,
9061008 sidebarByOrientation,
1009+ workspacePageWidth,
9071010 } ;
9081011
9091012 const inspectorSheet = (
@@ -1009,18 +1112,15 @@ function AdaptiveWorkspaceLayoutContent(
10091112 < Animated . View
10101113 collapsable = { false }
10111114 style = { [
1012- // While the keyboard moves the sidebar, the content tracks its edge every frame so
1013- // the two land together; a settled width would jump when React commits mid-slide.
1014- keyboardHoldsSidebar
1015- ? { flex : 1 , marginRight : contentEndGap }
1016- : contentTargetWidth !== null
1017- ? {
1018- flex : 1 ,
1019- width : contentTargetWidth ,
1020- alignSelf : contentAnchor . end ? "flex-end" : "flex-start" ,
1021- marginRight : contentAnchor . end ? contentEndGap : 0 ,
1022- }
1023- : { flex : 1 } ,
1115+ contentTargetWidth !== null
1116+ ? {
1117+ flex : 1 ,
1118+ width : contentTargetWidth ,
1119+ // The strip's column is wider than the pane; the pane sits at its start.
1120+ alignSelf : contentAnchor . end && ! stripSidebar ? "flex-end" : "flex-start" ,
1121+ marginRight : contentAnchor . end && ! stripSidebar ? contentEndGap : 0 ,
1122+ }
1123+ : { flex : 1 } ,
10241124 Platform . OS === "android" ? androidNavigatorLimit : undefined ,
10251125 ] }
10261126 >
@@ -1068,6 +1168,35 @@ function AdaptiveWorkspaceLayoutContent(
10681168 </ WorkspaceSettledContentWidthContext >
10691169 </ WorkspaceContentWidthContext >
10701170 </ Animated . View >
1171+ { keyboardHoldsSidebar && contentTargetWidth !== null ? (
1172+ < >
1173+ < Animated . View
1174+ pointerEvents = "none"
1175+ className = "absolute top-0 bg-header"
1176+ style = { [
1177+ {
1178+ left : contentTargetWidth ,
1179+ width : keyboardSidebarRest + contentEndGap ,
1180+ height : threadHeaderHeight ,
1181+ } ,
1182+ contentOverhangStyle ,
1183+ ] }
1184+ />
1185+ < Animated . View
1186+ pointerEvents = "none"
1187+ className = "absolute bottom-0 rounded-tr-[28px] bg-thread-canvas"
1188+ style = { [
1189+ {
1190+ // Starts under the card's rounded corner so the two read as one card.
1191+ left : contentTargetWidth - 28 ,
1192+ width : keyboardSidebarRest + 28 ,
1193+ top : threadHeaderHeight ,
1194+ } ,
1195+ contentOverhangStyle ,
1196+ ] }
1197+ />
1198+ </ >
1199+ ) : null }
10711200 </ Animated . View >
10721201 { sidebarFloats ? (
10731202 < Animated . View
0 commit comments