The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 09:45 UTC
fix(mobile): composer animates between compact and multiline (#37562)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 16, 2026 at 00:02 UTC
b3eeeaac01c22d76eb628ff08f5e4b0171a79215
1 file changed
+64
-21
apps/mobile/src/features/threads/ThreadComposer.tsx
+64
-21
@@ -148,7 +148,11 @@ function collapsedEditorInset(text: ScaledTextRole): number {
148
return Math.max(0, Math.round(COLLAPSED_EDITOR_DEFAULT_INSET - shift));
149
}
150
151
-function useCompactComposerEditor(text: ScaledTextRole, value: string) {
151
+const EXPANDED_EDITOR_INSET = 14;
152
+// Room under the expanded editor for the toolbar row.
153
+const EXPANDED_EDITOR_BOTTOM = 52;
154
+
155
+function useCompactComposerEditor(text: ScaledTextRole, value: string, animate: boolean) {
156
const [contentSize, setContentSize] = useState({ width: 0, height: 0 });
157
const [compactWidth, setCompactWidth] = useState(0);
158
const contentHeight = contentSize.height;
@@ -169,27 +173,55 @@ function useCompactComposerEditor(text: ScaledTextRole, value: string) {
173
(contentHeight > text.lineHeight * 1.5 ||
174
(compactWidth > 0 && contentSize.width > compactWidth));
175
const compactRowHeight = Math.max(44, minimum);
176
+ const compactBottom = (compactRowHeight - minimum) / 2;
177
const isRTL = I18nManager.isRTL;
173
- const editorStyle = useAnimatedStyle(() => ({
174
- position: "absolute",
175
- overflow: "hidden",
176
- // The compact slot is unknown until its first layout, so the editor would draw over the + button.
177
- opacity: isExpanded || editorWidth.value > 0 ? 1 : 0,
178
- height,
179
- ...(isExpanded
180
- ? { left: 14, right: 14 }
181
- : compactEditorInsets({
182
- slotX: editorX.value,
183
- slotWidth: editorWidth.value,
184
- rowWidth: rowWidth.value,
185
- isRTL,
186
- })),
187
- // The full-width editor must move above the controls in the same frame it widens.
188
- bottom: isExpanded ? 52 : (compactRowHeight - minimum) / 2,
178
+ const expandedRowHeight = height + EXPANDED_EDITOR_BOTTOM;
179
+ const expansion = useDerivedValue(() => {
180
+ const target = isExpanded ? 1 : 0;
181
+ return animate
182
+ ? withTiming(target, {
183
+ duration: COMPOSER_TRANSITION_DURATION_MS,
184
+ reduceMotion: ReduceMotion.System,
185
+ })
186
+ : target;
187
+ });
188
+ const editorStyle = useAnimatedStyle(() => {
189
+ const compactInsets = compactEditorInsets({
190
+ slotX: editorX.value,
191
+ slotWidth: editorWidth.value,
192
+ rowWidth: rowWidth.value,
193
+ isRTL,
194
+ });
195
+ const progress = expansion.value;
196
+ // Hanging from the row top lets the text ride the growing edge and ignore the stale
197
+ // height measured while it still wrapped in the compact slot. Layout props only:
198
+ // Reanimated applies transforms frames ahead of layout, which tore the text from its frame.
199
+ return {
200
+ position: "absolute",
201
+ overflow: "hidden",
202
+ // The compact slot is unknown until its first layout, so the editor would draw over the + button.
203
+ opacity: isExpanded || editorWidth.value > 0 ? 1 : 0,
204
+ height,
205
+ top: compactBottom * (1 - progress),
206
+ left: compactInsets.left + (EXPANDED_EDITOR_INSET - compactInsets.left) * progress,
207
+ // Snapping the far edge keeps the line from rewrapping while the near edge moves.
208
+ right: isExpanded ? EXPANDED_EDITOR_INSET : compactInsets.right,
209
+ };
210
+ });
211
+ const containerStyle = useAnimatedStyle(() => ({
212
+ height: compactRowHeight + (expandedRowHeight - compactRowHeight) * expansion.value,
213
}));
214
return {
215
isExpanded,
192
- containerStyle: { height: isExpanded ? height + 52 : compactRowHeight },
216
+ containerStyle,
217
+ // The expanded toolbar takes the row the text is leaving; reveal it once the text has lifted.
218
+ // An entering animation hides it from its first frame, which a shared-value opacity cannot.
219
+ toolbarControlsEntering:
220
+ animate && isExpanded
221
+ ? FadeIn.delay(COMPOSER_TRANSITION_DURATION_MS / 2)
222
+ .duration(COMPOSER_TRANSITION_DURATION_MS / 2)
223
+ .reduceMotion(ReduceMotion.System)
224
+ : undefined,
225
editorStyle,
226
onRowLayout: (event: { nativeEvent: { layout: { width: number } } }) => {
227
rowWidth.set(event.nativeEvent.layout.width);
@@ -623,7 +655,12 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
655
const surfacePaddingVertical = usesLargeControls ? 9 : floatingSidebarComposer ? 6 : 2;
656
const [compactRowWidth, setCompactRowWidth] = useState(0);
657
const compactAttachmentLimit = compactRowWidth >= 500 ? 3 : 1;
626
- const compactEditor = useCompactComposerEditor(bodyText, draftMessage);
658
+ // Animate only while typing; a thread switch or restored draft lands in place.
659
+ const compactEditor = useCompactComposerEditor(
660
+ bodyText,
661
+ draftMessage,
662
+ Platform.OS === "ios" && isFocused,
663
+ );
664
const showsCompactDictation = isVoiceInputPresented;
665
const isToolbarVisible = isVoiceInputPresented;
666
const hasEditingAttachments =
@@ -1145,8 +1182,14 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
1182
compactEditor.isExpanded ? { flex: 1, justifyContent: "flex-end" } : undefined
1183
}
1184
>
1148
- {compactControl}
1149
- {modelControl}
1185
+ <Animated.View
1186
+ key={compactEditor.isExpanded ? "expanded" : "compact"}
1187
+ className="min-w-0 shrink flex-row items-center"
1188
+ entering={compactEditor.toolbarControlsEntering}
1189
+ >
1190
+ {compactControl}
1191
+ {modelControl}
1192
+ </Animated.View>
1193
<ComposerDictationStartAction
1194
size={usesLargeControls ? "large" : "regular"}
1195
state={voiceInput.state}