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
18 changes: 9 additions & 9 deletions resources/views/native/partials/commit-poll.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@
<native:column ref="poll-{{ $commit->id }}" class="w-full mt-3 gap-2" a11y-label="{{ $poll->showsResults() ? 'Poll results' : 'Poll options' }}">
@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.
--}}
<native:column ref="poll-option-{{ $option->id }}" class="w-full rounded-md border border-theme-hairline" a11y-label="{{ $option->label }}{{ $option->voted ? ', your vote' : '' }}, {{ $option->share() }}%, {{ $option->votesLabel() }}">
@include('native.partials.poll-option-label', ['ref' => 'poll-sizer-'.$option->id, 'class' => 'opacity-0', 'isVisible' => false])
@if ($option->share() > 0)
<native:row class="absolute top-0 bottom-0 left-0 right-0">
<native:row ref="poll-bar-{{ $option->id }}" class="absolute top-0 bottom-0 left-0 right-0">
<native:column :flexGrow="$option->share()" :flexBasis="0" class="h-full rounded-md {{ $option->voted ? 'bg-theme-primary-soft' : 'bg-theme-wash' }}" />
{{-- 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)
<native:column :flexGrow="100 - $option->share()" :flexBasis="0" />
@endif
</native:row>
@endif
<native:row class="w-full px-3 py-2 gap-[6] items-center">
<native:text :font="$option->voted ? 'medium' : null" class="flex-shrink text-[15px] text-theme-ink">{{ $option->label }}</native:text>
@if ($option->voted)
<native:icon ref="poll-voted-{{ $option->id }}" :ios="\App\Icons\Lucide::Check->ios()" :android="\App\Icons\Lucide::Check->android()" :size="16" class="text-theme-primary" />
@endif
<native:spacer />
<native:text font="mono" class="text-[13px] text-theme-ink">{{ $option->share() }}%</native:text>
</native:row>
@include('native.partials.poll-option-label', ['ref' => 'poll-label-'.$option->id, 'class' => 'absolute top-0 bottom-0 left-0 right-0', 'isVisible' => true])
</native:column>
@elseif ($canVote)
@php($chosen = $choice === $option->id)
Expand Down
15 changes: 15 additions & 0 deletions resources/views/native/partials/poll-option-label.blade.php
Original file line number Diff line number Diff line change
@@ -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.
--}}
<native:row ref="{{ $ref }}" class="w-full px-3 py-2 gap-[6] items-center {{ $class }}">
<native:text :font="$option->voted ? 'medium' : null" class="flex-shrink text-[15px] text-theme-ink">{{ $option->label }}</native:text>
@if ($option->voted && $isVisible)
<native:icon ref="poll-voted-{{ $option->id }}" :ios="\App\Icons\Lucide::Check->ios()" :android="\App\Icons\Lucide::Check->android()" :size="16" class="text-theme-primary" />
@elseif ($option->voted)
<native:icon :ios="\App\Icons\Lucide::Check->ios()" :android="\App\Icons\Lucide::Check->android()" :size="16" class="text-theme-primary" />
@endif
<native:spacer />
<native:text font="mono" class="text-[13px] text-theme-ink">{{ $option->share() }}%</native:text>
</native:row>
33 changes: 31 additions & 2 deletions tests/Feature/Screens/CommitCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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.
Expand Down
Loading