From 35539b340be36321a315e24b0ac1f84d18288d8c Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 12:44:33 +0000 Subject: [PATCH 1/2] Show the handle under the name in the Post as menu Each row of the Post as menu was "Simon (@simon-hamp)", which wrapped onto two lines. Now the name is the row's label and the handle is a subtitle under it, smaller, on iOS and Android. Screen readers read the name and then the handle. It's the same menu in the New commit sheet, the reply bar and the quote composer. Needs NativePHP/mobile-ui#228 (MenuItem::subtitle). With an older mobile-ui the row keeps the combined label, and the subtitle test skips (tests/Support/MenuSubtitle). Co-Authored-By: Claude Opus 5.5 --- app/Devnull/PostAs.php | 21 +++++++++++++-- tests/Feature/Screens/PostAsTest.php | 40 ++++++++++++++++++++++++---- tests/Support/MenuSubtitle.php | 32 ++++++++++++++++++++++ 3 files changed, 86 insertions(+), 7 deletions(-) create mode 100644 tests/Support/MenuSubtitle.php diff --git a/app/Devnull/PostAs.php b/app/Devnull/PostAs.php index d57f5fb7..b2a89ee3 100644 --- a/app/Devnull/PostAs.php +++ b/app/Devnull/PostAs.php @@ -6,6 +6,7 @@ use App\Icons\Lucide; use Native\Mobile\Edge\Elements\TopBarAction; use Native\Mobile\Edge\Layouts\Builders\NavAction; +use Native\Mobile\UI\MenuItem; /** * Who a composer posts as, as the web's Post as menu chooses: you, or one of @@ -60,6 +61,9 @@ public static function offered(?string $picked): bool * an organization, as elsewhere in the app, and the one posting now ticked. Until an avatar loads, or if it * can't, a person or building icon stands in. $method is called with the handle picked, or '' for you. * + * Each row is the name with the handle under it, smaller, which screen readers read after the name. A mobile-ui + * without menu subtitles (before NativePHP/mobile-ui#228) gets one label, "Simon (@simon-hamp)", instead. + * * @return list */ public static function menu(User $me, ?User $author, string $method): array @@ -67,8 +71,11 @@ public static function menu(User $me, ?User $author, string $method): array return array_map(function (User $identity) use ($author, $method): TopBarAction { $icon = $identity->isOrganization ? Lucide::Building2 : Lucide::UserRound; - return NavAction::make('post-as-'.$identity->username) - ->label($identity->name.' (@'.$identity->username.')') + $handle = '@'.$identity->username; + $subtitled = self::subtitles(); + + $row = NavAction::make('post-as-'.$identity->username) + ->label($subtitled ? $identity->name : $identity->name.' ('.$handle.')') ->icon(ios: $icon->ios(), android: $icon->android()) ->image(ImageCache::src($identity->avatarUrl)) ->press($method."('".($identity->isOrganization ? $identity->username : '')."')") @@ -76,9 +83,19 @@ public static function menu(User $me, ?User $author, string $method): array ->setProp('image_shape', $identity->isOrganization ? 'rounded' : 'circle') ->setProp('checked', self::posting($identity, $author)) ->ref('post-as-'.$identity->username); + + return $subtitled ? MenuItem::subtitle($row, $handle) : $row; }, [$me, ...self::organizations()]); } + /** + * Whether the installed mobile-ui draws a subtitle under a menu row's label. + */ + private static function subtitles(): bool + { + return class_exists(MenuItem::class); + } + /** * What the composer's avatar says to a screen reader. */ diff --git a/tests/Feature/Screens/PostAsTest.php b/tests/Feature/Screens/PostAsTest.php index 21550679..3933b5eb 100644 --- a/tests/Feature/Screens/PostAsTest.php +++ b/tests/Feature/Screens/PostAsTest.php @@ -10,6 +10,7 @@ use Illuminate\Support\Facades\Http; use Native\Mobile\Testing\Native; use Native\Mobile\Testing\TestableComponent; +use Tests\Support\MenuSubtitle; beforeEach(function () { config(['devnull.url' => 'http://devnull.test']); @@ -68,6 +69,18 @@ function composeOnLogAs(?array $answer = null, array $extra = []): TestableCompo return Native::visit('/log', platform: 'ios')->press('composeInSheet'); } +/** + * The Post as menu a pressable opens, as each row's ref, label and subtitle. + * + * @return list + */ +function postAsRows(TestableComponent $screen, string $ref): array +{ + $rows = array_filter(nodeByRef($screen, $ref)['children'] ?? [], fn (array $child): bool => ($child['type'] ?? null) === 'top_bar_action'); + + return array_values(array_map(fn (array $row): array => [$row['ref'] ?? null, $row['props']['label'] ?? null, $row['props']['subtitle'] ?? null], $rows)); +} + /** * The JSON of the commits sent to devnull. * @@ -157,11 +170,7 @@ function commitsSent(): array expect(nodeByRef($screen, 'sheet-post-as-name')['props']['text'])->toBe('Local Dev') ->and(nodeByRef($screen, 'sheet-post-as-handle')['props']['text'])->toBe('@local_dev') ->and(nodeByRef($screen, 'sheet-post-as')['props']['a11y_label'])->toBe('Posting as @local_dev. Choose who to post as') - ->and(array_map(fn (array $item): array => [$item[0], $item[1]], menuItems($screen, 'sheet-post-as')))->toBe([ - ['post-as-local_dev', 'Local Dev (@local_dev)'], - ['post-as-dev-null-sh', '/dev/null (@dev-null-sh)'], - ['post-as-nativephp', 'NativePHP (@nativephp)'], - ]); + ->and(array_column(menuItems($screen, 'sheet-post-as'), 0))->toBe(['post-as-local_dev', 'post-as-dev-null-sh', 'post-as-nativephp']); $screen->call('postAsInSheet', 'nativephp'); @@ -178,6 +187,27 @@ function commitsSent(): array expect(sheetButtonCircle($screen, 'sheet-commit')['style']['bg_color'])->not->toBe($organizationFill); }); +it('names each account in the Post as menu, with its handle under the name', function () { + MenuSubtitle::skipUnlessSupported(); + memberOf([memberOrganizationJson(), memberOrganizationJson(['id' => 'o2', 'handle' => 'nativephp', 'name' => 'NativePHP', 'role' => 'member'])]); + + expect(postAsRows(composeOnLogAs(), 'sheet-post-as'))->toBe([ + ['post-as-local_dev', 'Local Dev', '@local_dev'], + ['post-as-dev-null-sh', '/dev/null', '@dev-null-sh'], + ['post-as-nativephp', 'NativePHP', '@nativephp'], + ]); +}); + +it('puts the handle in the label when mobile-ui has no menu subtitles', function () { + MenuSubtitle::skipIfSupported(); + memberOf([memberOrganizationJson()]); + + expect(postAsRows(composeOnLogAs(), 'sheet-post-as'))->toBe([ + ['post-as-local_dev', 'Local Dev (@local_dev)', null], + ['post-as-dev-null-sh', '/dev/null (@dev-null-sh)', null], + ]); +}); + it('commits as the organization picked, and shows it staged as the organization', function () { memberOf([memberOrganizationJson()]); holdRefreshes(); diff --git a/tests/Support/MenuSubtitle.php b/tests/Support/MenuSubtitle.php new file mode 100644 index 00000000..78e96866 --- /dev/null +++ b/tests/Support/MenuSubtitle.php @@ -0,0 +1,32 @@ +markTestSkipped('Needs a mobile-ui that draws menu row subtitles (NativePHP/mobile-ui#228)'); + } + } + + public static function skipIfSupported(): void + { + if (self::supported()) { + test()->markTestSkipped('The installed mobile-ui draws menu row subtitles, so the menu never falls back to one label'); + } + } +} From 1d72a7703e8633b222deb2ba7735fad793352950 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 13:23:56 +0000 Subject: [PATCH 2/2] Set the Post as handle with core's NavAction::subtitle() Core now has NavAction::subtitle() (NativePHP/mobile-air#740), and mobile-ui#228 dropped its MenuItem::subtitle() stop-gap. PostAs::menu() calls ->subtitle('@handle') on the row, and falls back to the combined "Name (@handle)" label when the installed core has no subtitle(). The tests skip on the same check (tests/Support/MenuSubtitle). Co-Authored-By: Claude Opus 5.5 --- app/Devnull/PostAs.php | 20 +++++++++++--------- tests/Feature/Screens/PostAsTest.php | 2 +- tests/Support/MenuSubtitle.php | 14 +++++++------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/app/Devnull/PostAs.php b/app/Devnull/PostAs.php index b2a89ee3..26711721 100644 --- a/app/Devnull/PostAs.php +++ b/app/Devnull/PostAs.php @@ -6,7 +6,6 @@ use App\Icons\Lucide; use Native\Mobile\Edge\Elements\TopBarAction; use Native\Mobile\Edge\Layouts\Builders\NavAction; -use Native\Mobile\UI\MenuItem; /** * Who a composer posts as, as the web's Post as menu chooses: you, or one of @@ -61,8 +60,8 @@ public static function offered(?string $picked): bool * an organization, as elsewhere in the app, and the one posting now ticked. Until an avatar loads, or if it * can't, a person or building icon stands in. $method is called with the handle picked, or '' for you. * - * Each row is the name with the handle under it, smaller, which screen readers read after the name. A mobile-ui - * without menu subtitles (before NativePHP/mobile-ui#228) gets one label, "Simon (@simon-hamp)", instead. + * Each row is the name with the handle under it, smaller, which screen readers read after the name. A core + * without NavAction::subtitle() (before NativePHP/mobile-air#740) gets one label, "Simon (@simon-hamp)", instead. * * @return list */ @@ -78,22 +77,25 @@ public static function menu(User $me, ?User $author, string $method): array ->label($subtitled ? $identity->name : $identity->name.' ('.$handle.')') ->icon(ios: $icon->ios(), android: $icon->android()) ->image(ImageCache::src($identity->avatarUrl)) - ->press($method."('".($identity->isOrganization ? $identity->username : '')."')") - ->toElement() + ->press($method."('".($identity->isOrganization ? $identity->username : '')."')"); + + if ($subtitled) { + $row->subtitle($handle); + } + + return $row->toElement() ->setProp('image_shape', $identity->isOrganization ? 'rounded' : 'circle') ->setProp('checked', self::posting($identity, $author)) ->ref('post-as-'.$identity->username); - - return $subtitled ? MenuItem::subtitle($row, $handle) : $row; }, [$me, ...self::organizations()]); } /** - * Whether the installed mobile-ui draws a subtitle under a menu row's label. + * Whether the installed core can give a menu row a subtitle under its label. */ private static function subtitles(): bool { - return class_exists(MenuItem::class); + return method_exists(NavAction::class, 'subtitle'); } /** diff --git a/tests/Feature/Screens/PostAsTest.php b/tests/Feature/Screens/PostAsTest.php index 3933b5eb..700b2202 100644 --- a/tests/Feature/Screens/PostAsTest.php +++ b/tests/Feature/Screens/PostAsTest.php @@ -198,7 +198,7 @@ function commitsSent(): array ]); }); -it('puts the handle in the label when mobile-ui has no menu subtitles', function () { +it('puts the handle in the label when core has no menu row subtitles', function () { MenuSubtitle::skipIfSupported(); memberOf([memberOrganizationJson()]); diff --git a/tests/Support/MenuSubtitle.php b/tests/Support/MenuSubtitle.php index 78e96866..4ad7d904 100644 --- a/tests/Support/MenuSubtitle.php +++ b/tests/Support/MenuSubtitle.php @@ -2,31 +2,31 @@ namespace Tests\Support; -use Native\Mobile\UI\MenuItem; +use Native\Mobile\Edge\Layouts\Builders\NavAction; /** - * Whether the installed mobile-ui draws a subtitle under a menu row's label (`MenuItem::subtitle()`, from - * NativePHP/mobile-ui#228). Without it the Post as menu puts the handle in the label, "Simon (@simon-hamp)", - * so the tests of the subtitle skip. + * Whether the installed core can give a menu row a subtitle (`NavAction::subtitle()`, from NativePHP/mobile-air#740; + * mobile-ui draws it since NativePHP/mobile-ui#228). Without it the Post as menu puts the handle in the label, + * "Simon (@simon-hamp)", so the tests of the subtitle skip. */ final class MenuSubtitle { public static function supported(): bool { - return class_exists(MenuItem::class); + return method_exists(NavAction::class, 'subtitle'); } public static function skipUnlessSupported(): void { if (! self::supported()) { - test()->markTestSkipped('Needs a mobile-ui that draws menu row subtitles (NativePHP/mobile-ui#228)'); + test()->markTestSkipped('Needs a core with NavAction::subtitle() (NativePHP/mobile-air#740)'); } } public static function skipIfSupported(): void { if (self::supported()) { - test()->markTestSkipped('The installed mobile-ui draws menu row subtitles, so the menu never falls back to one label'); + test()->markTestSkipped('The installed core has NavAction::subtitle(), so the menu never falls back to one label'); } } }