Skip to content

Commit 32ea1a1

Browse files
S3333Fmaria-rcks
andauthored
fix(mobile): keep the composer text box off the model button on RTL phones (#26090)
Co-authored-by: maria-rcks <[email protected]>
1 parent f56a477 commit 32ea1a1

3 files changed

Lines changed: 45 additions & 3 deletions

File tree

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
import { StackActions, useFocusEffect, useNavigation } from "@react-navigation/native";
3333
import type { ReactNode } from "react";
3434
import { useEffect, useEffectEvent, useRef, useState, type RefObject } from "react";
35-
import { Keyboard, Platform, View, type ViewStyle } from "react-native";
35+
import { I18nManager, Keyboard, Platform, View, type ViewStyle } from "react-native";
3636
import { composerImageGallery } from "../../lib/composerImageGallery";
3737
import { filePreviewGallery } from "../../lib/filePreviewGallery";
3838
import { FilePreviewModal, type FilePreviewSource } from "../../components/FilePreviewModal";
@@ -97,6 +97,7 @@ import {
9797
resolveComposerSendPresentation,
9898
type ComposerSendPresentation,
9999
} from "./composerSendPresentation";
100+
import { compactEditorInsets } from "./compactEditorInsets";
100101
import { ComposerCommandPopover } from "./ComposerCommandPopover";
101102
import { ComposerPopoverAnchor } from "./ComposerPopoverAnchor";
102103
import { ComposerQueuedEditAttachments } from "./ComposerQueuedEdit";
@@ -157,12 +158,19 @@ function useCompactComposerEditor(text: ScaledTextRole, value: string) {
157158
(contentHeight > text.lineHeight * 1.5 ||
158159
(compactWidth > 0 && contentSize.width > compactWidth));
159160
const compactRowHeight = Math.max(44, minimum);
161+
const isRTL = I18nManager.isRTL;
160162
const editorStyle = useAnimatedStyle(() => ({
161163
position: "absolute",
162164
overflow: "hidden",
163165
height,
164-
left: isExpanded ? 14 : editorX.value + 4,
165-
right: isExpanded ? 14 : rowWidth.value - editorX.value - editorWidth.value + 4,
166+
...(isExpanded
167+
? { left: 14, right: 14 }
168+
: compactEditorInsets({
169+
slotX: editorX.value,
170+
slotWidth: editorWidth.value,
171+
rowWidth: rowWidth.value,
172+
isRTL,
173+
})),
166174
// The full-width editor must move above the controls in the same frame it widens.
167175
bottom: isExpanded ? 52 : (compactRowHeight - minimum) / 2,
168176
}));
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { describe, expect, it } from "vite-plus/test";
2+
3+
import { compactEditorInsets } from "./compactEditorInsets";
4+
5+
describe("compact editor insets", () => {
6+
it("keeps the measured slot position in left-to-right layouts", () => {
7+
expect(compactEditorInsets({ slotX: 48, slotWidth: 200, rowWidth: 360, isRTL: false })).toEqual(
8+
{ left: 52, right: 116 },
9+
);
10+
});
11+
12+
it("swaps the insets in right-to-left layouts so the editor stays over its slot", () => {
13+
expect(compactEditorInsets({ slotX: 112, slotWidth: 200, rowWidth: 360, isRTL: true })).toEqual(
14+
{ left: 52, right: 116 },
15+
);
16+
});
17+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const COMPACT_EDITOR_SLOT_INSET = 4;
2+
3+
/**
4+
* Places the floating editor over its slot. Layout x is measured from the left,
5+
* but React Native swaps left and right styles in RTL, so the insets trade places.
6+
*/
7+
export function compactEditorInsets(input: {
8+
readonly slotX: number;
9+
readonly slotWidth: number;
10+
readonly rowWidth: number;
11+
readonly isRTL: boolean;
12+
}): { left: number; right: number } {
13+
"worklet";
14+
const fromLeft = input.slotX + COMPACT_EDITOR_SLOT_INSET;
15+
const fromRight = input.rowWidth - input.slotX - input.slotWidth + COMPACT_EDITOR_SLOT_INSET;
16+
return input.isRTL ? { left: fromRight, right: fromLeft } : { left: fromLeft, right: fromRight };
17+
}

0 commit comments

Comments
 (0)