Skip to content

Commit 6f2e48d

Browse files
fix(mobile): keep Android thread title spacing consistent (#26666)
Co-authored-by: maria-rcks <[email protected]>
1 parent 01eb339 commit 6f2e48d

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

‎apps/mobile/src/features/threads/thread-list-v2-items.tsx‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { canSnooze } from "@t3tools/client-runtime/state/thread-settled";
3131
import { threadChipCopyTarget } from "@t3tools/client-runtime/thread-reference";
3232
import type { MenuAction } from "@react-native-menu/menu";
3333
import { memo, useCallback, useMemo, useState, type ComponentProps } from "react";
34-
import { Pressable, useWindowDimensions, View } from "react-native";
34+
import { Platform, Pressable, useWindowDimensions, View } from "react-native";
3535
import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable";
3636

3737
import type { ThreadListProvider } from "../../state/thread-list-environments";
@@ -637,7 +637,12 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
637637
const metadataTypography = useScaledTextRole("label");
638638
const projectIconSize = titleTypography.fontSize * 1.25 * fontScale;
639639
const machineIconSize = metadataTypography.fontSize * fontScale;
640-
const titleLineHeight = titleTypography.lineHeight * fontScale;
640+
// Android's nonlinear system text scaling can differ from the fontScale estimate.
641+
const [androidTitleLineHeight, setTitleLineHeight] = useState(
642+
titleTypography.lineHeight * fontScale,
643+
);
644+
const titleLineHeight =
645+
Platform.OS === "android" ? androidTitleLineHeight : titleTypography.lineHeight * fontScale;
641646
const {
642647
thread,
643648
variant,
@@ -1079,6 +1084,16 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
10791084
isRegeneratingTitle && "opacity-55",
10801085
)}
10811086
numberOfLines={2}
1087+
onTextLayout={
1088+
Platform.OS === "android"
1089+
? ({ nativeEvent }) => {
1090+
const firstLine = nativeEvent.lines[0];
1091+
if (firstLine && Math.abs(firstLine.height - titleLineHeight) > 0.5) {
1092+
setTitleLineHeight(firstLine.height);
1093+
}
1094+
}
1095+
: undefined
1096+
}
10821097
>
10831098
{thread.title}
10841099
</Text>

0 commit comments

Comments
 (0)