From 8239737d59e9cad19d6a6b45061488f45daec099 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 23 Oct 2026 21:41:14 +0100 Subject: [PATCH] Document how platform detection works from 4.7 System::isIos() and friends read the platform from an env var the app sets on device, so they no longer go through getInfo(). The Device page said they did. Adds System::platform(), how Jump detects the platform, how to fake a platform in tests, and the deprecation of the undocumented Native\Mobile\Platform class. Goes with NativePHP/mobile-air#596. Co-Authored-By: Claude Opus 5.5 --- .../views/docs/mobile/4/testing/advanced.md | 18 +++++++++++++++++ .../views/docs/mobile/4/the-basics/device.md | 4 ++-- .../views/docs/mobile/4/the-basics/system.md | 20 ++++++++++++++++++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/resources/views/docs/mobile/4/testing/advanced.md b/resources/views/docs/mobile/4/testing/advanced.md index 61ed3615f..febb6f874 100644 --- a/resources/views/docs/mobile/4/testing/advanced.md +++ b/resources/views/docs/mobile/4/testing/advanced.md @@ -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 +: `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 . 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). diff --git a/resources/views/docs/mobile/4/the-basics/device.md b/resources/views/docs/mobile/4/the-basics/device.md index 53f436cc7..131f74ee9 100644 --- a/resources/views/docs/mobile/4/the-basics/device.md +++ b/resources/views/docs/mobile/4/the-basics/device.md @@ -76,8 +76,8 @@ $info['model']; // e.g. 'iPhone15,3' diff --git a/resources/views/docs/mobile/4/the-basics/system.md b/resources/views/docs/mobile/4/the-basics/system.md index 550244bdf..9395859b7 100644 --- a/resources/views/docs/mobile/4/the-basics/system.md +++ b/resources/views/docs/mobile/4/the-basics/system.md @@ -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()` + gives you the answer as a string, which saves checking both. + +On the device , 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). + + Each is also available as a global helper function — `isIos()`, `isAndroid()`, `isMobile()` — for terse use in Blade and components: