Download the PHP package codingwithrk/double-back-to-close without Composer
On this page you can find all versions of the php package codingwithrk/double-back-to-close. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download codingwithrk/double-back-to-close
More information about codingwithrk/double-back-to-close
Files in codingwithrk/double-back-to-close
Package double-back-to-close
Short Description A NativePHP Mobile plugin that prompts users to press back twice before exiting the app.
License MIT
Informations about the package double-back-to-close
Double Back to Close — NativePHP Mobile Plugin

Prompts users to press the back button twice before the app exits.
On the first back press a native toast is shown ("Press back again to exit"). If the user presses back again within the timeout the app exits. If the timeout elapses the state resets and the next back press starts the cycle over.
Supports NativePHP Mobile v3 and v4 (SuperNative). DoubleBackToClose::showToast() uses the Dialog facade to optionally surface the confirmation message as a rich dialog toast from PHP.
Requirements
| Platform | Minimum version |
|---|---|
| Android | API 26 (Android 8) |
| iOS | 18.2 (feature is a no-op; iOS has no hardware back button) |
nativephp/mobile ^3.0 or ^4.0.
Installation
Publish the plugins provider (first time only):
Register this plugin (adds the service provider to your NativePluginsServiceProvider):
showToast() on NativePHP Mobile v3
On v4, Dialog ships inside nativephp/mobile core — no extra steps needed. On v3, Dialog is a separate plugin, so if you want to use DoubleBackToClose::showToast() install and register it too:
This is only required if you call showToast(); enable(), disable(), and configure() work without it.
Verify:
PHP Usage
Typical Livewire setup
Events
DoubleBackToCloseTriggered
Dispatched on the first back press. The native Android Toast has already been shown; listen to this event if you want to show a dialog toast via the Dialog facade instead.
Payload
| Property | Type | Description |
|---|---|---|
message |
string |
The configured toast message |
AppExiting
Dispatched on the second back press, immediately before activity.finish() is called.
JavaScript Usage
How it works
Android
Enable registers an OnBackPressedCallback on the activity's onBackPressedDispatcher.
- First press: shows a native
Toast, dispatchesDoubleBackToCloseTriggered, starts aHandlertimer for the configured timeout. - Second press within timeout: cancels the timer, dispatches
AppExiting, callsactivity.finish(). - Timeout elapses: resets
backPressedOncetofalse; the next press is treated as a first press again.
Disable removes the callback and clears all state.
Configure updates the message/timeout in-place without re-registering the callback.
iOS
iOS does not expose a hardware back button. The bridge functions accept and store configuration, and fire the same PHP events so cross-platform code stays consistent. Pair the feature with DoubleBackToClose::showToast() if you need visual feedback on iOS.
Support
For questions or issues, email [email protected]
License
The MIT License (MIT). Please see License File for more information.