From 5fcb78e6963727dcd7af29d5f2c56c8c619759d1 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 03:24:55 +0000 Subject: [PATCH 1/5] Fill the composer sheet with the field, and float mentions over it The sheet's field stopped at eight lines with its own scroll bar, inside a scroll view, with empty space under it. Now nothing scrolls but the field. It gets as many lines as fit between the author row and the toolbar, less whatever sits under it: photos, the poll editor, the quoted commit or the schedule box. ComposerSheet works those heights out, since neither platform tells PHP how tall the sheet is and mobile-ui's multiline field sizes itself in lines rather than to the space it's given. The mention list is no longer in the layout. It floats over the field and the quoted commit, on Liquid Glass on iOS and a raised surface on Android, from just under the caret's line down to the toolbar, and scrolls inside. The caret's line is estimated from the text before it, wrapped at the field's width, because the field doesn't report where the caret is drawn. Each part of the sheet has a keyed slot that is always drawn, so the field keeps its id and its place among its siblings and the keyboard stays up. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/ComposerSheet.php | 190 ++++++++++++++++++ .../native/partials/commit-sheet.blade.php | 162 ++++++++++----- tests/Feature/Screens/CommitMentionsTest.php | 33 +++ tests/Feature/Screens/ComposeSheetTest.php | 40 ++++ tests/Feature/Screens/ComposerPhotosTest.php | 4 +- tests/Feature/Screens/QuoteTest.php | 12 ++ tests/Unit/Devnull/ComposerSheetTest.php | 41 ++++ 7 files changed, 428 insertions(+), 54 deletions(-) create mode 100644 app/Devnull/ComposerSheet.php create mode 100644 tests/Unit/Devnull/ComposerSheetTest.php diff --git a/app/Devnull/ComposerSheet.php b/app/Devnull/ComposerSheet.php new file mode 100644 index 00000000..b3f3dc7d --- /dev/null +++ b/app/Devnull/ComposerSheet.php @@ -0,0 +1,190 @@ + $above + * @param list $below + */ + public static function fieldLines(array $above, array $below): int + { + $parts = [...array_filter($above), ...array_filter($below)]; + $free = self::BodyHeight - self::TopPadding - self::BottomPadding - array_sum($parts) - count($parts) * self::Gap; + + return max(self::MinFieldLines, intdiv($free, self::FieldLineHeight)); + } + + /** + * The height of the space under the stack above the field: the field and what's under it, where the mention list + * floats. + * + * @param list $above + */ + public static function bodyHeight(array $above): int + { + $above = array_filter($above); + + return self::BodyHeight - array_sum($above) - count($above) * self::Gap; + } + + /** + * Which of the field's shown lines the caret is on, from the top, counting from 0: the text before it, wrapped a + * word at a time at the field's width. Past the last line shown, the field has scrolled to keep the caret in + * view, so it's on the last. + */ + public static function caretLine(string $text, int $caret, int $shownLines, bool $ios = true): int + { + $perLine = $ios ? self::IosCharactersPerLine : self::AndroidCharactersPerLine; + $lines = 0; + + foreach (explode("\n", mb_substr($text, 0, max(0, $caret))) as $paragraph) { + $lines += self::wrappedLines($paragraph, $perLine); + } + + return min(max(0, $lines - 1), max(0, $shownLines - 1)); + } + + /** + * Where the mention list's top goes in the space under the stack: just under the caret's line, or higher when + * that would leave it room for fewer than three people. + */ + public static function mentionTop(int $caretLine, int $bodyHeight): int + { + $underCaret = self::TopPadding + ($caretLine + 1) * self::FieldLineHeight + self::MentionGap; + $lowest = $bodyHeight - self::MentionInset - self::MentionMinRows * self::MentionRowHeight - 8; + + return max(0, min($underCaret, $lowest)); + } + + /** + * A commit drawn as a static card (partials/quoted-commit): its chrome, its body clamped to six lines, its poll. + */ + public static function cardHeight(Commit $commit): int + { + $lines = 0; + + foreach (explode("\n", $commit->plainText()) as $paragraph) { + $lines += self::wrappedLines($paragraph, self::CardCharactersPerLine); + } + + return self::CardChromeHeight + + min(self::CardMaxLines, max(1, $lines)) * self::CardLineHeight + + ($commit->poll === null ? 0 : 4 + count($commit->poll->options) * self::CardPollOptionHeight); + } + + /** + * The poll editor (partials/poll-editor): its padding, a field per option, Add option until there are four, then + * Poll length and Remove poll under a hairline. + * + * @param list $options + */ + public static function pollEditorHeight(array $options): int + { + $count = count($options); + + return 24 + $count * 64 + ($count < PollDraft::MaxOptions ? 44 : 0) + 9 + 56; + } + + /** + * A note in small text, such as an error, at its wrapped height. + */ + public static function noteHeight(string $note): int + { + return self::wrappedLines($note, self::NoteCharactersPerLine) * self::NoteLineHeight; + } + + /** + * How many lines a paragraph wraps to, a word at a time, at about $perLine characters. A word longer than a line + * breaks, as the fields and Text break it. + */ + private static function wrappedLines(string $paragraph, int $perLine): int + { + return $paragraph === '' ? 1 : substr_count(wordwrap($paragraph, $perLine, "\n", true), "\n") + 1; + } +} diff --git a/resources/views/native/partials/commit-sheet.blade.php b/resources/views/native/partials/commit-sheet.blade.php index 1af931c2..a9633432 100644 --- a/resources/views/native/partials/commit-sheet.blade.php +++ b/resources/views/native/partials/commit-sheet.blade.php @@ -26,11 +26,14 @@ A commit's page opens its reply here too, as "Reply to @handle", with the commit being answered as a static card over the field, for the photos and the preview its reply bar has no room for. Commit says Reply there. - While the caret is after an "@handle", the people to mention show right under the field, as the web's composer lists - them (see SuggestsMentions): for a bare "@" in a new commit, the people you follow, under that heading. The field - keeps the keyboard up through presses in the sheet (keep-focus), so picking someone leaves you typing after them. + While the caret is after an "@handle", the people to mention float over the field just under the caret's line, as + the web's composer lists them (see SuggestsMentions): for a bare "@" in a new commit, the people you follow, under + that heading. They cover a quoted commit too, and run down to the toolbar. The field keeps the keyboard up through + presses in the sheet (keep-focus), so picking someone leaves you typing after them. - Under what's being written come its photos and the poll editor. A toolbar is pinned to the bottom of the sheet, so + The sheet doesn't scroll. The field fills the space between the author row and the toolbar, less what's under it: + the photos as a strip of 80pt squares, the poll editor, the commit being quoted, or "Submit at", each at its own + height (see ComposerSheet). Only the field scrolls its text. A toolbar is pinned to the bottom of the sheet, so it stays just above the keyboard: the tools on the left, photos, the camera, a poll (not on a reply) and the preview, which shows the draft as the commit it would become in place of the field (see AttachesToCommits), and stash@{0} and the counter on the right. An issue draft has no tools, as on the web. With photos, Commit spins while @@ -70,37 +73,74 @@ @endif - - - @if ($postsAs) - - @include('native.partials.post-as', ['ref' => 'sheet-post-as', 'me' => $postingMe, 'picked' => $sheetAuthor, 'method' => 'postAsInSheet', 'size' => 36, 'withName' => true]) - - @endif - - @if ($sheetError) - {{ $sheetError }} - @endif + {{-- + Nothing here scrolls but the field (or the preview in its place). What's over the field and under + it take their own height, and the field takes the lines left between them and the toolbar (see + ComposerSheet). Each part has a keyed slot that's always drawn, empty or not, so the field never + moves among its siblings: Android rebuilds a node that does, and the keyboard goes down with it. + --}} + @php($sheetLayout = \App\Devnull\ComposerSheet::class) + @php($linkTooLong = ! $issueCommand && \App\Devnull\Data\CommitBody::hasOversizedUrl($sheetBody)) + @php($pollShown = $sheetPoll !== null && ! $replying) + @php($offersIssues = ! $quoting && ! $scheduling && ! $replying && ! $issueCommand) + @php($issueCommands = $offersIssues && $sheetTyped ? \App\Devnull\IssueCommand::suggested($sheetBody) : []) + @php($issueHint = $offersIssues && ! $issueHintsDismissed ? \App\Devnull\IssueCommand::hinted($sheetBody) : null) + @php($above = [ + $postsAs ? $sheetLayout::PostAsHeight : 0, + $sheetError ? $sheetLayout::noteHeight($sheetError) : 0, + $issueCommand ? $sheetLayout::IssueBadgeHeight : 0, + $replying ? $sheetLayout::cardHeight($sheetCommit) : 0, + ]) + @php($below = $previewing ? [] : [ + $linkTooLong ? $sheetLayout::NoteLineHeight * 2 : 0, + $sheetImages === [] ? 0 : $sheetLayout::PhotosHeight + ($describing !== null ? $sheetLayout::PhotoDescriptionHeight : 0), + $pollShown ? $sheetLayout::pollEditorHeight($sheetPoll) : 0, + match (true) { + $quoting => $sheetLayout::cardHeight($sheetCommit), + $scheduling => $sheetLayout::ScheduleHeight, + $issueCommands !== [] => count($issueCommands) * $sheetLayout::IssueCommandRowHeight + 8, + $issueHint !== null => $sheetLayout::IssueHintHeight, + default => 0, + }, + ]) + @php($fieldLines = $sheetLayout::fieldLines($above, $below)) + @php($hasAbove = array_filter($above) !== []) + + @if ($postsAs) + + @include('native.partials.post-as', ['ref' => 'sheet-post-as', 'me' => $postingMe, 'picked' => $sheetAuthor, 'method' => 'postAsInSheet', 'size' => 36, 'withName' => true]) + + @endif - @if ($issueCommand) - @include('native.partials.issue-badge', ['command' => $issueCommand]) - @endif + @if ($sheetError) + {{ $sheetError }} + @endif - @if ($replying) - @include('native.partials.quoted-commit', ['quoted' => $sheetCommit, 'static' => true, 'label' => 'Replying to']) - @endif + @if ($issueCommand) + @include('native.partials.issue-badge', ['command' => $issueCommand]) + @endif - @if ($previewing) - @include('native.partials.composer-preview', [ - 'ref' => 'sheet-draft', - 'body' => $sheetBody, - 'preview' => $sheetPreview, - 'images' => $sheetImages, - 'poll' => $replying ? null : $sheetPoll, - 'pollLength' => $sheetPollLength, - 'quoted' => $quoting ? $sheetCommit : null, - ]) - @else + @if ($replying) + @include('native.partials.quoted-commit', ['quoted' => $sheetCommit, 'static' => true, 'label' => 'Replying to']) + @endif + + + @if ($previewing) + + + @include('native.partials.composer-preview', [ + 'ref' => 'sheet-draft', + 'body' => $sheetBody, + 'preview' => $sheetPreview, + 'images' => $sheetImages, + 'poll' => $replying ? null : $sheetPoll, + 'pollLength' => $sheetPollLength, + 'quoted' => $quoting ? $sheetCommit : null, + ]) + + + @else + - - @include('native.partials.mention-suggestions', [ - 'field' => 'sheetBody', - 'heading' => ($mention['query'] ?? null) === '' && $sheetView === 'compose' ? 'People you follow' : null, - 'label' => 'Mention a developer', - 'class' => 'w-full py-1 rounded-md border border-theme-hairline bg-theme-surface', - ]) - - @if (! $issueCommand && \App\Devnull\Data\CommitBody::hasOversizedUrl($sheetBody)) + + @php($hasBelow = array_filter($below) !== []) + + @if ($linkTooLong) Each link must not be greater than {{ \App\Devnull\Data\BodyLink::MaxLength }} characters. @endif @include('native.partials.composer-photos') - @if ($sheetPoll !== null && ! $replying) + @if ($pollShown) @include('native.partials.poll-editor') @endif @@ -139,17 +176,38 @@ class="w-full text-theme-ink" @include('native.partials.quoted-commit', ['quoted' => $sheetCommit, 'static' => true]) @elseif ($scheduling) @include('native.partials.schedule-picker') - @elseif (! $replying && ! $issueCommand) - @include('native.partials.issue-suggestions', [ - 'suggestions' => $sheetTyped ? \App\Devnull\IssueCommand::suggested($sheetBody) : [], - 'hint' => $issueHintsDismissed ? null : \App\Devnull\IssueCommand::hinted($sheetBody), - ]) + @elseif ($offersIssues) + @include('native.partials.issue-suggestions', ['suggestions' => $issueCommands, 'hint' => $issueHint]) @endif - @endif + - - - {{-- Pinned under the scroll view, so it rides just above the keyboard, and above the home indicator without it. --}} + {{-- + The people to mention float over the field and whatever is under it, out of the layout, so + nothing moves when they come and go. They start just under the line the caret is on, as + near as the app can tell (see ComposerSheet::caretLine()), and run down to the toolbar, + scrolling inside when there are more than fit. On Liquid Glass on iOS, like the reply + bar's, and on a raised surface on Android. + --}} + @if (($mention['field'] ?? null) === 'sheetBody' && ($mentionPeople !== [] || $mentionOrganizations !== [])) + @php($caretLine = $sheetLayout::caretLine($mention['text'], $mention['start'] + mb_strlen($mention['query']) + 1, $fieldLines, \Native\Mobile\Platform::isIos())) + + + @include('native.partials.mention-suggestions', [ + 'field' => 'sheetBody', + 'heading' => ($mention['query'] ?? null) === '' && $sheetView === 'compose' ? 'People you follow' : null, + 'label' => 'Mention a developer', + 'class' => 'w-full py-1', + ]) + + + @endif + @endif + + {{-- Pinned under the field and what's around it, so it rides just above the keyboard, and above the home indicator without it. --}} @unless ($issueCommand) diff --git a/tests/Feature/Screens/CommitMentionsTest.php b/tests/Feature/Screens/CommitMentionsTest.php index 4d35f14f..f9b4fe2c 100644 --- a/tests/Feature/Screens/CommitMentionsTest.php +++ b/tests/Feature/Screens/CommitMentionsTest.php @@ -1,5 +1,6 @@ assertSet('mention', null) ->assertSet('mentionPeople', []); }); + +it('floats the suggestions over the quoted commit on glass, from just under the caret line down to the toolbar', function () { + $screen = mentionsComposer(quoting: true)->input('sheet-body', "see\n@a", 6); + $overlay = nodeByRef($screen, 'sheet-mentions'); + + // Out of the layout, over the field and the card under it, so neither moves. + expect($overlay['layout']['position_type'])->toBe(1) + ->and($overlay['layout']['position'])->toEqual([ + ComposerSheet::TopPadding + 2 * ComposerSheet::FieldLineHeight + ComposerSheet::MentionGap, + 12, + ComposerSheet::MentionInset, + 12, + ]) + ->and($overlay['props']['glass'])->toBe(1) + ->and(childRefs($screen, 'sheet-body-area'))->toBe(['sheet-field-slot', 'sheet-below', 'sheet-mentions']) + ->and(findNode(nodeByRef($screen, 'sheet-below'), fn (array $node): bool => ($node['ref'] ?? null) === 'quote-card'))->not->toBeNull() + // The list scrolls inside it when there are more than fit. + ->and(findNode($overlay, fn (array $node): bool => $node['type'] === 'scroll_view' && ($node['ref'] ?? null) === 'sheet-mentions-scroll'))->not->toBeNull() + ->and(childRefs($screen, 'mention-suggestions'))->toBe(['mention-ada', 'mention-adam', 'mention-adaptive']); +}); + +it('draws the floating suggestions on a raised surface on Android', function () { + fakeApi([ + 'GET /api/v1/log/following' => [pageJson([])], + 'GET /api/v1/search/mentions' => mentionsFound(), + ]); + + $overlay = nodeByRef(Native::visit('/log', platform: 'android')->press('composeInSheet')->input('sheet-body', 'hi @a', 5), 'sheet-mentions'); + + expect($overlay['props'])->not->toHaveKey('glass') + ->and(strtolower($overlay['style']['bg_color']))->toBe(strtolower(config('native-ui.theme.light.surface'))); +}); diff --git a/tests/Feature/Screens/ComposeSheetTest.php b/tests/Feature/Screens/ComposeSheetTest.php index d0f319ee..490768e6 100644 --- a/tests/Feature/Screens/ComposeSheetTest.php +++ b/tests/Feature/Screens/ComposeSheetTest.php @@ -1,5 +1,6 @@ and(idsDownTo($screen->tree(), 'sheet-body'))->toBe($field); }); +it('fills the sheet with the field, with nothing scrolling around it', function () { + $screen = composeSheetOnLog(); + $field = nodeByRef($screen, 'sheet-body')['props']; + + expect(findNodes(nodeByRef($screen, 'sheet'), fn (array $node): bool => $node['type'] === 'scroll_view'))->toBe([]) + // As many lines as the sheet has room for, so the field reaches down to the toolbar. + ->and($field['min_lines'])->toBe($field['max_lines']) + ->and($field['max_lines'])->toBe(ComposerSheet::fieldLines([], [])) + ->and($field['line_height_px'])->toEqual(ComposerSheet::FieldLineHeight); +}); + +it('gives the field fewer lines while a poll takes its room, and the poll sits under the field', function () { + $screen = composeSheetOnLog(); + $lines = nodeByRef($screen, 'sheet-body')['props']['max_lines']; + + $screen->tap('sheet-poll'); + + expect(nodeByRef($screen, 'sheet-body')['props']['max_lines'])->toBeLessThan($lines) + ->and(nodeByRef($screen, 'sheet-body')['props']['min_lines'])->toBe(nodeByRef($screen, 'sheet-body')['props']['max_lines']) + ->and(findNode(nodeByRef($screen, 'sheet-below'), fn (array $node): bool => ($node['ref'] ?? null) === 'poll-editor'))->not->toBeNull(); +}); + +it('keeps the field the same view while photos, a poll and mentions come and go around it', function () { + fakeApi([ + 'GET /api/v1/log/following' => [pageJson([])], + 'GET /api/v1/search/mentions' => [['data' => [userJson(['id' => 'u9', 'handle' => 'ada'])], 'organizations' => []]], + ]); + $screen = Native::visit('/log', platform: 'ios')->press('composeInSheet'); + $field = idsDownTo($screen->tree(), 'sheet-body'); + + $screen->input('sheet-body', 'hi @a', 5); + expect(nodeByRef($screen, 'sheet-mentions'))->not->toBeEmpty() + ->and(idsDownTo($screen->tree(), 'sheet-body'))->toBe($field); + + $screen->input('sheet-body', 'hi', 2)->tap('sheet-poll'); + expect(nodeByRef($screen, 'poll-editor'))->not->toBeEmpty() + ->and(idsDownTo($screen->tree(), 'sheet-body'))->toBe($field); +}); + it('only commits from a sheet that has a composer in it', function () { fakeApi(['GET /api/v1/log/following' => [pageJson([commitJson(['id' => 'c1', 'author' => userJson(['id' => 'u2', 'handle' => 'ada'])])])]]); diff --git a/tests/Feature/Screens/ComposerPhotosTest.php b/tests/Feature/Screens/ComposerPhotosTest.php index 9a0fa6e1..5e3bc826 100644 --- a/tests/Feature/Screens/ComposerPhotosTest.php +++ b/tests/Feature/Screens/ComposerPhotosTest.php @@ -41,11 +41,11 @@ function isTool(TestableComponent $screen, string $ref): bool return nodeByRef($screen, $ref)['type'] === 'pressable'; } -it('pins the toolbar under the scroll view, so it stays just above the keyboard', function () { +it('pins the toolbar under the field and what is around it, so it stays just above the keyboard', function () { $screen = composerOnLog(); $toolbar = nodeByRef($screen, 'sheet-toolbar'); - expect(findNode(nodeByRef($screen, 'sheet-composer'), fn (array $node): bool => ($node['ref'] ?? null) === 'sheet-toolbar'))->toBeNull() + expect(findNode(nodeByRef($screen, 'sheet-body-area'), fn (array $node): bool => ($node['ref'] ?? null) === 'sheet-toolbar'))->toBeNull() ->and(findNode($toolbar, fn (array $node): bool => ($node['ref'] ?? null) === 'sheet-tools'))->not->toBeNull() ->and(findNode($toolbar, fn (array $node): bool => ($node['ref'] ?? null) === 'sheet-preview'))->not->toBeNull(); }); diff --git a/tests/Feature/Screens/QuoteTest.php b/tests/Feature/Screens/QuoteTest.php index 3ce4a7b5..5f08c99c 100644 --- a/tests/Feature/Screens/QuoteTest.php +++ b/tests/Feature/Screens/QuoteTest.php @@ -1,5 +1,6 @@ toBeFalse() ->and($screen->instance()->commit->id)->toBe('c2'); }); + +it('puts the quoted commit right under the field, which gives up the room it takes', function () { + $screen = quoteSheetOnLog(); + $field = nodeByRef($screen, 'sheet-body')['props']; + $card = ComposerSheet::cardHeight(Commit::fromArray(commitJson(['id' => 'c1', 'body' => 'Required reading.', 'author' => quoteAda()]))); + + expect(childRefs($screen, 'sheet-below'))->toBe(['quote-card']) + ->and($field['max_lines'])->toBe(ComposerSheet::fieldLines([], [$card])) + ->and($field['max_lines'])->toBeLessThan(ComposerSheet::fieldLines([], [])) + ->and($field['min_lines'])->toBe($field['max_lines']); +}); diff --git a/tests/Unit/Devnull/ComposerSheetTest.php b/tests/Unit/Devnull/ComposerSheetTest.php new file mode 100644 index 00000000..eeb6b09c --- /dev/null +++ b/tests/Unit/Devnull/ComposerSheetTest.php @@ -0,0 +1,41 @@ +toBe(intdiv(ComposerSheet::BodyHeight - ComposerSheet::TopPadding - ComposerSheet::BottomPadding, ComposerSheet::FieldLineHeight)) + // A quoted card under the field takes its height and a gap off the field. + ->and(ComposerSheet::fieldLines([], [96]))->toBe(intdiv(ComposerSheet::BodyHeight - ComposerSheet::TopPadding - ComposerSheet::BottomPadding - 96 - ComposerSheet::Gap, ComposerSheet::FieldLineHeight)) + // Nothing there is nothing taken. + ->and(ComposerSheet::fieldLines([0], [0, 0]))->toBe($empty) + // However much is around it, the field keeps two lines. + ->and(ComposerSheet::fieldLines([200], [300]))->toBe(ComposerSheet::MinFieldLines); +}); + +it('finds the line the caret is on from the text before it, wrapped a word at a time', function () { + expect(ComposerSheet::caretLine('see @a', 6, 10))->toBe(0) + ->and(ComposerSheet::caretLine("one\ntwo\n@a", 10, 10))->toBe(2) + // A blank line still counts. + ->and(ComposerSheet::caretLine("one\n\n@a", 7, 10))->toBe(2) + // Wrapped at about 40 characters on iOS, and fewer on Android's bigger text. + ->and(ComposerSheet::caretLine(str_repeat('word ', 9).'@a', 47, 10))->toBe(1) + ->and(ComposerSheet::caretLine(str_repeat('word ', 7).'@a', 37, 10, ios: true))->toBe(0) + ->and(ComposerSheet::caretLine(str_repeat('word ', 7).'@a', 37, 10, ios: false))->toBe(1) + // Only the text before the caret moves it. + ->and(ComposerSheet::caretLine("@a\nmore\nlines", 2, 10))->toBe(0); +}); + +it('keeps the caret on the last line the field shows once the field has scrolled', function () { + expect(ComposerSheet::caretLine(str_repeat("line\n", 20).'@a', 102, 6))->toBe(5); +}); + +it('starts the mention list under the caret line, or higher when that would leave it room for fewer than three', function () { + $underFirstLine = ComposerSheet::TopPadding + ComposerSheet::FieldLineHeight + ComposerSheet::MentionGap; + $lowest = 300 - ComposerSheet::MentionInset - ComposerSheet::MentionMinRows * ComposerSheet::MentionRowHeight - 8; + + expect(ComposerSheet::mentionTop(0, 300))->toBe($underFirstLine) + ->and(ComposerSheet::mentionTop(9, 300))->toBe($lowest) + ->and(ComposerSheet::mentionTop(0, 100))->toBe(0); +}); From 12bc35d42760a8f227cf8344fe633ffbf928fd30 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 09:09:29 +0000 Subject: [PATCH 2/5] Fill the composer sheet with a field that really fills, and place mentions by its caret The sheet's field had its lines worked out from an estimate of the sheet's height and of everything under it, and the mention list's top from the text before the caret, wrapped at a guessed width. mobile-ui#227 lets a multiline field fill the height it's given (h-full) and report where its caret is drawn (@caretChange), so the field is now h-full in a flex-1 slot and the list starts just under the caret's line as the field reports it. ComposerSheet keeps only the list's placement. Its line and height estimates, and the 24pt line height set on the field for them, are gone. Tests of the fill and the caret skip on a mobile-ui without them (Tests\Support\TextFieldFill), where the field is as tall as its lines. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/ComposerSheet.php | 183 ++++-------------- .../Concerns/OpensCommitSheet.php | 20 ++ .../native/partials/commit-sheet.blade.php | 49 ++--- tests/Feature/Screens/CommitMentionsTest.php | 10 +- tests/Feature/Screens/ComposeSheetTest.php | 35 ++-- tests/Feature/Screens/QuoteTest.php | 11 +- tests/Support/TextFieldFill.php | 25 +++ tests/Unit/Devnull/ComposerSheetTest.php | 47 ++--- 8 files changed, 151 insertions(+), 229 deletions(-) create mode 100644 tests/Support/TextFieldFill.php diff --git a/app/Devnull/ComposerSheet.php b/app/Devnull/ComposerSheet.php index b3f3dc7d..226b443a 100644 --- a/app/Devnull/ComposerSheet.php +++ b/app/Devnull/ComposerSheet.php @@ -2,79 +2,24 @@ namespace App\Devnull; -use App\Devnull\Data\Commit; -use App\Devnull\Data\PollDraft; +use Native\Mobile\UI\Caret; /** - * How the composer sheet (partials/commit-sheet) shares its height out, in points. The field takes what the rest - * leaves between the author row and the toolbar, and the mention list floats under the line the caret is on. + * Where the composer sheet (partials/commit-sheet) floats its mention list: just under the line the caret is on, which + * the field reports (`@caretChange`, see OpensCommitSheet::sheetCaretMoved()), down to the toolbar. * - * Neither platform tells PHP how tall the sheet is, or where the caret is drawn, and mobile-ui's multiline field is as - * tall as its lines (min-lines to max-lines), not as tall as the space it's given. So this works both out from what - * the app knows: the sheet's height on a 6.1" iPhone with the keyboard up, how tall each thing under the field is - * drawn, and how the draft wraps at the field's width. The field's line height is set (FieldLineHeight), so a line - * is the same height on both platforms. + * The field fills the space between the author row and what's under it by itself (`h-full`), so nothing here sizes + * it. The list's top is in the sheet's body area, whose top is the field slot's top: the slot's padding, then the + * caret's line in the field's own points. */ final class ComposerSheet { - /** - * The sheet between its bar's hairline and the toolbar's hairline, keyboard up, on a 6.1" iPhone. Bigger phones - * leave a little room under the field; nothing smaller is supported for composing. - */ - public const int BodyHeight = 340; - - /** The padding above the first thing in the sheet and under the last. */ - public const int TopPadding = 12; - - public const int BottomPadding = 8; - - /** The gap between the things stacked above and under the field. */ - public const int Gap = 12; - - public const int FieldLineHeight = 24; + /** The field slot's padding above the field (pt-3). */ + public const int FieldTop = 12; + /** The least the field shows, on a phone short enough that the rest leaves it little room. */ public const int MinFieldLines = 2; - /** - * About how many characters of the field's text fit on a line across the sheet: 18pt on iOS, 20sp on Android. - */ - public const int IosCharactersPerLine = 40; - - public const int AndroidCharactersPerLine = 36; - - /** The Post as row's avatar, with its name and handle beside it. */ - public const int PostAsHeight = 36; - - public const int IssueBadgeHeight = 32; - - /** A line of small text: an error, or the link-length note. */ - public const int NoteLineHeight = 20; - - public const int NoteCharactersPerLine = 48; - - /** The photo strip's 80pt squares, and the description under them while it's open. */ - public const int PhotosHeight = 80; - - public const int PhotoDescriptionHeight = 150; - - /** The schedule box: "Submit at", the picker, the timezone and its lines, then Scheduled commits →. */ - public const int ScheduleHeight = 170; - - public const int IssueCommandRowHeight = 44; - - public const int IssueHintHeight = 32; - - /** A quoted commit's card: its margin, padding and header, then up to six lines of its body. */ - public const int CardChromeHeight = 44; - - public const int CardLineHeight = 24; - - public const int CardCharactersPerLine = 42; - - public const int CardMaxLines = 6; - - public const int CardPollOptionHeight = 36; - /** The mention list's rows, and how many of them it always has room for. */ public const int MentionRowHeight = 44; @@ -85,106 +30,52 @@ final class ComposerSheet public const int MentionInset = 8; + /** The list's own padding above and under its rows (py-1). */ + public const int MentionPadding = 8; + /** - * How many lines the field shows, after everything else in the sheet has its height: $above are the heights of - * what's stacked over the field, $below of what's under it. - * - * @param list $above - * @param list $below + * Before the field has said where its caret is (it says so as soon as it has focus, so only for a moment), the + * list goes under about one line. */ - public static function fieldLines(array $above, array $below): int - { - $parts = [...array_filter($above), ...array_filter($below)]; - $free = self::BodyHeight - self::TopPadding - self::BottomPadding - array_sum($parts) - count($parts) * self::Gap; - - return max(self::MinFieldLines, intdiv($free, self::FieldLineHeight)); - } + public const int FirstLineHeight = 24; /** - * The height of the space under the stack above the field: the field and what's under it, where the mention list - * floats. + * The caret as the sheet keeps it: the bottom of its line and the field's visible height, in points. A caret the + * field has scrolled out of view is kept to its edges. * - * @param list $above + * @return array{bottom: float, field_height: float} */ - public static function bodyHeight(array $above): int + public static function caret(Caret $caret): array { - $above = array_filter($above); + $field = max(0.0, $caret->fieldHeight); + $bottom = max(0.0, $caret->bottom()); - return self::BodyHeight - array_sum($above) - count($above) * self::Gap; + return ['bottom' => $field > 0 ? min($bottom, $field) : $bottom, 'field_height' => $field]; } /** - * Which of the field's shown lines the caret is on, from the top, counting from 0: the text before it, wrapped a - * word at a time at the field's width. Past the last line shown, the field has scrolled to keep the caret in - * view, so it's on the last. + * Where the mention list's top goes in the sheet's body area: just under the caret's line, or higher when that + * would leave it room for fewer than three people above the toolbar. The room is measured to the field's bottom, + * since the field doesn't say how tall what's under it is, so with a quoted commit under it the list can go up a + * little sooner than it has to. + * + * @param array{bottom: float, field_height: float}|null $caret */ - public static function caretLine(string $text, int $caret, int $shownLines, bool $ios = true): int + public static function mentionTop(?array $caret): int { - $perLine = $ios ? self::IosCharactersPerLine : self::AndroidCharactersPerLine; - $lines = 0; - - foreach (explode("\n", mb_substr($text, 0, max(0, $caret))) as $paragraph) { - $lines += self::wrappedLines($paragraph, $perLine); + if ($caret === null) { + return self::FieldTop + self::FirstLineHeight + self::MentionGap; } - return min(max(0, $lines - 1), max(0, $shownLines - 1)); - } - - /** - * Where the mention list's top goes in the space under the stack: just under the caret's line, or higher when - * that would leave it room for fewer than three people. - */ - public static function mentionTop(int $caretLine, int $bodyHeight): int - { - $underCaret = self::TopPadding + ($caretLine + 1) * self::FieldLineHeight + self::MentionGap; - $lowest = $bodyHeight - self::MentionInset - self::MentionMinRows * self::MentionRowHeight - 8; + $underCaret = self::FieldTop + (int) ceil($caret['bottom']) + self::MentionGap; - return max(0, min($underCaret, $lowest)); - } - - /** - * A commit drawn as a static card (partials/quoted-commit): its chrome, its body clamped to six lines, its poll. - */ - public static function cardHeight(Commit $commit): int - { - $lines = 0; - - foreach (explode("\n", $commit->plainText()) as $paragraph) { - $lines += self::wrappedLines($paragraph, self::CardCharactersPerLine); + if ($caret['field_height'] <= 0) { + return $underCaret; } - return self::CardChromeHeight - + min(self::CardMaxLines, max(1, $lines)) * self::CardLineHeight - + ($commit->poll === null ? 0 : 4 + count($commit->poll->options) * self::CardPollOptionHeight); - } - - /** - * The poll editor (partials/poll-editor): its padding, a field per option, Add option until there are four, then - * Poll length and Remove poll under a hairline. - * - * @param list $options - */ - public static function pollEditorHeight(array $options): int - { - $count = count($options); + $lowest = self::FieldTop + (int) floor($caret['field_height']) + - self::MentionInset - self::MentionMinRows * self::MentionRowHeight - self::MentionPadding; - return 24 + $count * 64 + ($count < PollDraft::MaxOptions ? 44 : 0) + 9 + 56; - } - - /** - * A note in small text, such as an error, at its wrapped height. - */ - public static function noteHeight(string $note): int - { - return self::wrappedLines($note, self::NoteCharactersPerLine) * self::NoteLineHeight; - } - - /** - * How many lines a paragraph wraps to, a word at a time, at about $perLine characters. A word longer than a line - * breaks, as the fields and Text break it. - */ - private static function wrappedLines(string $paragraph, int $perLine): int - { - return $paragraph === '' ? 1 : substr_count(wordwrap($paragraph, $perLine, "\n", true), "\n") + 1; + return max(0, min($underCaret, $lowest)); } } diff --git a/app/NativeComponents/Concerns/OpensCommitSheet.php b/app/NativeComponents/Concerns/OpensCommitSheet.php index 06df216a..b4fc25af 100644 --- a/app/NativeComponents/Concerns/OpensCommitSheet.php +++ b/app/NativeComponents/Concerns/OpensCommitSheet.php @@ -3,6 +3,7 @@ namespace App\NativeComponents\Concerns; use App\Devnull\Client; +use App\Devnull\ComposerSheet; use App\Devnull\Data\Commit; use App\Devnull\Data\Draft; use App\Devnull\Data\PollDraft; @@ -20,6 +21,7 @@ use Carbon\CarbonImmutable; use Closure; use Native\Mobile\Facades\System; +use Native\Mobile\UI\Caret; /** * The sheet under a commit (see partials/commit-sheet). Report commit, in the @@ -110,6 +112,14 @@ trait OpensCommitSheet */ public string $sheetBody = ''; + /** + * Where the sheet's field last said its caret is drawn, for the mention list to float under (see ComposerSheet). + * Null until it has said, and again once the sheet is gone. + * + * @var array{bottom: float, field_height: float}|null + */ + public ?array $sheetCaret = null; + /** * The handle of the organization the sheet posts as, or null for you (see PostAs). */ @@ -307,6 +317,14 @@ public function openScheduledCommits(): void /** * Stashes the draft as it changes (see stashSheetDraft()). */ + /** + * The sheet's field drew its caret somewhere else: it moved, the text wrapped differently, or the field scrolled. + */ + public function sheetCaretMoved(Caret $caret): void + { + $this->sheetCaret = ComposerSheet::caret($caret); + } + public function updatedSheetBody(): void { $this->typeIssueCommand(); @@ -493,6 +511,7 @@ private function closeCommitSheet(): void { $this->sheetClosing = $this->sheetClosing || ($this->sheetOpen && System::isIos()); $this->sheetOpen = false; + $this->sheetCaret = null; $this->forgetMention('sheetBody'); } @@ -606,6 +625,7 @@ private function forgetCommitSheet(): void $this->reportReason = ''; $this->reportDetails = ''; $this->sheetBody = ''; + $this->sheetCaret = null; $this->sheetAuthor = null; $this->sheetRestored = false; $this->sheetError = null; diff --git a/resources/views/native/partials/commit-sheet.blade.php b/resources/views/native/partials/commit-sheet.blade.php index a9633432..55a945c9 100644 --- a/resources/views/native/partials/commit-sheet.blade.php +++ b/resources/views/native/partials/commit-sheet.blade.php @@ -26,14 +26,14 @@ A commit's page opens its reply here too, as "Reply to @handle", with the commit being answered as a static card over the field, for the photos and the preview its reply bar has no room for. Commit says Reply there. - While the caret is after an "@handle", the people to mention float over the field just under the caret's line, as - the web's composer lists them (see SuggestsMentions): for a bare "@" in a new commit, the people you follow, under + While the caret is after an "@handle", the people to mention float over the field just under the caret's line, + which the field reports (@caretChange), as the web's composer lists them (see SuggestsMentions): for a bare "@" in a new commit, the people you follow, under that heading. They cover a quoted commit too, and run down to the toolbar. The field keeps the keyboard up through presses in the sheet (keep-focus), so picking someone leaves you typing after them. The sheet doesn't scroll. The field fills the space between the author row and the toolbar, less what's under it: the photos as a strip of 80pt squares, the poll editor, the commit being quoted, or "Submit at", each at its own - height (see ComposerSheet). Only the field scrolls its text. A toolbar is pinned to the bottom of the sheet, so + height. Only the field scrolls its text. A toolbar is pinned to the bottom of the sheet, so it stays just above the keyboard: the tools on the left, photos, the camera, a poll (not on a reply) and the preview, which shows the draft as the commit it would become in place of the field (see AttachesToCommits), and stash@{0} and the counter on the right. An issue draft has no tools, as on the web. With photos, Commit spins while @@ -75,8 +75,8 @@ {{-- Nothing here scrolls but the field (or the preview in its place). What's over the field and under - it take their own height, and the field takes the lines left between them and the toolbar (see - ComposerSheet). Each part has a keyed slot that's always drawn, empty or not, so the field never + it take their own height, and the field (h-full in a flex-1 slot) takes what's left between them + and the toolbar. Each part has a keyed slot that's always drawn, empty or not, so the field never moves among its siblings: Android rebuilds a node that does, and the keyboard goes down with it. --}} @php($sheetLayout = \App\Devnull\ComposerSheet::class) @@ -85,26 +85,7 @@ @php($offersIssues = ! $quoting && ! $scheduling && ! $replying && ! $issueCommand) @php($issueCommands = $offersIssues && $sheetTyped ? \App\Devnull\IssueCommand::suggested($sheetBody) : []) @php($issueHint = $offersIssues && ! $issueHintsDismissed ? \App\Devnull\IssueCommand::hinted($sheetBody) : null) - @php($above = [ - $postsAs ? $sheetLayout::PostAsHeight : 0, - $sheetError ? $sheetLayout::noteHeight($sheetError) : 0, - $issueCommand ? $sheetLayout::IssueBadgeHeight : 0, - $replying ? $sheetLayout::cardHeight($sheetCommit) : 0, - ]) - @php($below = $previewing ? [] : [ - $linkTooLong ? $sheetLayout::NoteLineHeight * 2 : 0, - $sheetImages === [] ? 0 : $sheetLayout::PhotosHeight + ($describing !== null ? $sheetLayout::PhotoDescriptionHeight : 0), - $pollShown ? $sheetLayout::pollEditorHeight($sheetPoll) : 0, - match (true) { - $quoting => $sheetLayout::cardHeight($sheetCommit), - $scheduling => $sheetLayout::ScheduleHeight, - $issueCommands !== [] => count($issueCommands) * $sheetLayout::IssueCommandRowHeight + 8, - $issueHint !== null => $sheetLayout::IssueHintHeight, - default => 0, - }, - ]) - @php($fieldLines = $sheetLayout::fieldLines($above, $below)) - @php($hasAbove = array_filter($above) !== []) + @php($hasAbove = $postsAs || $sheetError || $issueCommand || $replying) @if ($postsAs) @@ -140,27 +121,26 @@ @else - + - @php($hasBelow = array_filter($below) !== []) + @php($hasBelow = $linkTooLong || $sheetImages !== [] || $pollShown || $quoting || $scheduling || $issueCommands !== [] || $issueHint !== null) @if ($linkTooLong) Each link must not be greater than {{ \App\Devnull\Data\BodyLink::MaxLength }} characters. @@ -183,17 +163,16 @@ class="w-full text-theme-ink" {{-- The people to mention float over the field and whatever is under it, out of the layout, so - nothing moves when they come and go. They start just under the line the caret is on, as - near as the app can tell (see ComposerSheet::caretLine()), and run down to the toolbar, + nothing moves when they come and go. They start just under the line the caret is on, where + the field says it is (see ComposerSheet::mentionTop()), and run down to the toolbar, scrolling inside when there are more than fit. On Liquid Glass on iOS, like the reply bar's, and on a raised surface on Android. --}} @if (($mention['field'] ?? null) === 'sheetBody' && ($mentionPeople !== [] || $mentionOrganizations !== [])) - @php($caretLine = $sheetLayout::caretLine($mention['text'], $mention['start'] + mb_strlen($mention['query']) + 1, $fieldLines, \Native\Mobile\Platform::isIos())) @include('native.partials.mention-suggestions', [ diff --git a/tests/Feature/Screens/CommitMentionsTest.php b/tests/Feature/Screens/CommitMentionsTest.php index f9b4fe2c..effbc57e 100644 --- a/tests/Feature/Screens/CommitMentionsTest.php +++ b/tests/Feature/Screens/CommitMentionsTest.php @@ -5,6 +5,8 @@ use Illuminate\Support\Facades\Http; use Native\Mobile\Testing\Native; use Native\Mobile\Testing\TestableComponent; +use Native\Mobile\UI\Caret; +use Tests\Support\TextFieldFill; beforeEach(function () { config(['devnull.url' => 'http://devnull.test']); @@ -184,13 +186,17 @@ function mentionsComposer(bool $quoting = false): TestableComponent }); it('floats the suggestions over the quoted commit on glass, from just under the caret line down to the toolbar', function () { - $screen = mentionsComposer(quoting: true)->input('sheet-body', "see\n@a", 6); + TextFieldFill::skipUnlessSupported(); + + $screen = mentionsComposer(quoting: true) + ->input('sheet-body', "see\n@a", 6) + ->moveCaretTo('sheet-body', new Caret(x: 20, y: 22, width: 2, height: 22, line: 1, fieldWidth: 350, fieldHeight: 240)); $overlay = nodeByRef($screen, 'sheet-mentions'); // Out of the layout, over the field and the card under it, so neither moves. expect($overlay['layout']['position_type'])->toBe(1) ->and($overlay['layout']['position'])->toEqual([ - ComposerSheet::TopPadding + 2 * ComposerSheet::FieldLineHeight + ComposerSheet::MentionGap, + ComposerSheet::FieldTop + 44 + ComposerSheet::MentionGap, 12, ComposerSheet::MentionInset, 12, diff --git a/tests/Feature/Screens/ComposeSheetTest.php b/tests/Feature/Screens/ComposeSheetTest.php index 490768e6..100b5877 100644 --- a/tests/Feature/Screens/ComposeSheetTest.php +++ b/tests/Feature/Screens/ComposeSheetTest.php @@ -7,6 +7,8 @@ use Illuminate\Support\Facades\Http; use Native\Mobile\Testing\Native; use Native\Mobile\Testing\TestableComponent; +use Native\Mobile\UI\Caret; +use Tests\Support\TextFieldFill; beforeEach(function () { config(['devnull.url' => 'http://devnull.test']); @@ -283,27 +285,38 @@ function sheetCommitDisabled(TestableComponent $screen): bool }); it('fills the sheet with the field, with nothing scrolling around it', function () { + TextFieldFill::skipUnlessSupported(); + $screen = composeSheetOnLog(); $field = nodeByRef($screen, 'sheet-body')['props']; expect(findNodes(nodeByRef($screen, 'sheet'), fn (array $node): bool => $node['type'] === 'scroll_view'))->toBe([]) - // As many lines as the sheet has room for, so the field reaches down to the toolbar. - ->and($field['min_lines'])->toBe($field['max_lines']) - ->and($field['max_lines'])->toBe(ComposerSheet::fieldLines([], [])) - ->and($field['line_height_px'])->toEqual(ComposerSheet::FieldLineHeight); + // As tall as the space between the author row and the toolbar, scrolling its own text. + ->and($field['fills_height'] ?? null)->toBeTrue() + ->and($field['min_lines'])->toBe(ComposerSheet::MinFieldLines) + ->and($field)->not->toHaveKey('max_lines') + ->and(nodeByRef($screen, 'sheet-field-slot')['layout']['flex_grow'] ?? null)->toEqual(1) + // It says where its caret is drawn, for the mention list. + ->and($field['on_caret_change'] ?? null)->toBeInt(); }); -it('gives the field fewer lines while a poll takes its room, and the poll sits under the field', function () { - $screen = composeSheetOnLog(); - $lines = nodeByRef($screen, 'sheet-body')['props']['max_lines']; - - $screen->tap('sheet-poll'); +it('puts the poll under the field, which gives up the room it takes', function () { + $screen = composeSheetOnLog()->tap('sheet-poll'); - expect(nodeByRef($screen, 'sheet-body')['props']['max_lines'])->toBeLessThan($lines) - ->and(nodeByRef($screen, 'sheet-body')['props']['min_lines'])->toBe(nodeByRef($screen, 'sheet-body')['props']['max_lines']) + expect(childRefs($screen, 'sheet-body-area'))->toBe(['sheet-field-slot', 'sheet-below']) ->and(findNode(nodeByRef($screen, 'sheet-below'), fn (array $node): bool => ($node['ref'] ?? null) === 'poll-editor'))->not->toBeNull(); }); +it('keeps where the field says its caret is until the sheet goes', function () { + TextFieldFill::skipUnlessSupported(); + + $screen = composeSheetOnLog() + ->moveCaretTo('sheet-body', new Caret(y: 48, height: 24, line: 2, fieldWidth: 350, fieldHeight: 240)) + ->assertSet('sheetCaret', ['bottom' => 72.0, 'field_height' => 240.0]); + + $screen->press('hideCommitSheet')->assertSet('sheetCaret', null); +}); + it('keeps the field the same view while photos, a poll and mentions come and go around it', function () { fakeApi([ 'GET /api/v1/log/following' => [pageJson([])], diff --git a/tests/Feature/Screens/QuoteTest.php b/tests/Feature/Screens/QuoteTest.php index 5f08c99c..e9a1eb92 100644 --- a/tests/Feature/Screens/QuoteTest.php +++ b/tests/Feature/Screens/QuoteTest.php @@ -1,11 +1,11 @@ 'http://devnull.test']); @@ -214,12 +214,11 @@ function quoteButtonDisabled(TestableComponent $screen): bool }); it('puts the quoted commit right under the field, which gives up the room it takes', function () { + TextFieldFill::skipUnlessSupported(); + $screen = quoteSheetOnLog(); - $field = nodeByRef($screen, 'sheet-body')['props']; - $card = ComposerSheet::cardHeight(Commit::fromArray(commitJson(['id' => 'c1', 'body' => 'Required reading.', 'author' => quoteAda()]))); expect(childRefs($screen, 'sheet-below'))->toBe(['quote-card']) - ->and($field['max_lines'])->toBe(ComposerSheet::fieldLines([], [$card])) - ->and($field['max_lines'])->toBeLessThan(ComposerSheet::fieldLines([], [])) - ->and($field['min_lines'])->toBe($field['max_lines']); + ->and(childRefs($screen, 'sheet-body-area'))->toBe(['sheet-field-slot', 'sheet-below']) + ->and(nodeByRef($screen, 'sheet-body')['props']['fills_height'] ?? null)->toBeTrue(); }); diff --git a/tests/Support/TextFieldFill.php b/tests/Support/TextFieldFill.php new file mode 100644 index 00000000..d714743c --- /dev/null +++ b/tests/Support/TextFieldFill.php @@ -0,0 +1,25 @@ +markTestSkipped('Needs a mobile-ui whose multiline field fills and reports its caret (NativePHP/mobile-ui#227)'); + } + } +} diff --git a/tests/Unit/Devnull/ComposerSheetTest.php b/tests/Unit/Devnull/ComposerSheetTest.php index eeb6b09c..28ccd184 100644 --- a/tests/Unit/Devnull/ComposerSheetTest.php +++ b/tests/Unit/Devnull/ComposerSheetTest.php @@ -1,41 +1,30 @@ TextFieldFill::skipUnlessSupported()); - expect($empty)->toBe(intdiv(ComposerSheet::BodyHeight - ComposerSheet::TopPadding - ComposerSheet::BottomPadding, ComposerSheet::FieldLineHeight)) - // A quoted card under the field takes its height and a gap off the field. - ->and(ComposerSheet::fieldLines([], [96]))->toBe(intdiv(ComposerSheet::BodyHeight - ComposerSheet::TopPadding - ComposerSheet::BottomPadding - 96 - ComposerSheet::Gap, ComposerSheet::FieldLineHeight)) - // Nothing there is nothing taken. - ->and(ComposerSheet::fieldLines([0], [0, 0]))->toBe($empty) - // However much is around it, the field keeps two lines. - ->and(ComposerSheet::fieldLines([200], [300]))->toBe(ComposerSheet::MinFieldLines); -}); +it('starts the mention list just under the line the field says the caret is on', function () { + $caret = ComposerSheet::caret(new Caret(y: 48, height: 24, line: 2, fieldHeight: 300)); -it('finds the line the caret is on from the text before it, wrapped a word at a time', function () { - expect(ComposerSheet::caretLine('see @a', 6, 10))->toBe(0) - ->and(ComposerSheet::caretLine("one\ntwo\n@a", 10, 10))->toBe(2) - // A blank line still counts. - ->and(ComposerSheet::caretLine("one\n\n@a", 7, 10))->toBe(2) - // Wrapped at about 40 characters on iOS, and fewer on Android's bigger text. - ->and(ComposerSheet::caretLine(str_repeat('word ', 9).'@a', 47, 10))->toBe(1) - ->and(ComposerSheet::caretLine(str_repeat('word ', 7).'@a', 37, 10, ios: true))->toBe(0) - ->and(ComposerSheet::caretLine(str_repeat('word ', 7).'@a', 37, 10, ios: false))->toBe(1) - // Only the text before the caret moves it. - ->and(ComposerSheet::caretLine("@a\nmore\nlines", 2, 10))->toBe(0); + expect(ComposerSheet::mentionTop($caret))->toBe(ComposerSheet::FieldTop + 72 + ComposerSheet::MentionGap); }); -it('keeps the caret on the last line the field shows once the field has scrolled', function () { - expect(ComposerSheet::caretLine(str_repeat("line\n", 20).'@a', 102, 6))->toBe(5); +it('moves the list up when the caret is too near the field\'s bottom to leave room for three people', function () { + $lowest = ComposerSheet::FieldTop + 300 - ComposerSheet::MentionInset - ComposerSheet::MentionMinRows * ComposerSheet::MentionRowHeight - ComposerSheet::MentionPadding; + + expect(ComposerSheet::mentionTop(ComposerSheet::caret(new Caret(y: 264, height: 24, fieldHeight: 300))))->toBe($lowest) + // A field too short for three people puts the list at the top of it. + ->and(ComposerSheet::mentionTop(ComposerSheet::caret(new Caret(y: 24, height: 24, fieldHeight: 80))))->toBe(0); }); -it('starts the mention list under the caret line, or higher when that would leave it room for fewer than three', function () { - $underFirstLine = ComposerSheet::TopPadding + ComposerSheet::FieldLineHeight + ComposerSheet::MentionGap; - $lowest = 300 - ComposerSheet::MentionInset - ComposerSheet::MentionMinRows * ComposerSheet::MentionRowHeight - 8; +it('keeps a caret the field has scrolled out of view to the field\'s edges', function () { + expect(ComposerSheet::caret(new Caret(y: -60, height: 24, fieldHeight: 300)))->toBe(['bottom' => 0.0, 'field_height' => 300.0]) + ->and(ComposerSheet::caret(new Caret(y: 400, height: 24, fieldHeight: 300)))->toBe(['bottom' => 300.0, 'field_height' => 300.0]); +}); - expect(ComposerSheet::mentionTop(0, 300))->toBe($underFirstLine) - ->and(ComposerSheet::mentionTop(9, 300))->toBe($lowest) - ->and(ComposerSheet::mentionTop(0, 100))->toBe(0); +it('puts the list under about one line before the field has said where its caret is', function () { + expect(ComposerSheet::mentionTop(null))->toBe(ComposerSheet::FieldTop + ComposerSheet::FirstLineHeight + ComposerSheet::MentionGap); }); From 31567787b97c3cab73f71f2fc936b918cfa5f367 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 10:28:46 +0000 Subject: [PATCH 3/5] Shorten the sheet's field to make room for mentions under the caret When the mention list doesn't fit between the caret's line and the field's bottom, the field now gets shorter instead, ending on the caret's line, and the list goes under it down to the toolbar. Before, the list moved up to make room for three people and could cover the line being typed on. The list is as tall as its rows (up to six) when it floats, so it only scrolls when it has to. Once the list goes, the field fills again. The body area has animate-layout (mobile-air#736), so the field's height and the list coming and going are animated. The field slot keeps its key and place, so the keyboard stays up. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/ComposerSheet.php | 130 ++++++++++++++---- .../Concerns/OpensCommitSheet.php | 27 +++- .../native/partials/commit-sheet.blade.php | 39 ++++-- tests/Feature/Screens/CommitMentionsTest.php | 44 +++++- tests/Feature/Screens/ComposeSheetTest.php | 2 +- tests/Support/LayoutAnimation.php | 25 ++++ tests/Unit/Devnull/ComposerSheetTest.php | 80 +++++++++-- 7 files changed, 284 insertions(+), 63 deletions(-) create mode 100644 tests/Support/LayoutAnimation.php diff --git a/app/Devnull/ComposerSheet.php b/app/Devnull/ComposerSheet.php index 226b443a..80a3ccf7 100644 --- a/app/Devnull/ComposerSheet.php +++ b/app/Devnull/ComposerSheet.php @@ -5,12 +5,16 @@ use Native\Mobile\UI\Caret; /** - * Where the composer sheet (partials/commit-sheet) floats its mention list: just under the line the caret is on, which - * the field reports (`@caretChange`, see OpensCommitSheet::sheetCaretMoved()), down to the toolbar. + * Where the composer sheet (partials/commit-sheet) puts its mention list, and how tall its field is meanwhile. * - * The field fills the space between the author row and what's under it by itself (`h-full`), so nothing here sizes - * it. The list's top is in the sheet's body area, whose top is the field slot's top: the slot's padding, then the - * caret's line in the field's own points. + * The field fills the space between the author row and what's under it by itself (`h-full`). The list floats just + * under the line the caret is on, which the field reports (`@caretChange`, see OpensCommitSheet::sheetCaretMoved()), + * as tall as its rows, up to six of them. When there isn't room for that under the caret, the field gets shorter + * instead, just tall enough to end on the caret's line (it scrolls its text to keep the caret in view), and the list + * goes in the room that frees, under the field. Once the list is gone, the field fills again. + * + * Everything is in points from the top of the sheet's body area, whose top is the field slot's top: the slot's + * padding, then the field. */ final class ComposerSheet { @@ -20,62 +24,128 @@ final class ComposerSheet /** The least the field shows, on a phone short enough that the rest leaves it little room. */ public const int MinFieldLines = 2; - /** The mention list's rows, and how many of them it always has room for. */ + /** + * The mention list's rows, and how many show before the rest scroll inside it. The same as + * Display::MentionRowHeight and Display::MentionRowsShown, which cap the lists by the other fields. + */ public const int MentionRowHeight = 44; - public const int MentionMinRows = 3; + public const int MentionRowsShown = 6; - /** How far under the caret's line the mention list starts, and stops above the toolbar. */ + /** The list's own padding above and under its rows (py-1), and its heading's height (one line of text-xs, py-1). */ + public const int MentionPadding = 8; + + public const int MentionHeadingHeight = 24; + + /** How far under the caret's line (or the field) the mention list starts, and stops above the toolbar. */ public const int MentionGap = 4; public const int MentionInset = 8; - /** The list's own padding above and under its rows (py-1). */ - public const int MentionPadding = 8; - /** * Before the field has said where its caret is (it says so as soon as it has focus, so only for a moment), the - * list goes under about one line. + * list goes under about one line, and a line is taken to be this tall. */ public const int FirstLineHeight = 24; /** - * The caret as the sheet keeps it: the bottom of its line and the field's visible height, in points. A caret the - * field has scrolled out of view is kept to its edges. + * The caret as the sheet keeps it, as the field shows it at its full height: the bottom of its line, the line's + * height, and the field's visible height, in points. A caret the field has scrolled out of view is kept to its + * edges. * - * @return array{bottom: float, field_height: float} + * @return array{bottom: float, line_height: float, field_height: float} */ public static function caret(Caret $caret): array { $field = max(0.0, $caret->fieldHeight); $bottom = max(0.0, $caret->bottom()); - return ['bottom' => $field > 0 ? min($bottom, $field) : $bottom, 'field_height' => $field]; + return [ + 'bottom' => $field > 0 ? min($bottom, $field) : $bottom, + 'line_height' => max(0.0, $caret->height), + 'field_height' => $field, + ]; } /** - * Where the mention list's top goes in the sheet's body area: just under the caret's line, or higher when that - * would leave it room for fewer than three people above the toolbar. The room is measured to the field's bottom, - * since the field doesn't say how tall what's under it is, so with a quoted commit under it the list can go up a - * little sooner than it has to. + * The caret to keep after the field reports a new one. While the field is shorter for the list, it reports + * itself at that height, scrolled to the caret, which says nothing about where the caret is at its full height, + * so the sheet keeps what it had. Any other report is the field at its full height. * - * @param array{bottom: float, field_height: float}|null $caret + * @param array{bottom: float, line_height: float, field_height: float}|null $kept + * @param int|null $shortened how tall the sheet has made the field, or null when it fills + * @return array{bottom: float, line_height: float, field_height: float} */ - public static function mentionTop(?array $caret): int + public static function reported(Caret $caret, ?array $kept, ?int $shortened): array { - if ($caret === null) { - return self::FieldTop + self::FirstLineHeight + self::MentionGap; + if ($kept !== null && $shortened !== null && abs($caret->fieldHeight - $shortened) <= 1) { + return $kept; } - $underCaret = self::FieldTop + (int) ceil($caret['bottom']) + self::MentionGap; + return self::caret($caret); + } - if ($caret['field_height'] <= 0) { - return $underCaret; + /** The mention list's height with all its rows showing, up to six: its padding, its heading, then its rows. */ + public static function mentionHeight(int $rows, bool $heading = false): int + { + return self::MentionPadding + + ($heading ? self::MentionHeadingHeight : 0) + + min(max($rows, 1), self::MentionRowsShown) * self::MentionRowHeight; + } + + /** + * Where the mention list goes, and how tall the field is while it shows. + * + * - `field`: the field's height, or null when it fills as usual. + * - `top`: the list's top. + * - `height`: the list's height, or null when it runs down to the toolbar. + * + * With room for the whole list (up to six rows) between the caret's line and the field's bottom, it floats there + * over the field and nothing moves. Without it, the field ends on the caret's line, shortened by as much as the + * list needs but never under two lines, and the list starts under it and runs to the toolbar, over anything + * under the field (which comes up with the field's bottom). So the list never covers the caret's line. + * + * The room is measured to the field's bottom, since nothing reports how tall what's under it is. + * + * @param array{bottom: float, line_height: float, field_height: float}|null $caret + * @return array{field: int|null, top: int, height: int|null} + */ + public static function mentionLayout(?array $caret, int $rows, bool $heading = false): array + { + if ($caret === null || $caret['field_height'] <= 0) { + $line = $caret === null ? self::FirstLineHeight : (int) ceil($caret['bottom']); + + return ['field' => null, 'top' => self::FieldTop + $line + self::MentionGap, 'height' => null]; } - $lowest = self::FieldTop + (int) floor($caret['field_height']) - - self::MentionInset - self::MentionMinRows * self::MentionRowHeight - self::MentionPadding; + $list = self::mentionHeight($rows, $heading); + $field = (int) floor($caret['field_height']); + $bottom = (int) ceil($caret['bottom']); + $room = $field - $bottom - self::MentionGap - self::MentionInset; - return max(0, min($underCaret, $lowest)); + if ($room >= $list) { + return ['field' => null, 'top' => self::FieldTop + $bottom + self::MentionGap, 'height' => $list]; + } + + $line = $caret['line_height'] > 0 ? (int) ceil($caret['line_height']) : self::FirstLineHeight; + $shortened = max(self::MinFieldLines * $line, $field - self::MentionGap - self::MentionInset - $list); + + if ($shortened >= $bottom) { + // The caret is in the field's first lines already: shortening it frees nothing, so the list takes what + // room there is under the caret, at least a row. + return [ + 'field' => null, + 'top' => self::FieldTop + $bottom + self::MentionGap, + 'height' => max($room, self::MentionPadding + self::MentionRowHeight), + ]; + } + + return ['field' => $shortened, 'top' => self::FieldTop + $shortened + self::MentionGap, 'height' => null]; + } + + /** Whether the sheet's mention list has the "People you follow" heading: a bare "@" in a new commit. */ + public static function mentionHeading(?array $mention, string $view): bool + { + return ($mention['query'] ?? null) === '' && $view === 'compose'; } } diff --git a/app/NativeComponents/Concerns/OpensCommitSheet.php b/app/NativeComponents/Concerns/OpensCommitSheet.php index b4fc25af..3964a976 100644 --- a/app/NativeComponents/Concerns/OpensCommitSheet.php +++ b/app/NativeComponents/Concerns/OpensCommitSheet.php @@ -113,10 +113,10 @@ trait OpensCommitSheet public string $sheetBody = ''; /** - * Where the sheet's field last said its caret is drawn, for the mention list to float under (see ComposerSheet). - * Null until it has said, and again once the sheet is gone. + * Where the sheet's field last said its caret is drawn at its full height, for the mention list to go under (see + * ComposerSheet). Null until it has said, and again once the sheet is gone. * - * @var array{bottom: float, field_height: float}|null + * @var array{bottom: float, line_height: float, field_height: float}|null */ public ?array $sheetCaret = null; @@ -322,7 +322,26 @@ public function openScheduledCommits(): void */ public function sheetCaretMoved(Caret $caret): void { - $this->sheetCaret = ComposerSheet::caret($caret); + $this->sheetCaret = ComposerSheet::reported($caret, $this->sheetCaret, $this->sheetMentionLayout()['field'] ?? null); + } + + /** + * Where the sheet's mention list goes and how tall its field is meanwhile (see ComposerSheet::mentionLayout()), or + * null while there's no list. + * + * @return array{field: int|null, top: int, height: int|null}|null + */ + public function sheetMentionLayout(): ?array + { + if (($this->mention['field'] ?? null) !== 'sheetBody' || ($this->mentionPeople === [] && $this->mentionOrganizations === [])) { + return null; + } + + return ComposerSheet::mentionLayout( + $this->sheetCaret, + count($this->mentionPeople) + count($this->mentionOrganizations), + ComposerSheet::mentionHeading($this->mention, $this->sheetView), + ); } public function updatedSheetBody(): void diff --git a/resources/views/native/partials/commit-sheet.blade.php b/resources/views/native/partials/commit-sheet.blade.php index 55a945c9..1f21c144 100644 --- a/resources/views/native/partials/commit-sheet.blade.php +++ b/resources/views/native/partials/commit-sheet.blade.php @@ -26,10 +26,13 @@ A commit's page opens its reply here too, as "Reply to @handle", with the commit being answered as a static card over the field, for the photos and the preview its reply bar has no room for. Commit says Reply there. - While the caret is after an "@handle", the people to mention float over the field just under the caret's line, - which the field reports (@caretChange), as the web's composer lists them (see SuggestsMentions): for a bare "@" in a new commit, the people you follow, under - that heading. They cover a quoted commit too, and run down to the toolbar. The field keeps the keyboard up through - presses in the sheet (keep-focus), so picking someone leaves you typing after them. + While the caret is after an "@handle", the people to mention show as the web's composer lists them (see + SuggestsMentions): for a bare "@" in a new commit, the people you follow, under that heading. They float over the + field just under the caret's line, which the field reports (@caretChange), as tall as their rows, up to six. When + that doesn't fit above the field's bottom, the field gets shorter instead, ending on the caret's line, and the + list goes under it, down to the toolbar and over a quoted commit or poll (see ComposerSheet). The field fills + again once they're gone, and both moves are animated. The field keeps the keyboard up through presses in the sheet + (keep-focus), so picking someone leaves you typing after them. The sheet doesn't scroll. The field fills the space between the author row and the toolbar, less what's under it: the photos as a strip of 80pt squares, the poll editor, the commit being quoted, or "Submit at", each at its own @@ -105,7 +108,14 @@ @include('native.partials.quoted-commit', ['quoted' => $sheetCommit, 'static' => true, 'label' => 'Replying to']) @endif - + @php($sheetMentionsShown = ! $previewing && ($mention['field'] ?? null) === 'sheetBody' && ($mentionPeople !== [] || $mentionOrganizations !== [])) + @php($sheetMentions = $sheetMentionsShown ? $sheetLayout::mentionLayout($sheetCaret, count($mentionPeople) + count($mentionOrganizations), $sheetLayout::mentionHeading($mention, $sheetView)) : null) + {{-- + animate-layout: when the mention list comes or goes (or photos, the poll, the preview), the field + slot's new height and the parts under it slide into place rather than jump. The parts keep their + keys, so they're matched from one frame to the next. + --}} + @if ($previewing) @@ -121,7 +131,8 @@ @else - + {{-- Shorter while the mention list needs the room under it (see ComposerSheet::mentionLayout()), the slot keeps its key and place, so the field stays the same view. --}} + {{-- - The people to mention float over the field and whatever is under it, out of the layout, so - nothing moves when they come and go. They start just under the line the caret is on, where - the field says it is (see ComposerSheet::mentionTop()), and run down to the toolbar, - scrolling inside when there are more than fit. On Liquid Glass on iOS, like the reply - bar's, and on a raised surface on Android. + The people to mention, out of the layout so nothing moves when they come and go unless the + field has to make room for them: just under the caret's line, as tall as their rows, or + under the shortened field down to the toolbar (see ComposerSheet::mentionLayout()). They + scroll inside past six rows, or when even the shortened field leaves less room. On Liquid + Glass on iOS, like the reply bar's, and on a raised surface on Android. --}} - @if (($mention['field'] ?? null) === 'sheetBody' && ($mentionPeople !== [] || $mentionOrganizations !== [])) + @if ($sheetMentions !== null) @include('native.partials.mention-suggestions', [ 'field' => 'sheetBody', - 'heading' => ($mention['query'] ?? null) === '' && $sheetView === 'compose' ? 'People you follow' : null, + 'heading' => $sheetLayout::mentionHeading($mention, $sheetView) ? 'People you follow' : null, 'label' => 'Mention a developer', 'class' => 'w-full py-1', ]) diff --git a/tests/Feature/Screens/CommitMentionsTest.php b/tests/Feature/Screens/CommitMentionsTest.php index effbc57e..4ee44cb0 100644 --- a/tests/Feature/Screens/CommitMentionsTest.php +++ b/tests/Feature/Screens/CommitMentionsTest.php @@ -6,6 +6,7 @@ use Native\Mobile\Testing\Native; use Native\Mobile\Testing\TestableComponent; use Native\Mobile\UI\Caret; +use Tests\Support\LayoutAnimation; use Tests\Support\TextFieldFill; beforeEach(function () { @@ -185,7 +186,7 @@ function mentionsComposer(bool $quoting = false): TestableComponent ->assertSet('mentionPeople', []); }); -it('floats the suggestions over the quoted commit on glass, from just under the caret line down to the toolbar', function () { +it('floats the suggestions over the quoted commit on glass, just under the caret line and as tall as their rows', function () { TextFieldFill::skipUnlessSupported(); $screen = mentionsComposer(quoting: true) @@ -198,9 +199,12 @@ function mentionsComposer(bool $quoting = false): TestableComponent ->and($overlay['layout']['position'])->toEqual([ ComposerSheet::FieldTop + 44 + ComposerSheet::MentionGap, 12, - ComposerSheet::MentionInset, + null, 12, ]) + ->and($overlay['layout']['height'] ?? null)->toEqual(ComposerSheet::mentionHeight(3)) + // There's room for them under the caret, so the field still fills. + ->and(nodeByRef($screen, 'sheet-field-slot')['layout']['flex_grow'] ?? null)->toEqual(1) ->and($overlay['props']['glass'])->toBe(1) ->and(childRefs($screen, 'sheet-body-area'))->toBe(['sheet-field-slot', 'sheet-below', 'sheet-mentions']) ->and(findNode(nodeByRef($screen, 'sheet-below'), fn (array $node): bool => ($node['ref'] ?? null) === 'quote-card'))->not->toBeNull() @@ -209,6 +213,42 @@ function mentionsComposer(bool $quoting = false): TestableComponent ->and(childRefs($screen, 'mention-suggestions'))->toBe(['mention-ada', 'mention-adam', 'mention-adaptive']); }); +it('shortens the field to end on the caret line when the suggestions would not fit under it, and fills it again once they go', function () { + TextFieldFill::skipUnlessSupported(); + + $screen = mentionsComposer(quoting: true)->input('sheet-body', "see\n\n\n\n\n\n\n\n@a", 14); + $field = idsDownTo($screen->tree(), 'sheet-body'); + + // The caret's line ends 20pt above the field's bottom, where three people don't fit. + $screen->moveCaretTo('sheet-body', new Caret(x: 20, y: 196, width: 2, height: 24, line: 8, fieldWidth: 350, fieldHeight: 240)); + $shortened = 240 - ComposerSheet::MentionGap - ComposerSheet::MentionInset - ComposerSheet::mentionHeight(3); + $overlay = nodeByRef($screen, 'sheet-mentions'); + + expect(nodeByRef($screen, 'sheet-field-slot')['layout']['height'] ?? null)->toEqual(ComposerSheet::FieldTop + $shortened) + ->and(nodeByRef($screen, 'sheet-field-slot')['layout']['flex_grow'] ?? 0)->toEqual(0) + // Under the shortened field, so off the caret's line, and down to the toolbar over the quoted commit. + ->and($overlay['layout']['position'])->toEqual([ComposerSheet::FieldTop + $shortened + ComposerSheet::MentionGap, 12, ComposerSheet::MentionInset, 12]) + ->and(childRefs($screen, 'sheet-body-area'))->toBe(['sheet-field-slot', 'sheet-below', 'sheet-mentions']) + ->and(idsDownTo($screen->tree(), 'sheet-body'))->toBe($field); + + // The shortened field reports its caret at its new height, which doesn't move anything. + $screen->moveCaretTo('sheet-body', new Caret(x: 20, y: $shortened - 24, width: 2, height: 24, line: 8, fieldWidth: 350, fieldHeight: $shortened)) + ->assertSet('sheetCaret', ['bottom' => 220.0, 'line_height' => 24.0, 'field_height' => 240.0]); + + // Picked, the list goes and the field fills again, the same view. + $screen->tap('mention-ada'); + expect(findNode($screen->tree(), fn (array $node): bool => ($node['ref'] ?? null) === 'sheet-mentions'))->toBeNull() + ->and(nodeByRef($screen, 'sheet-field-slot')['layout']['flex_grow'] ?? null)->toEqual(1) + ->and(nodeByRef($screen, 'sheet-field-slot')['layout'])->not->toHaveKey('height') + ->and(idsDownTo($screen->tree(), 'sheet-body'))->toBe($field); +}); + +it('animates the field and the suggestions moving in the sheet', function () { + LayoutAnimation::skipUnlessSupported(); + + expect(nodeByRef(mentionsComposer(), 'sheet-body-area')['props'])->toHaveKey('animate_layout', true); +}); + it('draws the floating suggestions on a raised surface on Android', function () { fakeApi([ 'GET /api/v1/log/following' => [pageJson([])], diff --git a/tests/Feature/Screens/ComposeSheetTest.php b/tests/Feature/Screens/ComposeSheetTest.php index 100b5877..1bfc7e9b 100644 --- a/tests/Feature/Screens/ComposeSheetTest.php +++ b/tests/Feature/Screens/ComposeSheetTest.php @@ -312,7 +312,7 @@ function sheetCommitDisabled(TestableComponent $screen): bool $screen = composeSheetOnLog() ->moveCaretTo('sheet-body', new Caret(y: 48, height: 24, line: 2, fieldWidth: 350, fieldHeight: 240)) - ->assertSet('sheetCaret', ['bottom' => 72.0, 'field_height' => 240.0]); + ->assertSet('sheetCaret', ['bottom' => 72.0, 'line_height' => 24.0, 'field_height' => 240.0]); $screen->press('hideCommitSheet')->assertSet('sheetCaret', null); }); diff --git a/tests/Support/LayoutAnimation.php b/tests/Support/LayoutAnimation.php new file mode 100644 index 00000000..155686c8 --- /dev/null +++ b/tests/Support/LayoutAnimation.php @@ -0,0 +1,25 @@ +markTestSkipped('Needs a mobile-air with layout animation (NativePHP/mobile-air#736)'); + } + } +} diff --git a/tests/Unit/Devnull/ComposerSheetTest.php b/tests/Unit/Devnull/ComposerSheetTest.php index 28ccd184..8832a306 100644 --- a/tests/Unit/Devnull/ComposerSheetTest.php +++ b/tests/Unit/Devnull/ComposerSheetTest.php @@ -6,25 +6,81 @@ beforeEach(fn () => TextFieldFill::skipUnlessSupported()); -it('starts the mention list just under the line the field says the caret is on', function () { - $caret = ComposerSheet::caret(new Caret(y: 48, height: 24, line: 2, fieldHeight: 300)); +/** A field 360pt tall, as on a phone with the keyboard up, with its caret's line ending at $bottom. */ +function composerCaret(float $bottom, float $fieldHeight = 360): array +{ + return ComposerSheet::caret(new Caret(y: $bottom - 24, height: 24, fieldHeight: $fieldHeight)); +} - expect(ComposerSheet::mentionTop($caret))->toBe(ComposerSheet::FieldTop + 72 + ComposerSheet::MentionGap); +it('floats the list just under the caret, as tall as its rows, when they fit above the field\'s bottom', function () { + $layout = ComposerSheet::mentionLayout(composerCaret(72), rows: 3); + + expect($layout)->toBe([ + 'field' => null, + 'top' => ComposerSheet::FieldTop + 72 + ComposerSheet::MentionGap, + 'height' => ComposerSheet::MentionPadding + 3 * ComposerSheet::MentionRowHeight, + ]); +}); + +it('holds the list to six rows, plus its heading, and scrolls the rest', function () { + expect(ComposerSheet::mentionHeight(10))->toBe(ComposerSheet::MentionPadding + 6 * ComposerSheet::MentionRowHeight) + ->and(ComposerSheet::mentionHeight(2, heading: true))->toBe(ComposerSheet::MentionPadding + ComposerSheet::MentionHeadingHeight + 2 * ComposerSheet::MentionRowHeight); +}); + +it('shortens the field to end on the caret\'s line when the list would not fit under it, and puts the list under the field', function () { + // The caret low in the field, as in build 42: six people need 272pt, and there's 360 - 300 under the caret. + $layout = ComposerSheet::mentionLayout(composerCaret(300), rows: 8); + $list = ComposerSheet::mentionHeight(8); + $field = 360 - ComposerSheet::MentionGap - ComposerSheet::MentionInset - $list; + + expect($layout)->toBe(['field' => $field, 'top' => ComposerSheet::FieldTop + $field + ComposerSheet::MentionGap, 'height' => null]) + // The list starts under the caret's line, never over it: the field ends on that line. + ->and($layout['top'])->toBeGreaterThan(ComposerSheet::FieldTop + $layout['field']) + // And the list has its six rows from there to the toolbar. + ->and(ComposerSheet::FieldTop + 360 - ComposerSheet::MentionInset - $layout['top'])->toBe($list); +}); + +it('shortens the field only as far as the list needs', function () { + $layout = ComposerSheet::mentionLayout(composerCaret(300), rows: 2); + + expect($layout['field'])->toBe(360 - ComposerSheet::MentionGap - ComposerSheet::MentionInset - ComposerSheet::mentionHeight(2)) + ->and($layout['field'])->toBeLessThan(300); +}); + +it('keeps two lines of field on a short phone, and the list scrolls in what\'s left', function () { + $layout = ComposerSheet::mentionLayout(composerCaret(140, fieldHeight: 160), rows: 6); + + expect($layout)->toBe(['field' => ComposerSheet::MinFieldLines * 24, 'top' => ComposerSheet::FieldTop + 48 + ComposerSheet::MentionGap, 'height' => null]); +}); + +it('leaves the field alone when the caret is already in its first lines', function () { + $layout = ComposerSheet::mentionLayout(composerCaret(24, fieldHeight: 160), rows: 6); + + expect($layout['field'])->toBeNull() + ->and($layout['top'])->toBe(ComposerSheet::FieldTop + 24 + ComposerSheet::MentionGap) + ->and($layout['height'])->toBe(160 - 24 - ComposerSheet::MentionGap - ComposerSheet::MentionInset); }); -it('moves the list up when the caret is too near the field\'s bottom to leave room for three people', function () { - $lowest = ComposerSheet::FieldTop + 300 - ComposerSheet::MentionInset - ComposerSheet::MentionMinRows * ComposerSheet::MentionRowHeight - ComposerSheet::MentionPadding; +it('keeps where the caret is at the field\'s full height while the field is shortened', function () { + $kept = composerCaret(300); + $shortened = ComposerSheet::mentionLayout($kept, rows: 8)['field']; - expect(ComposerSheet::mentionTop(ComposerSheet::caret(new Caret(y: 264, height: 24, fieldHeight: 300))))->toBe($lowest) - // A field too short for three people puts the list at the top of it. - ->and(ComposerSheet::mentionTop(ComposerSheet::caret(new Caret(y: 24, height: 24, fieldHeight: 80))))->toBe(0); + // The shortened field reports itself scrolled to the caret: that's not where the caret is at full height. + expect(ComposerSheet::reported(new Caret(y: $shortened - 24, height: 24, fieldHeight: $shortened), $kept, $shortened))->toBe($kept) + // A report at another height is the field at its full height again. + ->and(ComposerSheet::reported(new Caret(y: 48, height: 24, fieldHeight: 360), $kept, $shortened))->toBe(composerCaret(72)) + ->and(ComposerSheet::reported(new Caret(y: 48, height: 24, fieldHeight: 360), $kept, null))->toBe(composerCaret(72)); }); it('keeps a caret the field has scrolled out of view to the field\'s edges', function () { - expect(ComposerSheet::caret(new Caret(y: -60, height: 24, fieldHeight: 300)))->toBe(['bottom' => 0.0, 'field_height' => 300.0]) - ->and(ComposerSheet::caret(new Caret(y: 400, height: 24, fieldHeight: 300)))->toBe(['bottom' => 300.0, 'field_height' => 300.0]); + expect(ComposerSheet::caret(new Caret(y: -60, height: 24, fieldHeight: 300)))->toBe(['bottom' => 0.0, 'line_height' => 24.0, 'field_height' => 300.0]) + ->and(ComposerSheet::caret(new Caret(y: 400, height: 24, fieldHeight: 300)))->toBe(['bottom' => 300.0, 'line_height' => 24.0, 'field_height' => 300.0]); }); -it('puts the list under about one line before the field has said where its caret is', function () { - expect(ComposerSheet::mentionTop(null))->toBe(ComposerSheet::FieldTop + ComposerSheet::FirstLineHeight + ComposerSheet::MentionGap); +it('puts the list under about one line, down to the toolbar, before the field has said where its caret is', function () { + expect(ComposerSheet::mentionLayout(null, rows: 3))->toBe([ + 'field' => null, + 'top' => ComposerSheet::FieldTop + ComposerSheet::FirstLineHeight + ComposerSheet::MentionGap, + 'height' => null, + ]); }); From 75cb547a4c2f8d66b6a9898882f82c252a7d6f4d Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 11:00:46 +0000 Subject: [PATCH 4/5] Ask the sheet's mention list not to scroll inside its own scroll view The sheet sizes its mention list and scrolls it. #196 gives the shared mention list a six-row scroll view of its own, so once both are merged a list of more than six would show two scroll bars on a short phone. The sheet now passes 'scrolls' => false, which #196 adds. Before #196 merges the partial ignores it. Co-Authored-By: Claude Opus 5.5 --- .../native/partials/commit-sheet.blade.php | 2 ++ tests/Feature/Screens/CommitMentionsTest.php | 21 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/resources/views/native/partials/commit-sheet.blade.php b/resources/views/native/partials/commit-sheet.blade.php index 1f21c144..752f5022 100644 --- a/resources/views/native/partials/commit-sheet.blade.php +++ b/resources/views/native/partials/commit-sheet.blade.php @@ -191,6 +191,8 @@ class="absolute left-[12] right-[12] top-[{{ $sheetMentions['top'] }}] {{ $sheet 'heading' => $sheetLayout::mentionHeading($mention, $sheetView) ? 'People you follow' : null, 'label' => 'Mention a developer', 'class' => 'w-full py-1', + // This scroll view scrolls them; the partial's own six-row one would be a second. + 'scrolls' => false, ]) diff --git a/tests/Feature/Screens/CommitMentionsTest.php b/tests/Feature/Screens/CommitMentionsTest.php index 4ee44cb0..471b2886 100644 --- a/tests/Feature/Screens/CommitMentionsTest.php +++ b/tests/Feature/Screens/CommitMentionsTest.php @@ -74,11 +74,11 @@ function mentionsCommitPage(?array $mentions = null): TestableComponent * The Log, with Ada's c1 in it and devnull's mention search answering, and the composer sheet open: for a new commit, * or for a quote of c1. */ -function mentionsComposer(bool $quoting = false): TestableComponent +function mentionsComposer(bool $quoting = false, ?array $mentions = null): TestableComponent { fakeApi([ 'GET /api/v1/log/following' => [pageJson([commitJson(['id' => 'c1', 'body' => 'Required reading.', 'author' => userJson(['id' => 'u2', 'handle' => 'ada', 'name' => 'Ada Lovelace'])])])], - 'GET /api/v1/search/mentions' => mentionsFound(), + 'GET /api/v1/search/mentions' => $mentions ?? mentionsFound(), ]); $screen = Native::visit('/log', platform: 'ios'); @@ -213,6 +213,23 @@ function mentionsComposer(bool $quoting = false): TestableComponent ->and(childRefs($screen, 'mention-suggestions'))->toBe(['mention-ada', 'mention-adam', 'mention-adaptive']); }); +it('scrolls a long list of suggestions in the sheet with one scroll view, its own', function () { + TextFieldFill::skipUnlessSupported(); + + $people = array_map(fn (int $n): array => userJson(['id' => "u{$n}", 'handle' => "ada{$n}", 'name' => "Ada {$n}"]), range(1, 9)); + $screen = mentionsComposer(mentions: [['data' => $people]]) + ->input('sheet-body', "see\n\n\n\n\n\n@a", 12) + ->moveCaretTo('sheet-body', new Caret(x: 20, y: 132, width: 2, height: 22, line: 6, fieldWidth: 350, fieldHeight: 240)); + $overlay = nodeByRef($screen, 'sheet-mentions'); + + // Nine rows is past the six the mention list scrolls by itself, but the sheet scrolls it already, so there is no + // second scroll view inside (two scroll bars on a short phone). + expect(findNodes($overlay, fn (array $node): bool => $node['type'] === 'scroll_view'))->toHaveCount(1) + ->and(nodeByRef($screen, 'sheet-mentions-scroll')['type'])->toBe('scroll_view') + ->and(rendersRef($screen, 'mention-scroll'))->toBeFalse() + ->and(childRefs($screen, 'mention-suggestions'))->toBe(array_map(fn (int $n): string => "mention-ada{$n}", range(1, 9))); +}); + it('shortens the field to end on the caret line when the suggestions would not fit under it, and fills it again once they go', function () { TextFieldFill::skipUnlessSupported(); From 59988ed55bf458619861888b52d303f0b802229f Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sun, 22 Nov 2026 13:14:51 +0000 Subject: [PATCH 5/5] Keep a quoted commit clear of the composer sheet's toolbar What sits under the field (the quoted commit, photos, the poll, "Submit at") had padding above it but none below, so the quote card ran into the toolbar's line. It now leaves 12pt there, the same gap the field leaves under "Replying to". Co-Authored-By: Claude Opus 5.5 --- resources/views/native/partials/commit-sheet.blade.php | 4 ++-- tests/Feature/Screens/QuoteTest.php | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/resources/views/native/partials/commit-sheet.blade.php b/resources/views/native/partials/commit-sheet.blade.php index 752f5022..66fea73d 100644 --- a/resources/views/native/partials/commit-sheet.blade.php +++ b/resources/views/native/partials/commit-sheet.blade.php @@ -36,7 +36,7 @@ The sheet doesn't scroll. The field fills the space between the author row and the toolbar, less what's under it: the photos as a strip of 80pt squares, the poll editor, the commit being quoted, or "Submit at", each at its own - height. Only the field scrolls its text. A toolbar is pinned to the bottom of the sheet, so + height, with 12pt clear of the toolbar, as the field leaves under "Replying to". Only the field scrolls its text. A toolbar is pinned to the bottom of the sheet, so it stays just above the keyboard: the tools on the left, photos, the camera, a poll (not on a reply) and the preview, which shows the draft as the commit it would become in place of the field (see AttachesToCommits), and stash@{0} and the counter on the right. An issue draft has no tools, as on the web. With photos, Commit spins while @@ -152,7 +152,7 @@ class="w-full h-full text-theme-ink" /> @php($hasBelow = $linkTooLong || $sheetImages !== [] || $pollShown || $quoting || $scheduling || $issueCommands !== [] || $issueHint !== null) - + @if ($linkTooLong) Each link must not be greater than {{ \App\Devnull\Data\BodyLink::MaxLength }} characters. @endif diff --git a/tests/Feature/Screens/QuoteTest.php b/tests/Feature/Screens/QuoteTest.php index e9a1eb92..cc716537 100644 --- a/tests/Feature/Screens/QuoteTest.php +++ b/tests/Feature/Screens/QuoteTest.php @@ -220,5 +220,7 @@ function quoteButtonDisabled(TestableComponent $screen): bool expect(childRefs($screen, 'sheet-below'))->toBe(['quote-card']) ->and(childRefs($screen, 'sheet-body-area'))->toBe(['sheet-field-slot', 'sheet-below']) - ->and(nodeByRef($screen, 'sheet-body')['props']['fills_height'] ?? null)->toBeTrue(); + ->and(nodeByRef($screen, 'sheet-body')['props']['fills_height'] ?? null)->toBeTrue() + // [top, right, bottom, left]: the card keeps clear of the toolbar, as the field does of "Replying to". + ->and(nodeByRef($screen, 'sheet-below')['layout']['padding'])->toEqual([12, 20, 12, 20]); });