Skip to content

Commit ca5441e

Browse files
fix(mobile): derive fixed feed row heights from the configurable text scale
The working row and work-log header heights baked in default-scale line heights; at larger base font sizes the fixed sizes went stale (review feedback on #4874). Predict them with scaledTypographyLineHeight — the same formula resolveTextScaleVariables injects into Uniwind — so the predicted and rendered heights cannot drift. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent d39ce79 commit ca5441e

3 files changed

Lines changed: 49 additions & 14 deletions

File tree

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ import { deriveCenteredContentHorizontalPadding, type LayoutVariant } from "../.
8282
import {
8383
resolveMarkdownFontSizes,
8484
resolveNativeMarkdownTypography,
85+
scaledTypographyLineHeight,
8586
} from "../../lib/appearancePreferences";
87+
import { MOBILE_TYPOGRAPHY } from "../../lib/typography";
8688
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
8789
import { useAppearanceCodeSurface } from "../settings/appearance/useAppearanceCodeSurface";
8890
import { markdownFileIconSource } from "@t3tools/mobile-markdown-text/file-icons";
@@ -124,11 +126,14 @@ function formatMessageTime(input: string): string {
124126
const FEED_ITEM_LAYOUT_DURATION_MS = 180;
125127

126128
// Pre-measurement heights for getFixedItemSize, mirroring renderFeedEntry's
127-
// classNames. Both rows hold a single text line shorter than the fixed parts,
128-
// so the height is deterministic; a drifted value costs one correction on
129+
// classNames. The fold row's min-h-11 (44px) stays taller than its single
130+
// text-sm line at every supported base font size (26px at the 22pt maximum),
131+
// so its height is a constant; a drifted value costs one correction on
129132
// measure, not a persistent offset.
130133
const TURN_FOLD_HEIGHT = 56; // min-h-11 (44) + mb-3 (12)
131-
const WORKING_ROW_HEIGHT = 40; // py-1 (8) + text-xs line (16) + mb-4 (16)
134+
// The working row has no min-height clamp — its height follows the scaled
135+
// text-xs line height (see workingRowHeight in ThreadFeed).
136+
const WORKING_ROW_VERTICAL_EXTRAS = 24; // py-1 (8) + mb-4 (16)
132137

133138
// Entering animations must only play for rows born just now — LegendList
134139
// remounts rows when they scroll back into view, and replaying an entrance for
@@ -1319,6 +1324,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
13191324
const headerMaterialVisibleRef = useRef(false);
13201325
const previousLatestTurnRef = useRef(props.latestTurn);
13211326
const { width: windowWidth } = useWindowDimensions();
1327+
const { appearance } = useAppearancePreferences();
13221328
const [viewportWidth, setViewportWidth] = useState(() =>
13231329
props.layoutVariant === "split" ? 0 : windowWidth,
13241330
);
@@ -1695,7 +1701,11 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
16951701
// scrolling up through unmeasured content corrects each row's height as it
16961702
// mounts — the feed visibly jumps. Fixed sizes make the small chrome rows
16971703
// exact; message rows stay undefined and use LegendList's per-type running
1698-
// average once one of their type has been measured.
1704+
// average once one of their type has been measured. Text-driven heights
1705+
// follow the configurable base font size via scaledTypographyLineHeight.
1706+
const workingRowHeight =
1707+
WORKING_ROW_VERTICAL_EXTRAS +
1708+
scaledTypographyLineHeight(MOBILE_TYPOGRAPHY.label, appearance.baseFontSize);
16991709
const getFixedItemSize = useCallback(
17001710
(entry: ThreadFeedEntry) => {
17011711
switch (entry.type) {
@@ -1704,18 +1714,18 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
17041714
case "work-toggle":
17051715
return WORK_GROUP_TOGGLE_HEIGHT;
17061716
case "working":
1707-
return WORKING_ROW_HEIGHT;
1717+
return workingRowHeight;
17081718
case "activity-group":
17091719
// Expanded rows append a variable detail block — fall back to
17101720
// measurement for those groups.
17111721
return entry.activities.some((activity) => expandedWorkRows[activity.id])
17121722
? undefined
1713-
: collapsedWorkLogHeight(entry.activities);
1723+
: collapsedWorkLogHeight(entry.activities, appearance.baseFontSize);
17141724
default:
17151725
return undefined;
17161726
}
17171727
},
1718-
[expandedWorkRows],
1728+
[expandedWorkRows, workingRowHeight, appearance.baseFontSize],
17191729
);
17201730

17211731
const renderItem = useCallback(

‎apps/mobile/src/features/threads/thread-work-log.tsx‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import { type AppSymbolName, SymbolView } from "../../components/AppSymbol";
33
import { LayoutAnimation, Pressable, ScrollView, useColorScheme, View } from "react-native";
44

55
import { AppText as Text } from "../../components/AppText";
6+
import { scaledTypographyLineHeight } from "../../lib/appearancePreferences";
67
import { cn } from "../../lib/cn";
78
import type { ThreadFeedActivity } from "../../lib/threadActivity";
9+
import { MOBILE_TYPOGRAPHY } from "../../lib/typography";
810
import Animated, { FadeIn } from "react-native-reanimated";
911

1012
const WORK_LOG_LAYOUT_ANIMATION = {
@@ -85,25 +87,33 @@ export function visibleWorkLogActivities(
8587
}
8688

8789
// Pre-measurement heights for the feed's getFixedItemSize. Collapsed work-log
88-
// rows are single-line (numberOfLines={1}) inside a min-height taller than the
89-
// text, so their height is deterministic. Values mirror the classNames below —
90-
// keep them in sync; a mismatch only costs a one-time correction on measure.
90+
// rows are single-line (numberOfLines={1}) inside a min-height that stays
91+
// taller than the text at every supported base font size (text-xs reaches
92+
// 23px at the 22pt maximum, under the 32px min-h-8), so row height is
93+
// deterministic. The "work log" label has no such clamp — its height follows
94+
// the scaled text-2xs line height. Values mirror the classNames below — keep
95+
// them in sync; a mismatch only costs a one-time correction on measure.
9196
const WORK_ROW_HEIGHT = 32; // min-h-8
9297
const WORK_ROW_GAP = 1; // gap-px
93-
const WORK_LOG_HEADER_HEIGHT = 18; // "work log" label: text-2xs line (16) + pb-0.5 (2)
98+
const WORK_LOG_HEADER_PADDING = 2; // pb-0.5 under the "work log" label
9499
const WORK_LOG_BOTTOM_MARGIN = 4; // mb-1
95100

96101
export const WORK_GROUP_TOGGLE_HEIGHT = 36; // min-h-8 (32) + mb-1 (4)
97102

98-
export function collapsedWorkLogHeight(activities: ReadonlyArray<ThreadFeedActivity>): number {
103+
export function collapsedWorkLogHeight(
104+
activities: ReadonlyArray<ThreadFeedActivity>,
105+
baseFontSize: number,
106+
): number {
99107
const rows = visibleWorkLogActivities(activities);
100108
if (rows.length === 0) {
101109
return 0;
102110
}
103111
const onlyToolRows = rows.every((row) => row.toolLike);
112+
const headerHeight =
113+
scaledTypographyLineHeight(MOBILE_TYPOGRAPHY.caption, baseFontSize) + WORK_LOG_HEADER_PADDING;
104114
return (
105115
WORK_LOG_BOTTOM_MARGIN +
106-
(onlyToolRows ? 0 : WORK_LOG_HEADER_HEIGHT) +
116+
(onlyToolRows ? 0 : headerHeight) +
107117
rows.length * WORK_ROW_HEIGHT +
108118
(rows.length - 1) * WORK_ROW_GAP
109119
);

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,27 @@ export function resolveTextScaleVariables(baseFontSize: number): Record<string,
198198

199199
for (const [name, role] of Object.entries(TEXT_SCALE_VARIABLE_ROLES)) {
200200
variables[name] = Math.max(8, Math.round(role.fontSize * scale));
201-
variables[`${name}--line-height`] = Math.max(10, Math.round(role.lineHeight * scale));
201+
variables[`${name}--line-height`] = scaledTypographyLineHeight(role, baseFontSize);
202202
}
203203

204204
return variables;
205205
}
206206

207+
/**
208+
* The line height a MOBILE_TYPOGRAPHY role renders at under the given base
209+
* font size — the same value resolveTextScaleVariables injects for the role's
210+
* `--text-*--line-height` variable. For layout code that must predict
211+
* text-driven heights (e.g. the thread feed's fixed item sizes) instead of
212+
* measuring them.
213+
*/
214+
export function scaledTypographyLineHeight(
215+
role: { readonly lineHeight: number },
216+
baseFontSize: number,
217+
): number {
218+
const scale = normalizeBaseFontSize(baseFontSize) / DEFAULT_BASE_FONT_SIZE;
219+
return Math.max(10, Math.round(role.lineHeight * scale));
220+
}
221+
207222
export function resolveNativeMarkdownTypography(baseFontSize: number): NativeMarkdownTypography {
208223
const fontSizes = resolveMarkdownFontSizes(baseFontSize);
209224
return {

0 commit comments

Comments
 (0)