PHP code example of codingwithrk / double-back-to-close

1. Go to this page and download the library: Download codingwithrk/double-back-to-close library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

codingwithrk / double-back-to-close example snippets


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 Dialog facade (built in on v4; 

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

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

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);
}

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

#[OnNative(AppExiting::class)]
public function onAppExiting(): void
{
    // Last-moment cleanup
}
bash
php artisan vendor:publish --tag=nativephp-plugins-provider
bash
php artisan native:plugin:list