From 9ff4476e8b0c276917aad8de05785dd431918338 Mon Sep 17 00:00:00 2001 From: Shane Smith Date: Wed, 18 Nov 2026 23:36:59 +1030 Subject: [PATCH] Keep poll labels readable over their bars on Android On Android a poll's results hid each option's label behind its share bar, so "Help and advice" read as "and advice" and an option with a big share showed no label at all. iOS was fine. The bar is an absolute layer written before the label so it sits behind it. iOS draws layers in the order they're written, but NativePHP's Android FlexContainer draws every absolute child after the flow ones, whatever the order (NativePHP/mobile-air#712). The label row is now a partial drawn twice: an invisible copy in the flow that gives the option its height, and the copy you see as an absolute layer after the bar, so it's on top on both platforms. The option's a11y-label still stands in for everything inside it, so screen readers read each option once. A test checks the order and that the two copies draw the same thing, so they can't drift apart. Fixes #174. --- .../native/partials/commit-poll.blade.php | 18 +++++----- .../partials/poll-option-label.blade.php | 15 +++++++++ tests/Feature/Screens/CommitCardTest.php | 33 +++++++++++++++++-- 3 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 resources/views/native/partials/poll-option-label.blade.php diff --git a/resources/views/native/partials/commit-poll.blade.php b/resources/views/native/partials/commit-poll.blade.php index 9df5bc5a..4e8f5242 100644 --- a/resources/views/native/partials/commit-poll.blade.php +++ b/resources/views/native/partials/commit-poll.blade.php @@ -17,9 +17,16 @@ @foreach ($poll->options as $option) @if ($poll->showsResults()) + {{-- + iOS draws an option's layers in the order they're written, but Android draws every absolute layer + after the flow ones (NativePHP/mobile-air#712), so a bar written first would still cover the label + there. The label is an absolute layer after the bar instead, and an invisible copy in the flow gives + the option its height. The option's a11y-label stands in for all three, so the copy is never read. + --}} + @include('native.partials.poll-option-label', ['ref' => 'poll-sizer-'.$option->id, 'class' => 'opacity-0', 'isVisible' => false]) @if ($option->share() > 0) - + {{-- EDGE grows a 0 flex-grow child that would fill the row (FlexContainer.swift effectiveGrow), so at 100% there's no spacer at all. --}} @if ($option->share() < 100) @@ -27,14 +34,7 @@ @endif @endif - - {{ $option->label }} - @if ($option->voted) - - @endif - - {{ $option->share() }}% - + @include('native.partials.poll-option-label', ['ref' => 'poll-label-'.$option->id, 'class' => 'absolute top-0 bottom-0 left-0 right-0', 'isVisible' => true]) @elseif ($canVote) @php($chosen = $choice === $option->id) diff --git a/resources/views/native/partials/poll-option-label.blade.php b/resources/views/native/partials/poll-option-label.blade.php new file mode 100644 index 00000000..8eb9d8c7 --- /dev/null +++ b/resources/views/native/partials/poll-option-label.blade.php @@ -0,0 +1,15 @@ +{{-- + One poll option's label row with results: its label, a check after it when it's your vote, and its percentage in + mono on the right. commit-poll draws it twice, an invisible copy in the flow that gives the option its height and + the copy you see on top of the bar, so $class places it and $ref names it. Only the copy you see names its check. +--}} + + {{ $option->label }} + @if ($option->voted && $isVisible) + + @elseif ($option->voted) + + @endif + + {{ $option->share() }}% + diff --git a/tests/Feature/Screens/CommitCardTest.php b/tests/Feature/Screens/CommitCardTest.php index 067cf306..023d6618 100644 --- a/tests/Feature/Screens/CommitCardTest.php +++ b/tests/Feature/Screens/CommitCardTest.php @@ -62,7 +62,7 @@ function logOf(array $commits): TestableComponent $spaces = nodeByRef($screen, 'poll-option-o2'); $soft = config('native-ui.theme.light.primary-soft'); $wash = config('native-ui.theme.light.wash'); - $fill = fn (array $option): array => $option['children'][0]['children']; + $fill = fn (array $option): array => findNode($option, fn (array $node): bool => ($node['ref'] ?? null) === str_replace('poll-option-', 'poll-bar-', $option['ref']))['children']; expect($tabs['props']['a11y_label'])->toBe('Tabs, your vote, 75%, 3 votes') ->and($spaces['props']['a11y_label'])->toBe('Spaces, 25%, 1 vote') @@ -88,12 +88,41 @@ function logOf(array $commits): TestableComponent ], ])])])->assertSee('100%'); - $bar = nodeByRef($screen, 'poll-option-o1')['children'][0]['children']; + $bar = nodeByRef($screen, 'poll-bar-o1')['children']; expect($bar)->toHaveCount(1) ->and($bar[0]['layout']['flex_grow'] ?? $bar[0]['layout']['flexGrow'] ?? null)->toEqual(100); }); +it("draws each option's label over its bar on Android too, which lays absolute layers over the rest", function () { + $screen = logOf([commitJson(['id' => 'c1', 'body' => 'Tabs or spaces?', 'poll' => votedPollJson()])]); + $option = nodeByRef($screen, 'poll-option-o1'); + $refs = array_column($option['children'], 'ref'); + $layer = fn (string $ref): array => $option['children'][array_search($ref, $refs, true)]; + $isAbsolute = fn (array $node): bool => ($node['layout']['position_type'] ?? $node['layout']['positionType'] ?? 0) === 1; + + // iOS draws layers in the order they're written, but Android draws every absolute one after the flow ones, so the + // label is an absolute layer after the bar on both. An invisible copy in the flow gives the option its height. + expect($refs)->toBe(['poll-sizer-o1', 'poll-bar-o1', 'poll-label-o1']) + ->and($isAbsolute($layer('poll-sizer-o1')))->toBeFalse() + ->and($layer('poll-sizer-o1')['style']['opacity'] ?? null)->toEqual(0) + ->and($isAbsolute($layer('poll-bar-o1')))->toBeTrue() + ->and($isAbsolute($layer('poll-label-o1')))->toBeTrue() + ->and(findNode($layer('poll-label-o1'), fn (array $node): bool => ($node['ref'] ?? null) === 'poll-voted-o1'))->not->toBeNull(); + + // The copy only sizes the option if it draws exactly what the label does, the check included. + $content = function (array $node) use (&$content): array { + return array_map($content, $node['children'] ?? []) + ['type' => $node['type'], 'props' => array_diff_key($node['props'] ?? [], ['ref' => true, 'id' => true]), 'style' => $node['style'] ?? [], 'layout' => $node['layout'] ?? []]; + }; + + foreach (['o1', 'o2'] as $id) { + $option = nodeByRef($screen, "poll-option-{$id}"); + $rows = array_column($option['children'], null, 'ref'); + + expect(array_map($content, $rows["poll-sizer-{$id}"]['children']))->toEqual(array_map($content, $rows["poll-label-{$id}"]['children'])); + } +}); + it('gives every action under a commit a target big enough to tap, without growing the row', function () { $screen = logOf([['id' => 'c1', 'stars_count' => 6, 'replies_count' => 3]]); // A button is its own box. More's box is the column inside it, beside the menu items that ride along as children.