Skip to content
Draft
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
34 changes: 34 additions & 0 deletions app/Devnull/Beat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Devnull;

use Native\Mobile\AsyncTask;

/**
* Waits $milliseconds on one of NativePHP's background PHP threads, so a
* screen can draw a frame, then change it once the phone has drawn it.
*
* EDGE animates a node from what it showed to what the next frame says
* (`animate-duration`), but it can't play a sequence or animate a row as it
* comes into a list. A screen draws the first step, and the next one when its
* Beat comes back: replies drawn see-through then faded in, a star scaled up
* then sprung back (see Concerns\ExpandsThreads and Concerns\PopsReactions).
*/
final class Beat extends AsyncTask
{
/**
* How long a frame waits for the next step of an animation, so the phone
* has drawn it first.
*/
public const int Step = 60;

public function handle(int $milliseconds): bool
{
// Tests run tasks inline, where only the order of the steps counts.
if (! app()->runningUnitTests()) {
usleep(max(0, $milliseconds) * 1000);
}

return true;
}
}
6 changes: 3 additions & 3 deletions app/Devnull/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@
public const string IssuesPath = 'issues';

/**
* How many replies the app asks for at a time. devnull sends 50 a page
* unless it's asked for fewer, and the app never asks for more than this.
* How many replies the app asks for at a time, in a feed's thread and on
* a commit's page. devnull sends 50 a page unless it's asked for fewer.
*/
public const int RepliesPerPage = 5;
public const int RepliesPerPage = 10;

/**
* Where the signed-in account's timezone is saved, or unset, with whether their profile shows their local time.
Expand Down
6 changes: 0 additions & 6 deletions app/Devnull/Display.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ final class Display
*/
public const int HomeIndicatorHeight = 34;

/**
* How far below the top of a reply's row its elbow comes level with the
* middle of the reply's avatar.
*/
public const int ElbowLevel = 22;

/**
* How long ago a commit was made, as the web prints it beside the commit:
* "now", "5m", "3h", "2d", then the date, in the same time zone as dayLabel().
Expand Down
39 changes: 39 additions & 0 deletions app/Devnull/Pop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Devnull;

/**
* How a star or a pastel looks at each step of the pop it gives when tapped,
* after the web's: the star grows to 1.35 tilted 12 degrees and springs back
* (`star-pop`), the pastel grows to 1.25 and settles (its button's
* `animate()`). See Concerns\PopsReactions for the steps.
*/
final class Pop
{
/**
* Drawn as it is, with the animation that the next step uses, so the phone
* has a node to animate from.
*/
public const string Ready = 'ready';

public const string Up = 'up';

public const string Down = 'down';

/**
* The icon's transform at $step, or nulls when it isn't popping.
*
* @return array{scale: float|null, rotate: float|null, duration: int|null, easing: string|null}
*/
public static function transform(?string $step, string $button): array
{
$star = $button === 'star';

return match ($step) {
self::Ready => ['scale' => 1.0, 'rotate' => 0.0, 'duration' => 150, 'easing' => 'ease-out'],
self::Up => ['scale' => $star ? 1.35 : 1.25, 'rotate' => $star ? -12.0 : 0.0, 'duration' => 150, 'easing' => 'ease-out'],
self::Down => ['scale' => 1.0, 'rotate' => 0.0, 'duration' => $star ? 320 : 180, 'easing' => $star ? 'spring' : 'ease-out'],
default => ['scale' => null, 'rotate' => null, 'duration' => null, 'easing' => null],
};
}
}
4 changes: 3 additions & 1 deletion app/Devnull/RowInputs.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public static function for(Commit $commit, array $scope): array
'stashed' => $scope['stashed'] ?? [],
'unfolded' => $scope['unfolded'] ?? [],
'expandable' => isset($scope['threads']),
'opened' => array_key_exists($commit->id, $scope['threads'] ?? []),
'opened' => array_key_exists($commit->id, $scope['threads'] ?? []) && ! in_array($commit->id, $scope['closingThreads'] ?? [], true),
'faded' => in_array($commit->id, $scope['fadedRows'] ?? [], true),
'popping' => [$scope['popping']['star-'.$commit->id] ?? null, $scope['popping']['pastel-'.$commit->id] ?? null],
'tombstones' => $scope['tombstones'] ?? false,
'tombstoneReplies' => array_key_exists($commit->id, $scope['tombstoneReplies'] ?? []),
'shown' => [self::changing($commit), $commit->quotedCommit === null ? null : self::changing($commit->quotedCommit)],
Expand Down
129 changes: 129 additions & 0 deletions app/Devnull/ThreadRows.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?php

namespace App\Devnull;

use App\Devnull\Data\Commit;

/**
* The list rows of a commit's thread opened in a feed (see
* Concerns\ExpandsThreads), in order, each with what its partial draws.
*
* Under the commit come its replies, each followed by its own replies when
* they're open, one step in, and "Show more" after the replies of a thread
* with more. Every row is a list row of its own, and the last one closes the
* commit's row with its hairline.
*
* The thread hangs off the rail in dashes, as on the web: the first reply on
* an elbow from the commit's rail, each later one on a short link from the
* line down from the reply above, which is in that reply's lane. A reply's
* own replies hang the same way off the line down from its avatar, which runs
* on past them ($spine) when another reply of the commit follows.
*/
final class ThreadRows
{
/**
* How long a thread's rows take to fade in or out, in milliseconds.
*/
public const int Fade = 220;

/**
* The space above the first reply's avatar, 7pt less than a reply's usual
* 10pt. The commit's row keeps the 7pt of padding under its replies line,
* where its hairline was, so it's as tall with its thread open as shut,
* and a list never moves the commit when the thread opens or closes (see
* partials/commit-row-content).
*/
public const int FirstReplyTop = 3;

/**
* @param array<string, list<Commit>> $threads Open threads, by the id of the commit or reply they answer.
* @param array<string, string> $cursors Where each open thread with more carries on.
* @param array<string, int> $shown How many of each open thread's replies show.
* @param int|string|null $railLane The commit's rail running on past its thread, when its author's run carries on below.
* @return list<array{key: string, partial: string, data: array<string, mixed>, reply: Commit|null}>
*/
public static function under(Commit $commit, array $threads, array $cursors, array $shown, int|string|null $railLane = null): array
{
$thread = fn (string $id): array => array_slice($threads[$id] ?? [], 0, $shown[$id] ?? null);
$hasMore = fn (string $id): bool => isset($cursors[$id]) || count($thread($id)) < count($threads[$id] ?? []);
$replies = $thread($commit->id);

if ($replies === []) {
return [];
}

$rows = [];
$more = $hasMore($commit->id);

foreach ($replies as $index => $reply) {
$nested = $reply->isDeleted() ? [] : $thread($reply->id);
$nestedMore = $nested !== [] && $hasMore($reply->id);
$followed = $index < count($replies) - 1 || $more;

$rows[] = self::reply($reply, [
'lane' => $commit->lane(),
'previousLane' => $index === 0 ? null : $replies[$index - 1]->lane(),
'hasNext' => $followed || $nested !== [],
'railLane' => $railLane,
'thread' => $commit,
'repliesInPlace' => true,
...($index === 0 ? ['top' => self::FirstReplyTop] : []),
]);

foreach ($nested as $nestedIndex => $nestedReply) {
$rows[] = self::reply($nestedReply, [
'lane' => $reply->lane(),
'previousLane' => $nestedIndex === 0 ? null : $nested[$nestedIndex - 1]->lane(),
'hasNext' => $nestedIndex < count($nested) - 1 || $nestedMore,
'railLane' => $railLane,
'indent' => 32,
'spine' => $followed ? $reply->lane() : null,
'thread' => $reply,
'repliesInPlace' => false,
]);
}

if ($nestedMore) {
$rows[] = self::more($reply->id, $nested[array_key_last($nested)]->lane(), $railLane, 32, $followed ? $reply->lane() : null);
}
}

if ($more) {
$rows[] = self::more($commit->id, $replies[array_key_last($replies)]->lane(), $railLane);
}

$last = array_key_last($rows);
$rows[$last]['data']['last'] = true;

return $rows;
}

/**
* @param array<string, mixed> $data
* @return array{key: string, partial: string, data: array<string, mixed>, reply: Commit}
*/
private static function reply(Commit $reply, array $data): array
{
return [
'key' => 'thread-reply-'.$reply->id,
'partial' => 'native.partials.thread-reply',
'data' => ['reply' => $reply, 'indent' => 0, 'spine' => null, 'last' => false, 'fades' => true, ...$data],
'reply' => $reply,
];
}

/**
* "Show more" at the foot of a thread, on a line down in the lane of the reply above it.
*
* @return array{key: string, partial: string, data: array<string, mixed>, reply: null}
*/
private static function more(string $threadId, int|string $lane, int|string|null $railLane, int $indent = 0, int|string|null $spine = null): array
{
return [
'key' => 'thread-more-'.$threadId,
'partial' => 'native.partials.thread-more-row',
'data' => ['threadId' => $threadId, 'lane' => $lane, 'railLane' => $railLane, 'indent' => $indent, 'spine' => $spine, 'last' => false],
'reply' => null,
];
}
}
4 changes: 2 additions & 2 deletions app/NativeComponents/CommitDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
* The commit opens near the top, under the commit it replies to, with the
* ones before that behind "↑ N earlier commits" and its replies behind
* "› N replies", each opened in place. Opened from a "› N replies" button
* ($data['replies']), its replies already show. They come five at a time
* ($data['replies']), its replies already show. They come ten at a time
* (see Client::RepliesPerPage), and "Show more" under the last asks for the
* next five, as it does under a deleted reply's replies opened in place.
* next ten, as it does under a deleted reply's replies opened in place.
*
* It opens on the commit as it was last time, or opened from a row, on what
* the row knew of it, then asks devnull for the rest behind it and fills it in.
Expand Down
Loading
Loading