Skip to content
TypeScript

fix(mobile): prevent message and composer overlap (#9195)

Julius Marminge7e9d5a7efa70
diff --git a/apps/mobile/src/features/threads/ThreadComposer.tsx b/apps/mobile/src/features/threads/ThreadComposer.tsx
index e4b34c2b022..15c0ff1b4e1 100644
--- a/apps/mobile/src/features/threads/ThreadComposer.tsx
+++ b/apps/mobile/src/features/threads/ThreadComposer.tsx
@@ -151,6 +151,11 @@ export const COMPOSER_LAYOUT_TRANSITION =
? undefined
: LinearTransition.duration(COMPOSER_TRANSITION_DURATION_MS).reduceMotion(ReduceMotion.System);
+const COMPOSER_ATTACHMENT_ENTERING =
+ Platform.OS === "android"
+ ? FadeIn.duration(160)
+ : FadeIn.delay(COMPOSER_TRANSITION_DURATION_MS).duration(160).reduceMotion(ReduceMotion.System);
+
const AnimatedGlassSurface = Animated.createAnimatedComponent(GlassSurface);
export function ComposerSurface(props: {
@@ -623,10 +628,10 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
onPickFiles={props.onPickDraftFiles}
/>
) : null}
- {isExpanded ? (
+ {isExpanded && props.draftAttachments.length > 0 ? (
<Animated.View
- className={props.draftAttachments.length > 0 ? "px-[14px] pb-2.5" : undefined}
- entering={FadeIn.duration(160)}
+ className="px-[14px] pb-2.5"
+ entering={COMPOSER_ATTACHMENT_ENTERING}
exiting={FadeOut.duration(120)}
>
<ComposerAttachmentStrip
diff --git a/apps/mobile/src/features/threads/ThreadFeed.tsx b/apps/mobile/src/features/threads/ThreadFeed.tsx
index e325245e802..e515d6f72ef 100644
--- a/apps/mobile/src/features/threads/ThreadFeed.tsx
+++ b/apps/mobile/src/features/threads/ThreadFeed.tsx
@@ -178,6 +178,10 @@ import {
import { MARKDOWN_IMAGE_MAX_WIDTH, resolveMarkdownImageDisplaySize } from "./markdownImageSize";
const WIDE_MARKDOWN_BLOCK_OPTIONS = {
+ // Native iOS blockquotes and adjacent selectable text are separate layout
+ // chunks. Giving their shrink-to-fit bubble a definite width keeps both
+ // chunks measured against the width at which UIKit draws them.
+ includeBlockquotes: Platform.OS === "ios",
includeOrderedLists: Platform.OS === "android",
} as const;
diff --git a/apps/mobile/src/lib/wideMarkdownBlocks.test.ts b/apps/mobile/src/lib/wideMarkdownBlocks.test.ts
index b0af9434c22..dd6d040300a 100644
--- a/apps/mobile/src/lib/wideMarkdownBlocks.test.ts
+++ b/apps/mobile/src/lib/wideMarkdownBlocks.test.ts
@@ -41,6 +41,14 @@ describe("hasWideMarkdownBlock", () => {
);
});
+ it("detects blockquotes only when the native renderer needs width pinning", () => {
+ expect(hasWideMarkdownBlock("> quoted", { includeBlockquotes: true })).toBe(true);
+ expect(hasWideMarkdownBlock(" > quoted", { includeBlockquotes: true })).toBe(true);
+ expect(hasWideMarkdownBlock("> quoted")).toBe(false);
+ expect(hasWideMarkdownBlock("prose > quoted", { includeBlockquotes: true })).toBe(false);
+ expect(hasWideMarkdownBlock(" > indented code", { includeBlockquotes: true })).toBe(false);
+ });
+
it("detects GFM tables", () => {
expect(hasWideMarkdownBlock("| a | b |\n| --- | --- |\n| 1 | 2 |")).toBe(true);
expect(hasWideMarkdownBlock("a | b\n:-- | --:\n1 | 2")).toBe(true);
diff --git a/apps/mobile/src/lib/wideMarkdownBlocks.ts b/apps/mobile/src/lib/wideMarkdownBlocks.ts
index 3c7279fc475..c4bd2864e47 100644
--- a/apps/mobile/src/lib/wideMarkdownBlocks.ts
+++ b/apps/mobile/src/lib/wideMarkdownBlocks.ts
@@ -1,6 +1,7 @@
/**
- * Detects markdown that the JS renderer draws as a block requiring a definite
- * user-bubble width — fenced code blocks, GFM tables, and ordered lists.
+ * Detects markdown that the renderer draws as a block requiring a definite
+ * user-bubble width: fenced code blocks, GFM tables, ordered lists, and
+ * blockquotes when requested by the caller.
*
* Fenced code blocks and tables report an intrinsic width equal to their
* widest line, which is effectively unbounded. A user bubble sizes itself
@@ -31,6 +32,7 @@ const BLOCKQUOTE_PREFIX = /^ {0,3}>[ \t]?/;
export interface WideMarkdownBlockOptions {
readonly includeOrderedLists?: boolean;
+ readonly includeBlockquotes?: boolean;
}
function stripBlockquotePrefixes(line: string): string {
@@ -41,6 +43,10 @@ function stripBlockquotePrefixes(line: string): string {
return content;
}
+function hasBlockquote(text: string): boolean {
+ return text.split("\n").some((line) => BLOCKQUOTE_PREFIX.test(line));
+}
+
function hasOrderedListItem(text: string): boolean {
let previousNonEmptyLine: string | null = null;
@@ -80,6 +86,9 @@ export function hasWideMarkdownBlock(
if (FENCED_CODE_BLOCK.test(text)) {
return true;
}
+ if (options.includeBlockquotes === true && hasBlockquote(text)) {
+ return true;
+ }
if (options.includeOrderedLists !== false && hasOrderedListItem(text)) {
return true;
}