PHPackages                             codingwithrk/double-back-to-close - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. codingwithrk/double-back-to-close

ActiveNativephp-plugin[Utility &amp; Helpers](/categories/utility)

codingwithrk/double-back-to-close
=================================

A NativePHP Mobile plugin that prompts users to press back twice before exiting the app.

v1.0.0(1mo ago)146MITPHPPHP ^8.2

Since Apr 15Pushed 1mo agoCompare

[ Source](https://github.com/codingwithrk/double-back-to-close)[ Packagist](https://packagist.org/packages/codingwithrk/double-back-to-close)[ RSS](/packages/codingwithrk-double-back-to-close/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Double Back to Close — NativePHP Mobile Plugin
==============================================

[](#double-back-to-close--nativephp-mobile-plugin)

[![Latest Version](https://camo.githubusercontent.com/9c1603f34bd618a11df6d403120a668815d2beea792b1493b9c9116302467e50/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f64696e6777697468726b2f646f75626c652d6261636b2d746f2d636c6f73653f7374796c653d706c6173746963)](https://packagist.org/packages/codingwithrk/double-back-to-close)[![Packagist Downloads](https://camo.githubusercontent.com/db6208cc0920ed6722fe8e6350c33ab4e616bb2e9d6dc94e515e507afe514a94/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f64696e6777697468726b2f646f75626c652d6261636b2d746f2d636c6f73653f7374796c653d706c6173746963)](https://camo.githubusercontent.com/db6208cc0920ed6722fe8e6350c33ab4e616bb2e9d6dc94e515e507afe514a94/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f64696e6777697468726b2f646f75626c652d6261636b2d746f2d636c6f73653f7374796c653d706c6173746963)[![License](https://camo.githubusercontent.com/a896509ab11cc2649c31ff30db19995460bcd2ead6c3a264f99be4be0682389a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f636f64696e6777697468726b2f646f75626c652d6261636b2d746f2d636c6f73653f7374796c653d706c6173746963)](https://camo.githubusercontent.com/a896509ab11cc2649c31ff30db19995460bcd2ead6c3a264f99be4be0682389a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f636f64696e6777697468726b2f646f75626c652d6261636b2d746f2d636c6f73653f7374796c653d706c6173746963)

[![Image](https://raw.githubusercontent.com/codingwithrk/nativephp-mobile-plugins/refs/heads/main/assets/screenshots/double-back-to-close.png)](https://raw.githubusercontent.com/codingwithrk/nativephp-mobile-plugins/refs/heads/main/assets/screenshots/double-back-to-close.png)

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.

Uses [`nativephp/mobile-dialog`](https://nativephp.com/plugins/nativephp/mobile-dialog) as a dependency so you can optionally surface the confirmation message as a rich dialog toast from PHP.

---

Requirements
------------

[](#requirements)

PlatformMinimum versionAndroidAPI 26 (Android 8)iOS18.2 (feature is a no-op; iOS has no hardware back button)---

Installation
------------

[](#installation)

```
composer require codingwithrk/double-back-to-close
```

Publish the plugins provider (first time only):

```
php artisan vendor:publish --tag=nativephp-plugins-provider
```

Register this plugin (adds the service provider to your `NativePluginsServiceProvider`):

```
php artisan native:plugin:register codingwithrk/double-back-to-close
```

Register the dependency plugin:

```
php artisan native:plugin:register nativephp/mobile-dialog
```

Verify:

```
php artisan native:plugin:list
```

---

PHP Usage
---------

[](#php-usage)

```
use Codingwithrk\DoubleBackToClose\Facades\DoubleBackToClose;

// Enable with defaults — message: "Press back again to exit", timeout: 2000 ms
DoubleBackToClose::enable();

// Enable with a custom message and timeout
DoubleBackToClose::enable('Tap back again to quit', 3000);

// Update message / timeout while already active
DoubleBackToClose::configure('Press back to exit', 2500);

// Disable (restores default back behaviour)
DoubleBackToClose::disable();

// Show a toast via the mobile-dialog plugin
DoubleBackToClose::showToast('Press back again to exit');
```

### Typical Livewire setup

[](#typical-livewire-setup)

```
use Livewire\Component;
use Codingwithrk\DoubleBackToClose\Facades\DoubleBackToClose;

class AppLayout extends Component
{
    public function mount(): void
    {
        DoubleBackToClose::enable();
    }
}
```

---

Events
------

[](#events)

### `DoubleBackToCloseTriggered`

[](#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 `mobile-dialog` instead.

```
use Native\Mobile\Attributes\OnNative;
use Codingwithrk\DoubleBackToClose\Events\DoubleBackToCloseTriggered;
use Codingwithrk\DoubleBackToClose\Facades\DoubleBackToClose;

#[OnNative(DoubleBackToCloseTriggered::class)]
public function onFirstBackPress(string $message): void
{
    // Override with a dialog toast
    DoubleBackToClose::showToast($message);
}
```

**Payload**

PropertyTypeDescription`message``string`The configured toast message### `AppExiting`

[](#appexiting)

Dispatched on the **second** back press, immediately before `activity.finish()` is called.

```
use Native\Mobile\Attributes\OnNative;
use Codingwithrk\DoubleBackToClose\Events\AppExiting;

#[OnNative(AppExiting::class)]
public function onAppExiting(): void
{
    // Last-moment cleanup
}
```

---

JavaScript Usage
----------------

[](#javascript-usage)

```
import {DoubleBackToClose, Events} from '@codingwithrk/double-back-to-close';
import {on, off} from '@nativephp/native';

// Enable
await DoubleBackToClose.enable({message: 'Press back again to exit', timeout: 2000});

// Update config
await DoubleBackToClose.configure({message: 'Back again to quit', timeout: 3000});

// Disable
await DoubleBackToClose.disable();

// Listen for first back press
const onTriggered = ({message}) => console.log('First press:', message);
on(Events.DoubleBackToCloseTriggered, onTriggered);

// Listen for exit
const onExiting = () => console.log('Goodbye!');
on(Events.AppExiting, onExiting);

// Tear down
off(Events.DoubleBackToCloseTriggered, onTriggered);
off(Events.AppExiting, onExiting);
```

---

How it works
------------

[](#how-it-works)

### Android

[](#android)

`Enable` registers an [`OnBackPressedCallback`](https://developer.android.com/reference/androidx/activity/OnBackPressedCallback) on the activity's `onBackPressedDispatcher`.

- **First press**: shows a native `Toast`, dispatches `DoubleBackToCloseTriggered`, starts a `Handler` timer for the configured timeout.
- **Second press within timeout**: cancels the timer, dispatches `AppExiting`, calls `activity.finish()`.
- **Timeout elapses**: resets `backPressedOnce` to `false`; 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)

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
-------

[](#support)

For questions or issues, email

---

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance89

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

55d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/107883290?v=4)[CodingwithRK](/maintainers/CodingwithRK)[@codingwithrk](https://github.com/codingwithrk)

---

Top Contributors

[![codingwithrk](https://avatars.githubusercontent.com/u/107883290?v=4)](https://github.com/codingwithrk "codingwithrk (2 commits)")

---

Tags

nativephpnativephp-mobilenativephp-plugin

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/codingwithrk-double-back-to-close/health.svg)

```
[![Health](https://phpackages.com/badges/codingwithrk-double-back-to-close/health.svg)](https://phpackages.com/packages/codingwithrk-double-back-to-close)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
