Native Share Plugin for NativePHP Mobile#
Copy text to the clipboard, or open the OS share sheet with a title and a line of text.
Brand assets for local packaging live in docs/brand and art (private repo paths are not embedded as README images so the marketplace listing does not show broken image placeholders).
Overview#
Two bridge functions, both plain text:
NativeShare.Copywrites a string to the system clipboard.NativeShare.Shareopens the AndroidACTION_SENDchooser or the iOSUIActivityViewController.
The official nativephp/mobile-share plugin (free) shares URLs and files. It doesn't copy to the clipboard. This plugin adds clipboard copy, plus a share($title, $text) that takes no URL or file: an invite link the user copies with one tap, or a "share this listing" message. If you only share URLs or files, use the official plugin.
The share sheet is the OS app picker. Whatever app the user picks (Messages, WhatsApp, Mail) brings its own recipient picker, so there's no in-app contact picker here.
Installation#
The repository is private. Add it to your app's composer.json as a VCS repository:
"repositories": [ { "type": "vcs", "url": "https://github.com/prosenthal828/nativephp-native-share" }]
Use the VCS URL rather than a local path repository so Bifrost and CI builds can resolve the package. Those machines need GitHub read access to the repo (for example through COMPOSER_AUTH).
Then:
composer require partek/native-sharephp artisan native:plugin:register partek/native-share
native:plugin:register adds the service provider to NativeServiceProvider::plugins(), which native:run reads at build time. Rebuild the native projects afterwards (php artisan native:run android or ios). There are no permissions to add.
Usage#
PHP (Super Native / Livewire / Blade)#
The facade is for Super Native first; the same call works from Livewire and Blade.
Call it from a press handler in a NativeComponent or Livewire component:
use Partek\NativeShare\Facades\NativeShare; NativeShare::copy('https://farmseconds.com/invite/abc'); NativeShare::share('Invite', 'Join me on FarmSeconds: https://farmseconds.com/invite/abc');
Both methods return void.
JavaScript#
The plugin ships its JavaScript at resources/js/index.js. NativePHP doesn't alias plugin JavaScript for you, so add an alias in vite.config.js:
import { fileURLToPath } from 'node:url'; export default defineConfig({ resolve: { alias: { 'partek-native-share': fileURLToPath( new URL('./vendor/partek/native-share/resources/js/index.js', import.meta.url) ), }, }, // ...});
import { copy, share } from 'partek-native-share'; await copy('https://farmseconds.com/invite/abc');await share('Invite', 'Join me on FarmSeconds: https://farmseconds.com/invite/abc');
Both reject with an Error if the bridge returns one, such as a missing text. Without the alias, core's bridgeCall from #nativephp works too: bridgeCall('NativeShare.Copy', { text }) and bridgeCall('NativeShare.Share', { title, text }).
Events#
None. copy() writes to the clipboard immediately. share() returns once the sheet is open, and the plugin doesn't report which app the user picked or whether they sent anything.
Methods#
copy(string $text): void#
Writes $text to the system clipboard, replacing whatever was there.
| Parameter | Type | Description |
|---|---|---|
text |
string | Plain text to copy |
share(string $title, string $text): void#
Opens the share sheet with $text as the content.
| Parameter | Type | Description |
|---|---|---|
title |
string | Sheet header and email subject. It isn't added to the message body. Pass '' for the system's default header. |
text |
string | The text to share |
There's no file or URL argument. For those, use nativephp/mobile-share.
Platform behavior#
Android#
- Copy:
ClipboardManager. Android 13 and later show their own "Copied" confirmation. - Share:
Intent.ACTION_SEND(text/plain) throughIntent.createChooser. The title goes intoEXTRA_TITLE(the sheet header on Android 10+),EXTRA_SUBJECT, and the chooser title on older versions. - Min SDK 21
- Text only, so no
FileProvider
iOS#
- Copy:
UIPasteboard.general - Share:
UIActivityViewController, presented from the topmost view controller so an open modal doesn't block it. On iPad it's anchored to the center of the screen. - The title becomes the sheet header (
LPLinkMetadata) and the Mail subject. - Min iOS 15.0
Testing#
Run the plugin's own suite:
vendor/bin/phpunit
In your app's tests, the plugin adds assertCopied() and assertShared() to NativePHP's fake bridge (nativephp/mobile v4):
use Native\Mobile\Testing\Native; Native::test(InviteScreen::class) ->tap('Copy invite link') ->assertCopied('https://farmseconds.com/invite/abc'); Native::test(InviteScreen::class) ->tap('Share invite') ->assertShared('Invite', 'Join me on FarmSeconds: https://farmseconds.com/invite/abc');
Every argument is optional. Any you pass must match the call.
Notes#
- No permissions on either platform.
- Register the plugin and rebuild, or the bridge functions never get compiled in.
- Doesn't replace
nativephp/mobile-sharefor URLs and files.
License#
Proprietary commercial software. See LICENSE.