Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 151 additions & 0 deletions app/Devnull/ComposerSheet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?php

namespace App\Devnull;

use Native\Mobile\UI\Caret;

/**
* 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`). 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
{
/** 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;

/**
* The mention list's rows, and how many show before the rest scroll inside it. The same as the lists by the other
* fields (see Display), whose row height partials/mention-suggestions draws.
*/
public const int MentionRowHeight = Display::MentionRowHeight;

public const int MentionRowsShown = Display::MentionRowsShown;

/** 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;

/**
* 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, and a line is taken to be this tall.
*/
public const int FirstLineHeight = 24;

/**
* 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, 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,
'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';
}
}
117 changes: 115 additions & 2 deletions app/Devnull/Display.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use App\Devnull\Data\CommitBody;
use Carbon\CarbonImmutable;
use Carbon\CarbonInterface;
use Native\Mobile\Edge\Elements\BottomBar;
use Native\Mobile\Facades\System;
use Native\Mobile\Platform;

/**
Expand Down Expand Up @@ -58,6 +60,29 @@ final class Display
*/
public const int ComposerGlassOpacity = 80;

/**
* The first iOS whose scroll views draw a scroll edge effect under a bar (see hasScrollEdge()).
*/
public const int ScrollEdgeIosVersion = 26;

/**
* Whether a composer's field and its row of tools sit in a rounded Liquid Glass box over the scroll edge effect,
* as in Messages (see composerInGlassBox()). Off, they sit straight on the effect. Only on iOS 26 and later.
*/
public const bool ComposerInGlassBox = true;

/**
* Which scroll edge effect iOS 26 and later draw under a composer bar (see composerEdgeBlur()): "soft", the
* progressive blur under the system's own toolbars, or "hard", an opaque fade.
*/
public const string ComposerEdgeBlur = 'soft';

/**
* A bar holding partials/composer-box in its glass box with one line of draft: ComposerBoxBarHeight, plus the
* box's own padding over and under what it holds (see composerBox()).
*/
public const int ComposerGlassBoxBarHeight = 100;

/**
* About how many characters fit on a line of the box's field, which runs the width of the box.
*/
Expand Down Expand Up @@ -264,8 +289,8 @@ public static function maskedKey(string $openSsh): string
*/
public static function replyBarClearance(string $draft, bool $hasPhotos = false, bool $describing = false): int
{
return self::ComposerFadeHeight
+ self::ComposerBoxBarHeight
return self::composerFadeHeight()
+ self::composerBoxBarHeight()
+ self::composerBoxGrowth($draft)
+ ($hasPhotos ? self::ReplyBarPhotosHeight : 0)
+ ($hasPhotos && $describing ? self::ReplyBarDescriptionHeight : 0)
Expand Down Expand Up @@ -313,19 +338,103 @@ public static function fadesInBar(): bool
return Platform::isIos();
}

/**
* Whether the composer bars stand on iOS's own scroll edge effect: iOS 26 and later blur what scrolls under the
* bar, as under its own toolbars, from the bar's edge-blur attribute (see composerEdgeBlur()). That stands in for
* the fade and the tinted glass, so a bar there draws neither and lets the effect show. Older iOS keeps the fade
* over glass, and Android its fade over the surface.
*
* It needs a mobile-air that takes edge-blur on a bottom bar and says which iOS the phone runs
* (System::osVersion()). Without one this is false and every iOS keeps the fade.
*/
public static function hasScrollEdge(): bool
{
if (! Platform::isIos()
|| ! method_exists(\Native\Mobile\System::class, 'osVersion')
|| ! method_exists(BottomBar::class, 'edgeBlurStyle')) {
return false;
}

return (int) System::osVersion() >= self::ScrollEdgeIosVersion;
}

/**
* Whether a composer bar draws partials/composer-fade as its first row: on iOS, before the scroll edge effect.
*/
public static function fadeRowInBar(): bool
{
return self::fadesInBar() && ! self::hasScrollEdge();
}

/**
* Whether the composer's field and tools sit in a rounded Liquid Glass box on the bar (ComposerInGlassBox): on
* iOS 26 and later, over the scroll edge effect. Older iOS and Android draw them straight on the bar, as before.
*/
public static function composerInGlassBox(): bool
{
return self::ComposerInGlassBox && self::hasScrollEdge();
}

/**
* The classes for partials/composer-box's outer column. In the glass box it's rounded to match the send button
* inside it, which sits 8pt in from its right and bottom edges: the row of tools leaves 6pt at its end and 2pt
* under the button, and the box 2pt more under the row.
*/
public static function composerBox(): string
{
return self::composerInGlassBox() ? 'rounded-[24] glass pb-[2]' : '';
}

/**
* The padding over the field inside partials/composer-box. In the glass box the field sits as far under the
* box's top edge as the row of tools sits under the field, 16pt to the text either way.
*/
public static function composerFieldTop(): string
{
return self::composerInGlassBox() ? 'pt-2' : 'pt-1';
}

/**
* How tall a composer bar is with one line of draft (see ComposerBoxBarHeight and ComposerGlassBoxBarHeight).
*/
public static function composerBoxBarHeight(): int
{
return self::composerInGlassBox() ? self::ComposerGlassBoxBarHeight : self::ComposerBoxBarHeight;
}

/**
* How tall the composer fade is where it's drawn: none where the scroll edge effect replaces it.
*/
public static function composerFadeHeight(): int
{
return self::hasScrollEdge() ? 0 : self::ComposerFadeHeight;
}

/**
* The classes for a composer's native:bottom-bar. On iOS that's Liquid Glass: what scrolls under the bar shows
* through it, blurred. A patched mobile-air draws the glass behind the whole bar, under the home indicator too,
* and fades it in over the bar's top ComposerFadeHeight points, so it has no hard top edge. EDGE's own glass on
* an element can't be faded, and stops short of the home indicator. The glass stops at ComposerGlassOpacity
* percent (glass/N), so a little of the screen under the bar shows through. Android has no glass, so the bar
* stays the surface there.
*
* From iOS 26 the bar's edge-blur takes the glass's place (see composerEdgeBlur()).
*/
public static function composerBarGlass(): string
{
return self::fadesInBar() ? 'glass/'.self::ComposerGlassOpacity : '';
}

/**
* The edge-blur attribute for a composer's native:bottom-bar: on iOS, ComposerEdgeBlur, so iOS 26 and later draw
* the system's scroll edge effect under the bar, and mobile-air leaves the bar's glass out there. Older iOS ignores
* it and keeps the glass. Android has no such effect, so nothing is asked there.
*/
public static function composerEdgeBlur(): string
{
return self::fadesInBar() ? self::ComposerEdgeBlur : '';
}

/**
* The composer bar's own classes. On Android it's the surface. On iOS it has no background at all: mobile-air
* paints a bar's background colour behind the whole bar, which would cover the fade at its top, so the bar's
Expand All @@ -344,6 +453,10 @@ public static function composerBar(): string
*/
public static function composerSurface(): string
{
if (self::hasScrollEdge()) {
return '';
}

return self::fadesInBar() ? 'bg-theme-surface/'.self::ComposerGlassTint : 'bg-theme-surface';
}

Expand Down
39 changes: 39 additions & 0 deletions app/NativeComponents/Concerns/OpensCommitSheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,6 +22,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
Expand Down Expand Up @@ -122,6 +124,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).
*/
Expand Down Expand Up @@ -328,6 +338,33 @@ public function openScheduledCommits(): void
$this->sheetOpen = false;
}

/**
* 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),
);
}

/**
* Stashes the draft as it changes (see stashSheetDraft()).
*/
Expand Down Expand Up @@ -536,6 +573,7 @@ private function closeCommitSheet(): void
{
$this->sheetClosing = $this->sheetClosing || ($this->sheetOpen && System::isIos());
$this->sheetOpen = false;
$this->sheetCaret = null;
$this->forgetMention('sheetBody');
}

Expand Down Expand Up @@ -666,6 +704,7 @@ private function forgetCommitSheet(): void
$this->reportReason = '';
$this->reportDetails = '';
$this->sheetBody = '';
$this->sheetCaret = null;
$this->sheetAuthor = null;
$this->sheetRestored = false;
$this->sheetError = null;
Expand Down
Loading
Loading