Skip to content
TypeScript

fix(android): fold tracking starts late and hinge retargets keep the edge (#20403)

Alex86ac54512ad5
diff --git a/apps/mobile/modules/t3-native-controls/android/src/main/java/expo/modules/t3nativecontrols/T3FoldPostureModule.kt b/apps/mobile/modules/t3-native-controls/android/src/main/java/expo/modules/t3nativecontrols/T3FoldPostureModule.kt
index 7646f2e678c..c2169dabdc1 100644
--- a/apps/mobile/modules/t3-native-controls/android/src/main/java/expo/modules/t3nativecontrols/T3FoldPostureModule.kt
+++ b/apps/mobile/modules/t3-native-controls/android/src/main/java/expo/modules/t3nativecontrols/T3FoldPostureModule.kt
@@ -52,6 +52,12 @@ class T3FoldPostureView(
override fun onAttachedToWindow() {
super.onAttachedToWindow()
+ observeFold()
+ }
+
+ // The activity can be missing when the view first attaches, so layout passes retry.
+ private fun observeFold() {
+ if (scope != null || !isAttachedToWindow) return
val activity = appContext.currentActivity ?: return
scope = MainScope().also { scope ->
scope.launch {
@@ -75,6 +81,7 @@ class T3FoldPostureView(
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
super.onLayout(changed, left, top, right, bottom)
+ observeFold()
if (changed) report()
}
diff --git a/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx b/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
index d316ddbcb02..931f8551825 100644
--- a/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
+++ b/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
@@ -504,7 +504,8 @@ function AdaptiveWorkspaceLayoutContent(
sidebarVisible: panes.primarySidebarVisible,
width: contentTargetWidth,
listPaneTarget: layout.listPaneWidth,
- listPaneFrom: layout.listPaneWidth,
+ listPaneFloor: layout.listPaneWidth,
+ listPaneCeiling: layout.listPaneWidth,
revision: 0,
});
if (
@@ -537,21 +538,34 @@ function AdaptiveWorkspaceLayoutContent(
? Math.max(contentSizing.width ?? 0, contentTargetWidth ?? 0)
: contentTargetWidth,
listPaneTarget: layout.listPaneWidth,
- // While a hinge resizes the list, its width follows the pane edge between these two.
- listPaneFrom: resizingSidebar ? contentSizing.listPaneTarget : layout.listPaneWidth,
+ // While a hinge resizes the list, its width follows the pane edge within this span. A
+ // retarget mid-animation widens the span, since the edge is still somewhere inside it.
+ listPaneFloor: resizingSidebar
+ ? Math.min(contentSizing.listPaneFloor ?? 0, layout.listPaneWidth ?? 0)
+ : layout.listPaneWidth,
+ listPaneCeiling: resizingSidebar
+ ? Math.max(contentSizing.listPaneCeiling ?? 0, layout.listPaneWidth ?? 0)
+ : layout.listPaneWidth,
revision: contentSizing.revision + 1,
});
}
const settleContentWidth = useCallback((revision: number) => {
setContentSizing((current) =>
current.revision !== revision ||
- (current.width === current.target && current.listPaneFrom === current.listPaneTarget)
+ (current.width === current.target &&
+ current.listPaneFloor === current.listPaneTarget &&
+ current.listPaneCeiling === current.listPaneTarget)
? current
- : { ...current, width: current.target, listPaneFrom: current.listPaneTarget },
+ : {
+ ...current,
+ width: current.target,
+ listPaneFloor: current.listPaneTarget,
+ listPaneCeiling: current.listPaneTarget,
+ },
);
}, []);
- const listPaneFloor = Math.min(contentSizing.listPaneFrom ?? 0, layout.listPaneWidth ?? 0);
- const listPaneCeiling = Math.max(contentSizing.listPaneFrom ?? 0, layout.listPaneWidth ?? 0);
+ const listPaneFloor = contentSizing.listPaneFloor ?? 0;
+ const listPaneCeiling = contentSizing.listPaneCeiling ?? 0;
const contentSettledWidth = Platform.OS === "android" ? contentSizing.width : contentTargetWidth;
const contentRevision = contentSizing.revision;