Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions resources/views/docs/mobile/4/testing/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ it('omits the android translucency on ios', function () {
`assertElement($type, $matcher)` finds an element of a wire type, optionally narrowed by a closure receiving the wire
node; `assertMissingElement()` is its inverse.

`platform` also answers [platform detection](../the-basics/system#platform-detection) inside the screen
<x-docs.version-badge changed="4.7" />: `System::isIos()` and friends, the `isIos()` helpers, and the `@ios`,
`@android`, `@mobile` and `@web` Blade directives all report the platform you passed.

In a test that doesn't render a screen, such as an HTTP test for a Blade view, set the `NATIVEPHP_PLATFORM`
environment variable instead <x-docs.version-badge since="4.7" />. It's what the app sets on a real device. Clear it
after each test so it doesn't leak into the next one:

```php
afterEach(fn () => putenv('NATIVEPHP_PLATFORM'));

it('offers Sign in with Apple on iOS', function () {
putenv('NATIVEPHP_PLATFORM=ios');

$this->get('/login')->assertSee('Sign in with Apple');
});
```

To audit a tree for screen-reader accessibility rather than a specific element, see
[Accessibility](accessibility).

Expand Down
4 changes: 2 additions & 2 deletions resources/views/docs/mobile/4/the-basics/device.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ $info['model']; // e.g. 'iPhone15,3'

<aside>

`System::isIos()`, `isAndroid()`, and `isMobile()` are thin conveniences over `getInfo()['platform']` — reach
for those when you only need platform detection. See [System](system).
When you only need the platform, reach for `System::isIos()`, `isAndroid()`, `isMobile()` or `platform()` instead.
On the device they don't call `getInfo()` at all. See [System](system).

</aside>

Expand Down
20 changes: 19 additions & 1 deletion resources/views/docs/mobile/4/the-basics/system.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,27 @@ use Native\Mobile\Facades\System;
System::isIos(); // true on iOS
System::isAndroid(); // true on Android
System::isMobile(); // true on either platform
System::platform(); // 'ios', 'android', or null outside the app
```

Use these to branch behavior or conditionally render UI for a specific platform.
Use these to branch behavior or conditionally render UI for a specific platform. `System::platform()`
<x-docs.version-badge since="4.7" /> gives you the answer as a string, which saves checking both.

On the device <x-docs.version-badge changed="4.7" />, the platform comes from an environment variable the app sets
before PHP starts, so these checks are cheap enough to call as often as you like, even once per row of a long list.
Before 4.7 every check asked the native side, which was far slower.

Under [Jump](jump), PHP runs on your computer instead of the phone, so that variable isn't set. The first check asks
the connected device, and the answer is remembered after that.

To render a screen as one platform in a test, see [Platform variants](../testing/advanced#platform-variants).

<aside>

If you've been using the undocumented `Native\Mobile\Platform` class, switch to these methods. It's
<x-docs.version-badge deprecated="4.7" /> and passes straight through to `System` until it's removed.

</aside>

Each is also available as a global helper function — `isIos()`, `isAndroid()`, `isMobile()` — for terse use in
Blade and components:
Expand Down
Loading