Skip to content

Commit 8e05d99

Browse files
fix(mobile): keep the conversation steady during layout changes
1 parent 1db31d0 commit 8e05d99

7 files changed

Lines changed: 305 additions & 105 deletions

File tree

‎apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx‎

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,18 @@ function AdaptiveWorkspaceLayoutContent(
829829
renderedInspectorWidth.value,
830830
),
831831
);
832+
// Android can resize the native row before React removes its split panes on a fold.
833+
const androidSplit = Platform.OS === "android" && layout.usesSplitView;
834+
const androidContentSlotStyle = useAnimatedStyle(() => ({
835+
width: androidSplit ? renderedContentWidth.value : ("100%" as const),
836+
}));
837+
// While the sidebar animates, clip the settled navigator instead of reflowing its text every frame.
838+
const androidNavigatorLimit = useAnimatedStyle(() => ({
839+
maxWidth:
840+
androidSplit && contentTargetWidth !== null && renderedContentWidth.value < contentTargetWidth
841+
? contentTargetWidth
842+
: ("100%" as const),
843+
}));
832844

833845
const handleSelectThread = (thread: EnvironmentThreadShell) => {
834846
handleSelectThreadRoute({
@@ -899,11 +911,11 @@ function AdaptiveWorkspaceLayoutContent(
899911
>
900912
<AndroidHingeObserver onChange={handleHingeChange} />
901913
{shouldRenderNavigationRail ? (
902-
<Animated.View className="self-stretch" style={railAnimatedStyle} />
914+
<Animated.View className="shrink self-stretch" style={railAnimatedStyle} />
903915
) : null}
904916
{shouldRenderPrimarySidebar && layout.listPaneWidth !== null ? (
905917
<Animated.View
906-
className="self-stretch overflow-hidden"
918+
className="self-stretch overflow-hidden android:shrink"
907919
accessibilityElementsHidden={workspacePage || !panes.primarySidebarVisible}
908920
collapsable={false}
909921
importantForAccessibility={
@@ -967,26 +979,28 @@ function AdaptiveWorkspaceLayoutContent(
967979
</Animated.View>
968980
</Animated.View>
969981
) : null}
970-
<View
982+
<Animated.View
971983
className={
972984
Platform.OS === "android"
973-
? "flex-1 overflow-hidden bg-header"
985+
? "max-w-full shrink-0 overflow-hidden bg-header"
974986
: "flex-1 overflow-hidden bg-screen"
975987
}
988+
style={Platform.OS === "android" ? androidContentSlotStyle : undefined}
976989
collapsable={false}
977990
>
978-
<View
991+
<Animated.View
979992
collapsable={false}
980-
style={
993+
style={[
981994
contentTargetWidth !== null
982995
? {
983996
flex: 1,
984997
width: contentTargetWidth,
985998
alignSelf: contentAnchor.end ? "flex-end" : "flex-start",
986999
marginRight: contentAnchor.end ? contentEndGap : 0,
9871000
}
988-
: { flex: 1 }
989-
}
1001+
: { flex: 1 },
1002+
Platform.OS === "android" ? androidNavigatorLimit : undefined,
1003+
]}
9901004
>
9911005
{/* Android holds the content still, so its floating controls keep its width. */}
9921006
<WorkspaceContentWidthContext
@@ -1029,8 +1043,8 @@ function AdaptiveWorkspaceLayoutContent(
10291043
) : null}
10301044
</WorkspaceSettledContentWidthContext>
10311045
</WorkspaceContentWidthContext>
1032-
</View>
1033-
</View>
1046+
</Animated.View>
1047+
</Animated.View>
10341048
<WorkspaceInspectorPane
10351049
pathname={props.pathname}
10361050
renderedInspectorWidth={renderedInspectorWidth}
@@ -1041,11 +1055,14 @@ function AdaptiveWorkspaceLayoutContent(
10411055
onClosed={handleWorkspaceInspectorClosed}
10421056
/>
10431057
{shouldRenderNavigationRail && navigationRailWidth > 0 ? (
1044-
// The rail reserves its slot above and draws over the panes, so it can widen over
1045-
// the list in place. It takes the whole workspace only while it is open.
1058+
// Its trailing inset clips the old rail as soon as Android fits the workspace to a cover display.
10461059
<View
1047-
className="absolute inset-y-0 left-0"
1048-
style={railOverlay ? { right: 0 } : { width: navigationRailWidth }}
1060+
className="absolute inset-y-0 left-0 overflow-hidden"
1061+
style={
1062+
railOverlay
1063+
? { right: 0 }
1064+
: { right: viewportWidth - navigationRailWidth, maxWidth: navigationRailWidth }
1065+
}
10491066
>
10501067
<AndroidWorkspaceNavigation
10511068
onNewThread={handleStartNewTask}

‎apps/mobile/src/features/threads/ComposerPopoverHost.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export function useComposerPopoverHost() {
1919
/** Mount inside KeyboardStickyView for Android gestures. Hide explicitly because portal content outlives its subtree. */
2020
export function ComposerPopoverHost(props: {
2121
readonly hidden: boolean;
22+
readonly inFlow?: boolean;
2223
readonly popoverHeight: SharedValue<number>;
2324
readonly children: ReactNode;
2425
}) {
@@ -33,8 +34,8 @@ export function ComposerPopoverHost(props: {
3334
ref={hostRef}
3435
collapsable={false}
3536
pointerEvents="box-none"
36-
className="absolute inset-0"
37-
onLayout={() => setLayoutVersion((version) => version + 1)}
37+
className={props.inFlow ? undefined : "absolute inset-0"}
38+
onLayout={props.hidden ? undefined : () => setLayoutVersion((version) => version + 1)}
3839
>
3940
{props.children}
4041
{props.hidden ? null : content}

‎apps/mobile/src/features/threads/PendingUserInputCard.tsx‎

Lines changed: 31 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,12 @@ import {
1010
import { useRef } from "react";
1111
import { Platform, Pressable, ScrollView, View, type LayoutChangeEvent } from "react-native";
1212
import Animated, {
13-
Easing,
14-
FadeInUp,
15-
FadeOutDown,
1613
useAnimatedStyle,
1714
useSharedValue,
1815
type DerivedValue,
1916
type SharedValue,
2017
} from "react-native-reanimated";
2118

22-
import { USER_INPUT_TOGGLE_DURATION_MS } from "./pendingUserInputLayout";
23-
2419
import { SymbolView } from "../../components/ui/AppSymbol";
2520
import { AppText as Text } from "../../components/ui/AppText";
2621
import { ControlPill } from "../../components/ui/ControlPill";
@@ -43,8 +38,8 @@ export interface PendingUserInputCardProps {
4338
readonly collapsed: boolean;
4439
readonly onToggleCollapsed: () => void;
4540
readonly onStopThread?: () => void;
46-
readonly cardProgress?: SharedValue<number>;
47-
readonly cardCoverage?: SharedValue<number>;
41+
readonly cardProgress: SharedValue<number>;
42+
readonly cardCoverage: SharedValue<number>;
4843
readonly onInputFocusChange?: (focused: boolean) => void;
4944
readonly drafts: Record<string, PendingUserInputDraftAnswer>;
5045
readonly answers: Record<string, string | ReadonlyArray<string>> | null;
@@ -63,9 +58,6 @@ export interface PendingUserInputCardProps {
6358
readonly onDismiss: () => Promise<unknown>;
6459
}
6560

66-
/** Android cannot hit-test overlays beyond their parent's bounds; render its expanded card in-flow. */
67-
const EXPANDED_CARD_IS_OVERLAY = Platform.OS === "ios";
68-
6961
function proseDirectionStyle(text: string, setDirection: TextDirection | undefined) {
7062
const direction = textDirection(text);
7163
return {
@@ -111,14 +103,11 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
111103
.join(" "),
112104
);
113105

114-
const cardCoverage = props.cardCoverage;
106+
const { cardCoverage, cardProgress, maxHeight } = props;
115107
const barHeightRef = useRef(0);
116108
const cardHeightRef = useRef(0);
117109
const cardHeight = useSharedValue(0);
118110
const notifyCoverage = () => {
119-
if (!cardCoverage) {
120-
return;
121-
}
122111
// The card resizes with the keyboard every frame, so easing each sample would leave the
123112
// feed inset and floating controls trailing it.
124113
cardCoverage.set(Math.max(0, cardHeightRef.current - barHeightRef.current));
@@ -132,22 +121,25 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
132121
cardHeight.set(event.nativeEvent.layout.height);
133122
notifyCoverage();
134123
};
135-
const cardProgress = props.cardProgress;
136-
const maxHeight = props.maxHeight;
137124
const cardAnimatedStyle = useAnimatedStyle(() => {
138-
const progress = cardProgress === undefined ? 1 : cardProgress.value;
125+
const progress = cardProgress.value;
126+
const travel = Platform.OS === "android" ? cardCoverage.value : cardHeight.value;
139127
return {
140128
maxHeight: maxHeight.value,
141-
transform: [{ translateY: (1 - progress) * cardHeight.value }],
129+
opacity:
130+
Platform.OS === "android"
131+
? Math.min(1, (progress * cardHeight.value) / Math.max(1, cardHeight.value - travel))
132+
: 1,
133+
transform: [{ translateY: (1 - progress) * travel }],
142134
};
143135
});
144-
const cardMaxHeightStyle = useAnimatedStyle(() => ({ maxHeight: maxHeight.value }));
136+
// Android hit-tests inside the parent; its height is also the space the card takes below the feed.
137+
const androidBoundsStyle = useAnimatedStyle(() => ({
138+
paddingTop: cardCoverage.value * cardProgress.value,
139+
}));
145140
const overlayHeightStyle = useAnimatedStyle(() => ({ height: maxHeight.value }));
146141

147-
// Keep the iOS card mounted so expansion starts on the UI thread without waiting for React layout.
148-
const renderCard = EXPANDED_CARD_IS_OVERLAY || !props.collapsed;
149-
const showBar = props.collapsed || EXPANDED_CARD_IS_OVERLAY;
150-
const bar = showBar ? (
142+
const bar = (
151143
<View
152144
onLayout={handleBarLayout}
153145
pointerEvents={props.collapsed ? "auto" : "none"}
@@ -188,25 +180,15 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
188180
/>
189181
) : null}
190182
</View>
191-
) : null;
192-
const card = renderCard ? (
183+
);
184+
const card = (
193185
<Animated.View
194186
onLayout={handleCardLayout}
195187
pointerEvents={props.collapsed ? "none" : "auto"}
196188
accessibilityElementsHidden={props.collapsed}
197189
importantForAccessibility={props.collapsed ? "no-hide-descendants" : "auto"}
198-
entering={
199-
EXPANDED_CARD_IS_OVERLAY
200-
? undefined
201-
: FadeInUp.duration(USER_INPUT_TOGGLE_DURATION_MS).easing(Easing.out(Easing.cubic))
202-
}
203-
exiting={
204-
EXPANDED_CARD_IS_OVERLAY
205-
? undefined
206-
: FadeOutDown.duration(USER_INPUT_TOGGLE_DURATION_MS).easing(Easing.out(Easing.cubic))
207-
}
208190
className="overflow-hidden gap-2.5 rounded-[20px] border border-border bg-card-alt p-4"
209-
style={EXPANDED_CARD_IS_OVERLAY ? cardAnimatedStyle : cardMaxHeightStyle}
191+
style={cardAnimatedStyle}
210192
>
211193
<Pressable
212194
accessibilityRole="button"
@@ -345,21 +327,20 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
345327
</Text>
346328
) : null}
347329
</Animated.View>
348-
) : null;
330+
);
349331
return (
350-
<View className="relative">
332+
<Animated.View
333+
className="relative"
334+
style={Platform.OS === "android" ? androidBoundsStyle : undefined}
335+
>
351336
{bar}
352-
{EXPANDED_CARD_IS_OVERLAY ? (
353-
<Animated.View
354-
pointerEvents={props.collapsed ? "none" : "box-none"}
355-
className="absolute inset-x-0 bottom-0 justify-end overflow-hidden"
356-
style={overlayHeightStyle}
357-
>
358-
{card}
359-
</Animated.View>
360-
) : (
361-
card
362-
)}
363-
</View>
337+
<Animated.View
338+
pointerEvents={props.collapsed ? "none" : "box-none"}
339+
className="absolute inset-x-0 bottom-0 justify-end overflow-hidden"
340+
style={overlayHeightStyle}
341+
>
342+
{card}
343+
</Animated.View>
344+
</Animated.View>
364345
);
365346
}

0 commit comments

Comments
 (0)