Skip to content

Commit 632a796

Browse files
committed
OnNative
1 parent 247845a commit 632a796

File tree

13 files changed

+78
-97
lines changed

13 files changed

+78
-97
lines changed

resources/views/docs/mobile/2/apis/biometrics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Fired when biometric authentication completes (success or failure).
3434
use Livewire\Attributes\On;
3535
use Native\Mobile\Events\Biometric\Completed;
3636

37-
#[On('native:'.Completed::class)]
37+
#[OnNative(Completed::class)]
3838
public function handle(Completed $event)
3939
{
4040
if ($event->success) {

resources/views/docs/mobile/2/apis/camera.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Fired when a photo is taken with the camera.
143143
use Livewire\Attributes\On;
144144
use Native\Mobile\Events\Camera\PhotoTaken;
145145

146-
#[On('native:'.PhotoTaken::class)]
146+
#[OnNative(PhotoTaken::class)]
147147
public function handlePhotoTaken(string $path)
148148
{
149149
// Process the captured photo
@@ -164,7 +164,7 @@ Fired when a video is successfully recorded.
164164
use Livewire\Attributes\On;
165165
use Native\Mobile\Events\Camera\VideoRecorded;
166166

167-
#[On('native:'.VideoRecorded::class)]
167+
#[OnNative(VideoRecorded::class)]
168168
public function handleVideoRecorded(string $path, string $mimeType, ?string $id = null)
169169
{
170170
// Process the recorded video
@@ -189,7 +189,7 @@ Fired when video recording is cancelled by the user.
189189
use Livewire\Attributes\On;
190190
use Native\Mobile\Events\Camera\VideoCancelled;
191191

192-
#[On('native:'.VideoCancelled::class)]
192+
#[OnNative(VideoCancelled::class)]
193193
public function handleVideoCancelled(bool $cancelled, ?string $id = null)
194194
{
195195
// Handle cancellation
@@ -207,7 +207,7 @@ Fired when media is selected from the gallery.
207207
use Livewire\Attributes\On;
208208
use Native\Mobile\Events\Gallery\MediaSelected;
209209

210-
#[On('native:'.MediaSelected::class)]
210+
#[OnNative(MediaSelected::class)]
211211
public function handleMediaSelected($success, $files, $count)
212212
{
213213
foreach ($files as $file) {

resources/views/docs/mobile/2/apis/dialog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Fired when a button is pressed in an alert dialog.
8585
use Livewire\Attributes\On;
8686
use Native\Mobile\Events\Alert\ButtonPressed;
8787

88-
#[On('native:'.ButtonPressed::class)]
88+
#[OnNative(ButtonPressed::class)]
8989
public function handleAlertButton($index, $label)
9090
{
9191
switch ($index) {

resources/views/docs/mobile/2/apis/file.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ use Livewire\Attributes\On;
7272
use Native\Mobile\Events\Camera\PhotoTaken;
7373
use Native\Mobile\Facades\File;
7474

75-
#[On('native:'.PhotoTaken::class)]
75+
#[OnNative(PhotoTaken::class)]
7676
public function handlePhotoTaken(string $path)
7777
{
7878
$destination = storage_path('app/photos/'.basename($path));
@@ -122,4 +122,4 @@ File::move($source, $destination);
122122
- If the destination file already exists, the operation fails and returns `false`
123123
- These operations are synchronous and block execution until completion
124124
- Ensure your app has the necessary file system permissions to read from the source and write to the destination
125-
- No events are dispatched by these operations; they return results directly
125+
- No events are dispatched by these operations; they return results directly

resources/views/docs/mobile/2/apis/geolocation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Fired when location data is requested (success or failure).
6969
use Livewire\Attributes\On;
7070
use Native\Mobile\Events\Geolocation\LocationReceived;
7171

72-
#[On('native:'.LocationReceived::class)]
72+
#[OnNative(LocationReceived::class)]
7373
public function handleLocationReceived(
7474
$success = null,
7575
$latitude = null,
@@ -101,7 +101,7 @@ Fired when permission status is checked.
101101
use Livewire\Attributes\On;
102102
use Native\Mobile\Events\Geolocation\PermissionStatusReceived;
103103

104-
#[On('native:'.PermissionStatusReceived::class)]
104+
#[OnNative(PermissionStatusReceived::class)]
105105
public function handlePermissionStatus($location, $coarseLocation, $fineLocation)
106106
{
107107
// ...

resources/views/docs/mobile/2/apis/audio.md renamed to resources/views/docs/mobile/2/apis/microphone.md

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,50 @@
11
---
2-
title: Audio
2+
title: Microphone
33
order: 50
44
---
55

66
## Overview
77

8-
The Audio API provides access to the device's microphone for recording audio. It offers a fluent interface for starting and managing recordings, tracking them with unique identifiers, and responding to completion events.
8+
The Microphone API provides access to the device's microphone for recording audio. It offers a fluent interface for
9+
starting and managing recordings, tracking them with unique identifiers, and responding to completion events.
910

1011
```php
11-
use Native\Mobile\Facades\Audio;
12+
use Native\Mobile\Facades\Microphone;
1213
```
1314

1415
## Methods
1516

1617
### `record()`
1718

18-
Start an audio recording. Returns a `PendingAudioRecorder` instance that controls the recording lifecycle.
19+
Start an audio recording. Returns a `PendingMicrophone` instance that controls the recording lifecycle.
1920

2021
```php
21-
Audio::record()->start();
22+
Microphone::record()->start();
2223
```
2324

2425
### `stop()`
2526

26-
Stop the current audio recording. This dispatches the `AudioRecorded` event with the recording file path.
27+
Stop the current audio recording. If this results in a saved file, this dispatches the `AudioRecorded` event with the
28+
recording file path.
2729

2830
```php
29-
Audio::stop();
31+
Microphone::stop();
3032
```
3133

3234
### `pause()`
3335

3436
Pause the current audio recording without ending it.
3537

3638
```php
37-
Audio::pause();
39+
Microphone::pause();
3840
```
3941

4042
### `resume()`
4143

4244
Resume a paused audio recording.
4345

4446
```php
45-
Audio::resume();
47+
Microphone::resume();
4648
```
4749

4850
### `getStatus()`
@@ -52,7 +54,7 @@ Get the current recording status.
5254
**Returns:** `string` - One of: `"idle"`, `"recording"`, or `"paused"`
5355

5456
```php
55-
$status = Audio::getStatus();
57+
$status = Microphone::getStatus();
5658

5759
if ($status === 'recording') {
5860
// A recording is in progress
@@ -66,25 +68,27 @@ Get the file path to the last recorded audio file.
6668
**Returns:** `string|null` - Path to the last recording, or `null` if none exists
6769

6870
```php
69-
$path = Audio::getRecording();
71+
$path = Microphone::getRecording();
7072

7173
if ($path) {
7274
// Process the recording file
7375
}
7476
```
7577

76-
## PendingAudioRecorder
78+
## PendingMicrophone
7779

78-
The `PendingAudioRecorder` provides a fluent interface for configuring and starting audio recordings. Most methods return `$this` for method chaining.
80+
The `PendingMicrophone` provides a fluent interface for configuring and starting audio recordings. Most methods return
81+
`$this` for method chaining.
7982

8083
### `id(string $id)`
8184

82-
Set a unique identifier for this recording. This ID will be included in the `AudioRecorded` event, allowing you to correlate recordings with completion events.
85+
Set a unique identifier for this recording. This ID will be included in the `AudioRecorded` event, allowing you to
86+
correlate recordings with completion events.
8387

8488
```php
8589
$recorderId = 'message-recording-' . $this->id;
8690

87-
Audio::record()
91+
Microphone::record()
8892
->id($recorderId)
8993
->start();
9094
```
@@ -94,7 +98,7 @@ Audio::record()
9498
Get the recorder's unique identifier. If no ID was set, one is automatically generated (UUID v4).
9599

96100
```php
97-
$recorder = Audio::record()
101+
$recorder = Microphone::record()
98102
->id('my-recording');
99103

100104
$id = $recorder->getId(); // 'my-recording'
@@ -109,7 +113,7 @@ Set a custom event class to dispatch when recording completes. By default, `Audi
109113
```php
110114
use App\Events\VoiceMessageRecorded;
111115

112-
Audio::record()
116+
Microphone::record()
113117
->event(VoiceMessageRecorded::class)
114118
->start();
115119
```
@@ -119,7 +123,7 @@ Audio::record()
119123
Store the recorder's ID in the session for later retrieval. This is useful when the recording completes on the next request.
120124

121125
```php
122-
Audio::record()
126+
Microphone::record()
123127
->id('voice-note')
124128
->remember()
125129
->start();
@@ -130,10 +134,10 @@ Audio::record()
130134
Retrieve the last remembered audio recorder ID from the session. Use this in event listeners to correlate recordings.
131135

132136
```php
133-
use Livewire\Attributes\On;
134-
use Native\Mobile\Events\Audio\AudioRecorded;
137+
use Native\Mobile\Attributes\OnNative;
138+
use Native\Mobile\Events\Microphone\MicrophoneRecorded;
135139

136-
#[On('native:'.AudioRecorded::class)]
140+
#[OnNative(MicrophoneRecorded::class)]
137141
public function handleAudioRecorded(string $path, string $mimeType, ?string $id)
138142
{
139143
// For comparing with remembered IDs
@@ -150,7 +154,7 @@ Explicitly start the audio recording. This is optional - recordings auto-start i
150154
**Returns:** `bool` - `true` if recording started successfully, `false` if it failed or was already started
151155

152156
```php
153-
$recorder = Audio::record()->id('my-recording');
157+
$recorder = Microphone::record()->id('my-recording');
154158

155159
if ($recorder->start()) {
156160
// Recording started
@@ -161,7 +165,7 @@ if ($recorder->start()) {
161165

162166
## Events
163167

164-
### `AudioRecorded`
168+
### `MicrophoneRecorded`
165169

166170
Dispatched when an audio recording completes. The event includes the file path and recording ID.
167171

@@ -171,10 +175,7 @@ Dispatched when an audio recording completes. The event includes the file path a
171175
- `?string $id` - The recorder's ID, if one was set
172176

173177
```php
174-
use Livewire\Attributes\On;
175-
use Native\Mobile\Events\Audio\AudioRecorded;
176-
177-
#[On('native:'.AudioRecorded::class)]
178+
#[OnNative(MicrophoneRecorded::class)]
178179
public function handleAudioRecorded(string $path, string $mimeType, ?string $id)
179180
{
180181
// Store or process the recording
@@ -192,10 +193,6 @@ public function handleAudioRecorded(string $path, string $mimeType, ?string $id)
192193

193194
- **File Format:** Recordings are stored as M4A/AAC audio files (`.m4a`). This format is optimized for small file sizes while maintaining quality.
194195

195-
- **Storage Location:**
196-
- **Android:** Recordings are stored in the app's cache directory (`context.cacheDir/audio_{timestamp}.m4a`). These are temporary files and may be deleted by the system.
197-
- **iOS:** Recordings are stored persistently in `~/Library/Application Support/Audio/NativePHP_{timestamp}.m4a` and are excluded from iCloud backup.
198-
199196
- **Recording State:** Only one recording can be active at a time. Calling `start()` while a recording is in progress will return `false`.
200197

201-
- **Auto-Start Behavior:** If you don't explicitly call `start()`, the recording will automatically start when the `PendingAudioRecorder` is destroyed. This maintains backward compatibility with earlier versions.
198+
- **Auto-Start Behavior:** If you don't explicitly call `start()`, the recording will automatically start when the `PendingMicrophone is destroyed. This maintains backward compatibility with earlier versions.

resources/views/docs/mobile/2/apis/push-notifications.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Fired when a push notification token is successfully generated.
3737
use Livewire\Attributes\On;
3838
use Native\Mobile\Events\PushNotification\TokenGenerated;
3939

40-
#[On('native:'.TokenGenerated::class)]
40+
#[OnNative(TokenGenerated::class)]
4141
public function handlePushToken(string $token)
4242
{
4343
// Send token to your backend

resources/views/docs/mobile/2/apis/qrcode.md renamed to resources/views/docs/mobile/2/apis/scanner.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
2-
title: QR Code Scanner
2+
title: Scanner
33
order: 350
44
---
55

66
## Overview
77

8-
The QR Code Scanner API provides cross-platform barcode scanning capabilities through a native camera interface.
8+
The Scanner API provides cross-platform barcode and QR code scanning capabilities through a native camera interface.
99

1010
```php
1111
use Native\Mobile\Facades\Scanner;
12-
use Native\Mobile\Events\QrCode\Scanned;
12+
use Native\Mobile\Events\Scanner\CodeScanned;
1313
```
1414

1515
## Basic Usage
@@ -19,7 +19,7 @@ use Native\Mobile\Events\QrCode\Scanned;
1919
Scanner::scan();
2020

2121
// Listen for scan results
22-
#[On('native:'.Scanned::class)]
22+
#[OnNative(Scanned::class)]
2323
public function handleScan($data, $format, $id = null)
2424
{
2525
Dialog::toast("Scanned: {$data}");
@@ -64,7 +64,7 @@ Scanner::scan()->id('checkout-scanner');
6464

6565
## Events
6666

67-
### `Scanned`
67+
### `CodeScanned`
6868

6969
Fired when a barcode is successfully scanned.
7070

@@ -74,7 +74,7 @@ Fired when a barcode is successfully scanned.
7474
- `string|null $id` - The scan session ID (if set)
7575

7676
```php
77-
#[On('native:'.Scanned::class)]
77+
#[OnNative(CodeScanned::class)]
7878
public function handleScan($data, $format, $id = null)
7979
{
8080
if ($id === 'product-scanner') {
@@ -88,4 +88,6 @@ public function handleScan($data, $format, $id = null)
8888
- **Platform Support:**
8989
- **Android:** ML Kit Barcode Scanning (API 21+)
9090
- **iOS:** AVFoundation (iOS 13.0+)
91-
- **Permissions:** You must enable the `qr_code` permission in `config/nativephp.php` to use the scanner. Camera permissions are then handled automatically, and users will be prompted for permission the first time the scanner is used.
91+
- **Permissions:** You must enable the `qr_code` permission in `config/nativephp.php` to use the scanner. Camera
92+
permissions are then handled automatically, and users will be prompted for permission the first time the scanner is
93+
used.

resources/views/docs/mobile/2/apis/share.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Share a photo that was captured with the camera.
7373
use Livewire\Attributes\On;
7474
use Native\Mobile\Events\Camera\PhotoTaken;
7575

76-
#[On('native:'.PhotoTaken::class)]
76+
#[OnNative(PhotoTaken::class)]
7777
public function handlePhotoTaken(string $path)
7878
{
7979
Share::file(

resources/views/docs/mobile/2/concepts/push-notifications.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ use Native\Mobile\Events\PushNotification\TokenGenerated;
7373

7474
class PushNotifications extends Component
7575
{
76-
#[On('native:'.TokenGenerated::class)]
76+
#[OnNative(TokenGenerated::class)]
7777
public function storePushToken(APIService $api, string $token)
7878
{
7979
$api->storePushToken($token);

0 commit comments

Comments
 (0)