Skip to content

Commit 269357c

Browse files
only21milcodexmaria-rcks
authored
fix(mobile): fit large thread titles in Arrange threads (#23499)
Co-authored-by: GPT-6.1 Sol <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 54c1f10 commit 269357c

3 files changed

Lines changed: 50 additions & 14 deletions

File tree

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

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell
55
import { effectiveSnoozed } from "@t3tools/client-runtime/state/thread-settled";
66
import { sortInboxThreadsByReturn } from "@t3tools/client-runtime/state/thread-inbox";
77
import { type ReactNode, useEffect, useMemo, useRef, useState } from "react";
8-
import { Animated, FlatList, Modal, Pressable, View } from "react-native";
8+
import { Animated, FlatList, Modal, Pressable, useWindowDimensions, View } from "react-native";
99
import { Gesture, GestureDetector, GestureHandlerRootView } from "react-native-gesture-handler";
1010
import Reanimated, { ReduceMotion, useAnimatedStyle, withTiming } from "react-native-reanimated";
1111
import { threadDragGapOffset } from "./threadDragGap";
@@ -14,6 +14,7 @@ import { SafeAreaProvider, SafeAreaView } from "react-native-safe-area-context";
1414
import { AppText as Text } from "../../components/ui/AppText";
1515
import { SymbolView } from "../../components/ui/AppSymbol";
1616
import { scopedThreadKey } from "../../lib/scopedEntities";
17+
import { deriveThreadArrangementSizing } from "../../lib/layout";
1718
import { environmentServerConfigsAtom } from "../../state/server";
1819
import { threadListEnvironmentsAtom } from "../../state/presentation";
1920
import { environmentThreadShells } from "../../state/threads";
@@ -39,9 +40,8 @@ import {
3940
} from "./threadListV2";
4041
import { useThreadListNow } from "./use-thread-list-now";
4142
import { useThreadListV2ShelfPreferences } from "./use-thread-list-v2-shelf-preferences";
43+
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
4244

43-
const ROW_HEIGHT = 56;
44-
const HEADER_HEIGHT = 48;
4545
const keyOf = (thread: EnvironmentThreadShell) => scopedThreadKey(thread.environmentId, thread.id);
4646
type Section = "pinned" | "active" | "snoozed" | "settled";
4747
type Destination = Exclude<ThreadMoveDestination, string>;
@@ -163,6 +163,12 @@ function DragHandle(props: {
163163
}
164164

165165
function ThreadArrangementSheet(props: { onClose: () => void }) {
166+
const { appearance } = useAppearancePreferences();
167+
const { fontScale } = useWindowDimensions();
168+
const { rowHeight, headerHeight } = deriveThreadArrangementSizing({
169+
baseFontSize: appearance.baseFontSize,
170+
fontScale,
171+
});
166172
const threads = useAtomValue(environmentThreadShells.navigationThreadShellsAtom);
167173
const configs = useAtomValue(environmentServerConfigsAtom);
168174
const listEnvironments = useAtomValue(threadListEnvironmentsAtom);
@@ -230,20 +236,20 @@ function ThreadArrangementSheet(props: { onClose: () => void }) {
230236
let offset = 0;
231237
for (const section of ["pinned", "active", "snoozed", "settled"] as const) {
232238
if (section === "snoozed" && sections[section].length === 0) continue;
233-
result.push({ key: section, section, offset, height: HEADER_HEIGHT });
234-
offset += HEADER_HEIGHT;
239+
result.push({ key: section, section, offset, height: headerHeight });
240+
offset += headerHeight;
235241
if ((section === "snoozed" || section === "settled") && !expanded[section]) continue;
236242
for (const thread of section === "settled" ? visibleSettled : sections[section]) {
237-
result.push({ key: keyOf(thread), section, thread, offset, height: ROW_HEIGHT });
238-
offset += ROW_HEIGHT;
243+
result.push({ key: keyOf(thread), section, thread, offset, height: rowHeight });
244+
offset += rowHeight;
239245
}
240246
if (section === "settled" && settledCount > visibleSettled.length) {
241-
result.push({ key: "settled-more", section, more: true, offset, height: ROW_HEIGHT });
242-
offset += ROW_HEIGHT;
247+
result.push({ key: "settled-more", section, more: true, offset, height: rowHeight });
248+
offset += rowHeight;
243249
}
244250
}
245251
return result;
246-
}, [sections, expanded, visibleSettled, settledCount]);
252+
}, [sections, expanded, visibleSettled, settledCount, rowHeight, headerHeight]);
247253
const list = useRef<FlatList<Row>>(null);
248254
const geometry = useRef({ height: 0, offset: 0 });
249255
const drag = useRef<Drag | null>(null);
@@ -261,7 +267,9 @@ function ThreadArrangementSheet(props: { onClose: () => void }) {
261267
setPreview(null);
262268
}
263269
const orderVersion = rows
264-
.map((row) => `${row.key}:${row.thread?.pinOrderKey}:${row.thread?.activeOrderKey}`)
270+
.map(
271+
(row) => `${row.key}:${row.height}:${row.thread?.pinOrderKey}:${row.thread?.activeOrderKey}`,
272+
)
265273
.join("|");
266274
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- cancels the in-progress drag gesture when the thread order changes underneath it
267275
useEffect(() => {
@@ -282,7 +290,7 @@ function ThreadArrangementSheet(props: { onClose: () => void }) {
282290
current.translation = translation;
283291
const { height, offset } = geometry.current;
284292
const y = current.startY + translation;
285-
translateY.setValue(Math.max(0, Math.min(height - ROW_HEIGHT, y - ROW_HEIGHT / 2)));
293+
translateY.setValue(Math.max(0, Math.min(height - rowHeight, y - rowHeight / 2)));
286294
const contentY = Math.max(0, y + offset);
287295
const target =
288296
latest.current.rows.find((row) => contentY < row.offset + row.height) ??
@@ -321,7 +329,7 @@ function ThreadArrangementSheet(props: { onClose: () => void }) {
321329
orderVersion,
322330
sourceSection: row.section,
323331
thread: row.thread,
324-
startY: row.offset + ROW_HEIGHT / 2 - geometry.current.offset,
332+
startY: row.offset + row.height / 2 - geometry.current.offset,
325333
translation: 0,
326334
destination: null,
327335
};
@@ -554,7 +562,7 @@ function ThreadArrangementSheet(props: { onClose: () => void }) {
554562
<Animated.View
555563
pointerEvents="none"
556564
className="absolute left-5 right-5 justify-center rounded-xl border border-border bg-screen px-4"
557-
style={{ top: 0, height: ROW_HEIGHT, transform: [{ translateY }] }}
565+
style={{ top: 0, height: rowHeight, transform: [{ translateY }] }}
558566
>
559567
<Text
560568
numberOfLines={visiblePreview.destination?.section ? 1 : 2}

‎apps/mobile/src/lib/layout.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,24 @@ import {
44
alignListPaneToHinge,
55
deriveLayout,
66
deriveThreadFeedInitialContentInset,
7+
deriveThreadArrangementSizing,
78
deriveThreadWorkLogSizing,
89
deriveWorkspacePaneLayout,
910
isPrimarySidebarPinned,
1011
} from "./layout";
1112

13+
describe("thread arrangement text sizing", () => {
14+
it("fits two title lines and section labels with combined app and system text scaling", () => {
15+
const sizing = deriveThreadArrangementSizing({ baseFontSize: 22, fontScale: 1.3 });
16+
expect(sizing.rowHeight).toBeGreaterThanOrEqual(2 * 32 * 1.3 + 10);
17+
expect(sizing.headerHeight).toBeGreaterThanOrEqual(26 * 1.3 + 24);
18+
expect(deriveThreadArrangementSizing({ baseFontSize: 16, fontScale: 1 })).toEqual({
19+
rowHeight: 56,
20+
headerHeight: 48,
21+
});
22+
});
23+
});
24+
1225
describe("thread work-log text sizing", () => {
1326
it.each([
1427
{ baseFontSize: 16, fontScale: 1.25, estimatedRowHeight: 28 },

‎apps/mobile/src/lib/layout.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ export const ANDROID_READING_MAX_WIDTH = 640;
1919
// min-h-8 uses the 14px rem configured in metro.config.js.
2020
export const THREAD_WORK_ROW_MIN_HEIGHT = 28;
2121

22+
export function deriveThreadArrangementSizing(input: {
23+
readonly baseFontSize: number;
24+
readonly fontScale: number;
25+
}) {
26+
const bodyLineHeight = scaledTypographyLineHeight(MOBILE_TYPOGRAPHY.body, input.baseFontSize);
27+
const headerLineHeight = scaledTypographyLineHeight(
28+
MOBILE_TYPOGRAPHY.footnote,
29+
input.baseFontSize,
30+
);
31+
return {
32+
rowHeight: Math.max(56, Math.ceil(2 * bodyLineHeight * input.fontScale) + 10),
33+
headerHeight: Math.max(48, Math.ceil(headerLineHeight * input.fontScale) + 24),
34+
};
35+
}
36+
2237
export function deriveThreadWorkLogSizing(input: {
2338
readonly baseFontSize: number;
2439
readonly fontScale: number;

0 commit comments

Comments
 (0)