nativephp / mobile-clipboard
System clipboard access (copy/paste text) for NativePHP Mobile
Package info
github.com/NativePHP/mobile-clipboard
Type:nativephp-plugin
pkg:composer/nativephp/mobile-clipboard
Requires
- php: ^8.2
- nativephp/mobile: ^3.0 || ^4.0
Requires (Dev)
- orchestra/testbench: ^10.0
- pestphp/pest: ^2.7|^3.0|^4.0
This package is auto-updated.
Last update: 2026-07-19 02:38:45 UTC
README
System clipboard access (copy/paste plain text) for NativePHP Mobile applications.
Overview
The Clipboard API reads and writes plain text on the system clipboard. Two methods, no permissions, no events.
Installation
composer require nativephp/mobile-clipboard php artisan native:plugin:register nativephp/mobile-clipboard
Usage
use NativePHP\Clipboard\Facades\Clipboard; // Copy text to the clipboard $copied = Clipboard::writeText('Hello from NativePHP!'); // true on success // Read text from the clipboard $text = Clipboard::readText(); // string, or null if the clipboard has no text if ($text !== null) { // Use the pasted text }
Methods
writeText(string $text): bool
Writes plain text to the system clipboard. Returns true once the text is on the clipboard, false on failure.
readText(): ?string
Reads plain text from the system clipboard. Returns null when the clipboard is empty or holds no text.
Both methods degrade gracefully when the native bridge isn't available (running tests, CI): writeText() returns false and readText() returns null — no exception is thrown.
Testing
The plugin extends the NativePHP testing suite with clipboard-specific helpers, so your app tests can fake and assert clipboard activity without knowing any bridge internals:
use Native\Mobile\Testing\Native; it('copies the invite link', function () { Native::fakeBridge()->withClipboard(); Native::test(ShareSheet::class) ->tap('Copy link') ->assertCopied('https://example.com/invite/abc'); }); it('pastes into the form', function () { Native::fakeBridge()->withClipboard('+1 555 0100'); Native::test(SignupScreen::class) ->tap('Paste number') ->assertSet('phone', '+1 555 0100'); });
Helpers
withClipboard(string $text = '')— fake the clipboard's contents. Reads return the current text; writes succeed and update it, so copy-then-paste flows behave like a real clipboard.assertCopied(?string $text = null)— assert something was copied, or exactly$textwhen given.assertNothingCopied()— assert no write happened.
The helpers are available on Native::fakeBridge() and chain directly off Native::test(...). They register automatically while running tests (requires a core with a macroable FakeBridge; on older cores they simply don't register).