Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions mobile/src/features/today/Today.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,20 @@ function Byline({ bot, time, unread, note, hostLabel }: { bot?: Bot; time: numbe
/** Markdown that folds to about four lines, with "More" when there is more. */
function Body({ text }: { text: string }) {
const [open, setOpen] = useState(false);
const [height, setHeight] = useState(0);
// Text measures shorter once the fold clips it, so keep the tallest height seen for this
// text: otherwise the fold clips, measures short, unclips, measures tall, and loops.
const [measured, setMeasured] = useState({ text, height: 0 });
const height = measured.text === text ? measured.height : 0;
const long = height > BODY_CLIP + 8;
const onMeasure = (next: number) =>
setMeasured((prev) => {
const base = prev.text === text ? prev.height : 0;
return next > base ? { text, height: next } : prev.text === text ? prev : { text, height: next };
});
return (
<View style={{ gap: space.xs }}>
<View style={{ maxHeight: open || !long ? undefined : BODY_CLIP, overflow: "hidden" }}>
<View onLayout={(event) => setHeight(event.nativeEvent.layout.height)}>
<View onLayout={(event) => onMeasure(event.nativeEvent.layout.height)}>
<Markdown text={text} size="small" />
</View>
</View>
Expand Down
Loading