diff --git a/app/Devnull/ComposerSheet.php b/app/Devnull/ComposerSheet.php
new file mode 100644
index 00000000..80a3ccf7
--- /dev/null
+++ b/app/Devnull/ComposerSheet.php
@@ -0,0 +1,151 @@
+fieldHeight);
+ $bottom = max(0.0, $caret->bottom());
+
+ return [
+ 'bottom' => $field > 0 ? min($bottom, $field) : $bottom,
+ 'line_height' => max(0.0, $caret->height),
+ 'field_height' => $field,
+ ];
+ }
+
+ /**
+ * 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, 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 reported(Caret $caret, ?array $kept, ?int $shortened): array
+ {
+ if ($kept !== null && $shortened !== null && abs($caret->fieldHeight - $shortened) <= 1) {
+ return $kept;
+ }
+
+ return self::caret($caret);
+ }
+
+ /** 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];
+ }
+
+ $list = self::mentionHeight($rows, $heading);
+ $field = (int) floor($caret['field_height']);
+ $bottom = (int) ceil($caret['bottom']);
+ $room = $field - $bottom - self::MentionGap - self::MentionInset;
+
+ 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 06df216a..3964a976 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 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, line_height: 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,33 @@ 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::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
{
$this->typeIssueCommand();
@@ -493,6 +530,7 @@ private function closeCommitSheet(): void
{
$this->sheetClosing = $this->sheetClosing || ($this->sheetOpen && System::isIos());
$this->sheetOpen = false;
+ $this->sheetCaret = null;
$this->forgetMention('sheetBody');
}
@@ -606,6 +644,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 1af931c2..66fea73d 100644
--- a/resources/views/native/partials/commit-sheet.blade.php
+++ b/resources/views/native/partials/commit-sheet.blade.php
@@ -26,11 +26,17 @@
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 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.
- 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, 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
@@ -70,68 +76,90 @@
@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 (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)
+ @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($hasAbove = $postsAs || $sheetError || $issueCommand || $replying)
+
+ @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
+
+ @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)
+
+
+ @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
+ {{-- 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. --}}
+
-
- @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 = $linkTooLong || $sheetImages !== [] || $pollShown || $quoting || $scheduling || $issueCommands !== [] || $issueHint !== null)
+
+ @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 +167,39 @@ 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, 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 ($sheetMentions !== null)
+
+
+ @include('native.partials.mention-suggestions', [
+ 'field' => 'sheetBody',
+ '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,
+ ])
+
+
+ @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..471b2886 100644
--- a/tests/Feature/Screens/CommitMentionsTest.php
+++ b/tests/Feature/Screens/CommitMentionsTest.php
@@ -1,9 +1,13 @@
'http://devnull.test']);
@@ -70,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');
@@ -181,3 +185,95 @@ function mentionsComposer(bool $quoting = false): TestableComponent
->assertSet('mention', null)
->assertSet('mentionPeople', []);
});
+
+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)
+ ->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::FieldTop + 44 + ComposerSheet::MentionGap,
+ 12,
+ 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()
+ // 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('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();
+
+ $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([])],
+ '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..1bfc7e9b 100644
--- a/tests/Feature/Screens/ComposeSheetTest.php
+++ b/tests/Feature/Screens/ComposeSheetTest.php
@@ -1,11 +1,14 @@
'http://devnull.test']);
@@ -281,6 +284,56 @@ function sheetCommitDisabled(TestableComponent $screen): bool
->and(idsDownTo($screen->tree(), 'sheet-body'))->toBe($field);
});
+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 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('puts the poll under the field, which gives up the room it takes', function () {
+ $screen = composeSheetOnLog()->tap('sheet-poll');
+
+ 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, 'line_height' => 24.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([])],
+ '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..cc716537 100644
--- a/tests/Feature/Screens/QuoteTest.php
+++ b/tests/Feature/Screens/QuoteTest.php
@@ -5,6 +5,7 @@
use Illuminate\Support\Facades\Http;
use Native\Mobile\Testing\Native;
use Native\Mobile\Testing\TestableComponent;
+use Tests\Support\TextFieldFill;
beforeEach(function () {
config(['devnull.url' => 'http://devnull.test']);
@@ -211,3 +212,15 @@ function quoteButtonDisabled(TestableComponent $screen): bool
expect(nodeByRef($screen, 'sheet')['props']['visible'])->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 () {
+ TextFieldFill::skipUnlessSupported();
+
+ $screen = quoteSheetOnLog();
+
+ 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()
+ // [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]);
+});
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/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
new file mode 100644
index 00000000..8832a306
--- /dev/null
+++ b/tests/Unit/Devnull/ComposerSheetTest.php
@@ -0,0 +1,86 @@
+ TextFieldFill::skipUnlessSupported());
+
+/** 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));
+}
+
+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('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'];
+
+ // 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, '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, 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,
+ ]);
+});