Skip to content

Commit 8ab9c12

Browse files
juliusmarmingePixPMusicclaude
committed
fix(mobile): the composer measures wrapped drafts on iOS
With scrolling off in the focused row, UIKit laid out only the first line, so a wrapping draft never moved to the card, and once in the card the used rect spanned the container, so it never came back. The focused row scrolls again, and both editors report a width only for a one-line draft, taken from its line fragment. The picker's width transition is iOS-only, since the Android composer runs no layout transitions. Co-authored-by: Pixel Perfect <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 9385a2e commit 8ab9c12

4 files changed

Lines changed: 27 additions & 21 deletions

File tree

‎apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -425,18 +425,13 @@ class T3ComposerEditorView(context: Context, appContext: AppContext) : ExpoView(
425425
}
426426

427427
private fun emitContentSizeIfNeeded() {
428-
// The laid-out text without insets. The widest line is the draft's natural width
429-
// when it fits one line, which lets JS tell whether it fits a narrower row than
430-
// the one it is laid out in. Trailing whitespace hangs past a line without
431-
// wrapping it, so it is left out of the width.
428+
// The laid-out text without insets. A one-line draft reports its natural width, so
429+
// JS can tell whether it fits a narrower row than the one it is laid out in; past
430+
// one line only the height matters. Trailing whitespace hangs past a line without
431+
// wrapping it, so getLineMax leaves it out.
432432
val layout = editor.layout
433433
val contentHeight = layout?.height ?: editor.measuredHeight
434-
val contentWidth =
435-
if (layout == null || layout.lineCount == 0) {
436-
0
437-
} else {
438-
(0 until layout.lineCount).maxOf { layout.getLineMax(it) }.toInt()
439-
}
434+
val contentWidth = if (layout?.lineCount == 1) layout.getLineMax(0).toInt() else 0
440435
if (contentHeight == lastContentHeight && contentWidth == lastContentWidth) return
441436
lastContentHeight = contentHeight
442437
lastContentWidth = contentWidth

‎apps/mobile/modules/t3-composer-editor/ios/T3ComposerEditorView.swift‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,19 +1219,28 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
12191219
}
12201220

12211221
private func emitContentSizeIfNeeded() {
1222-
// The laid-out text without insets: the widest line and the stacked lines. One
1223-
// line's width is the draft's natural width, which lets JS tell whether the draft
1224-
// fits a narrower row than the one it is laid out in. A trailing newline's empty
1225-
// line is not part of the used rect, so it is added from the extra fragment.
1222+
// The laid-out text without insets. A one-line draft reports its natural width, so
1223+
// JS can tell whether it fits a narrower row than the one it is laid out in; past
1224+
// one line only the height matters, so layout stops at the second line. The width
1225+
// comes from the line fragment because usedRect spans the container once the view
1226+
// scrolls. A trailing newline's empty line only exists as the extra fragment.
12261227
let layout = textView.layoutManager
12271228
let container = textView.textContainer
1228-
layout.ensureLayout(for: container)
1229-
let used = layout.usedRect(for: container)
1230-
var height = used.height
1231-
if layout.extraLineFragmentTextContainer === container {
1229+
var lines = 0
1230+
var width: CGFloat = 0
1231+
var height: CGFloat = 0
1232+
let glyphs = NSRange(location: 0, length: layout.numberOfGlyphs)
1233+
layout.enumerateLineFragments(forGlyphRange: glyphs) { _, used, _, _, stop in
1234+
lines += 1
1235+
width = used.width
1236+
height = used.maxY
1237+
if lines > 1 { stop.pointee = true }
1238+
}
1239+
if lines < 2, layout.extraLineFragmentTextContainer === container {
1240+
lines += 1
12321241
height = max(height, layout.extraLineFragmentUsedRect.maxY)
12331242
}
1234-
let nextSize = CGSize(width: ceil(used.width), height: ceil(height))
1243+
let nextSize = CGSize(width: lines == 1 ? ceil(width) : 0, height: ceil(height))
12351244
guard abs(nextSize.width - lastContentSize.width) > 0.5 ||
12361245
abs(nextSize.height - lastContentSize.height) > 0.5 else {
12371246
return

‎apps/mobile/src/components/ComposerToolbar.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ const COMPOSER_TOOLBAR_FADE_WIDTH = 18;
2525
const COMPOSER_TOOLBAR_SCROLL_EPSILON = 4;
2626
const INLINE_CONTROL_LABEL_ENTERING = FadeIn.duration(160);
2727
const INLINE_CONTROL_LABEL_EXITING = FadeOut.duration(120);
28-
const INLINE_CONTROL_WIDTH_TRANSITION = LinearTransition.duration(180);
28+
// Android runs no composer layout transitions, so the toolbar never trails the dock.
29+
const INLINE_CONTROL_WIDTH_TRANSITION =
30+
Platform.OS === "android" ? undefined : LinearTransition.duration(180);
2931

3032
export function ComposerInlineControl(props: {
3133
readonly accessibilityHint?: string;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
10371037
? sendPresentation.label
10381038
: FOLLOW_UP_ACTION_LABEL[sendPresentation.alternate]
10391039
}
1040-
scrollEnabled={usesCard}
1040+
scrollEnabled={isExpanded}
10411041
singleLineCentered={!usesCard}
10421042
contentInsetVertical={usesCard || Platform.OS === "android" ? 0 : 6}
10431043
onContentSizeChange={(size) => {

0 commit comments

Comments
 (0)