Swipe Actions for NativePHP Mobile#
Swipe a row to reveal actions, for NativePHP Mobile native (EDGE) screens.
<native:swipe-row> wraps any content, such as a list item, a card or a custom
row. Sliding it left or right reveals the actions you declare inside it as
<native:swipe-action> tags. Each action is drawn as you style it: by default,
an icon in the action's colour on whatever is behind the row, with no filled
box and no caption.
<native:swipe-row> <native:list-item headline="Order #1042" supporting="2 items" @tap="open(1042)" /> <native:swipe-action icon="archive" label="Archive" color="theme-primary" @tap="archive(1042)" /> <native:swipe-action icon="delete" label="Delete" destructive @tap="delete(1042)" /></native:swipe-row>
Requirements#
nativephp/mobile4.6 or later, using native (EDGE) screensnativephp/mobile-ui0.8 or later. The iOS renderer uses its column renderer, andtheme-*colours read its theme.- Android 8.0 (API 26) or later; iOS 15 or later
Installation#
composer require atlasnatives/nativephp-swipe-actionsphp artisan native:plugin:register atlasnatives/nativephp-swipe-actions
The second command adds AtlasNatives\SwipeActions\SwipeActionsServiceProvider
to your app/Providers/NativeServiceProvider.php. You can also add it to
plugins() yourself. Rebuild the app afterwards so the native renderer is
compiled in.
Usage#
Everything inside a <native:swipe-row> is the row's content, except its
<native:swipe-action> children, which are its actions. Actions appear in the
order written, with the first one nearest the row.
<native:swipe-row> <native:pressable @tap="openTask({{ $task->id }})" class="w-full rounded-2xl bg-white p-4"> <native:text class="text-base font-semibold">{{ $task->title }}</native:text> </native:pressable> @if ($task->done) <native:swipe-action icon="undo" label="Reopen" color="theme-primary" @tap="reopen({{ $task->id }})" /> @else <native:swipe-action icon="check" label="Done" color="theme-primary" @tap="complete({{ $task->id }})" /> @endif <native:swipe-action icon="delete" label="Delete" color="theme-destructive" destructive @tap="confirmDelete({{ $task->id }})" /> <native:swipe-action side="leading" icon="push_pin" label="Pin" color="amber-600" @tap="pin({{ $task->id }})" /></native:swipe-row>
Actions are ordinary tags, so you can wrap them in @if and @foreach like any
other tag. The row works on its own, inside a <native:column>, or as a row of
a <native:list>.
<native:swipe-row>#
| Attribute | Default | |
|---|---|---|
icon-size |
28 |
Icon size in dp |
action-width |
64 |
Width of each action in dp |
show-labels |
false |
Draw each action's label under its icon |
Style the row itself with the usual classes (class="w-full", padding and so on).
<native:swipe-action>#
| Attribute | |
|---|---|
@tap |
The component method to call. Required. |
icon |
A Material icon name. Use ios="…" / android="…" to override it per platform. |
label |
Read by screen readers. It is drawn under the icon only when the row has show-labels. |
color |
Icon and label colour. Accepts hex (#4F7D1F, #4F7D1F80), Tailwind palette names (red-600, red-600/20) or theme tokens (theme-primary); a theme token also follows dark mode. |
background |
An optional fill behind the action, using the same colours. By default there is none. |
destructive |
Marks the action as destructive. It turns red when no color is given. |
side |
trailing (default) shows the action on a left swipe; leading shows it on a right swipe. |
A <native:swipe-action> must be a direct child of a <native:swipe-row>;
anywhere else, it throws a LogicException.
Building rows in PHP#
use AtlasNatives\SwipeActions\Elements\SwipeAction;use AtlasNatives\SwipeActions\Elements\SwipeRow; SwipeRow::make( $content, SwipeAction::make('archive(1042)')->icon('archive')->label('Archive')->color('theme-primary'), SwipeAction::make('delete(1042)')->icon('delete')->label('Delete')->destructive(),)->iconSize(30);
Behaviour#
- A row snaps open once dragged past half its actions' width; otherwise it snaps shut.
- Only one row is open at a time. Opening a row closes any other.
- Tapping the open row, or one of its actions, closes it. While a row is open,
a tap on it doesn't reach the content's own
@tap. - The actions fade in as the row slides, so they never show through a row's rounded corners or gaps while it is shut.
- Screen-reader users reach the actions through the row's accessibility actions: TalkBack's actions menu, or VoiceOver's actions rotor.
Platform status#
- Android: tested on API 37.
- iOS: a SwiftUI renderer ships with the plugin but has not been tested on a device yet.
Testing#
vendor/bin/pest
Licence#
Proprietary: one licence per developer, for use in any number of apps. See LICENSE.md.