|
| 1 | +--- |
| 2 | +title: SuperNative Introduction |
| 3 | +order: 5 |
| 4 | +--- |
| 5 | + |
| 6 | +## What is SuperNative? |
| 7 | + |
| 8 | +SuperNative is our name for a combination of technologies that enable PHP to produce platform-native UI at |
| 9 | +blistering speeds. |
| 10 | + |
| 11 | +While SuperNative uses HTML-like syntax, **there is no need for a web view**. Your apps built with Blade |
| 12 | +can fully leverage the native components and performance of each platform's UI tools, directly from PHP — SwiftUI |
| 13 | +on iOS and Jetpack Compose on Android. |
| 14 | + |
| 15 | +Your app's screens are not web views rendering HTML. They are real, platform-native views, built and |
| 16 | +updated by your PHP code. Same Laravel app, same Blade templates, two genuine native UIs. |
| 17 | + |
| 18 | +You don't need to think about the right syntax for Android vs iOS, just use EDGE. |
| 19 | + |
| 20 | +SuperNative is **the default**. New apps render native screens from the very first route — no configuration |
| 21 | +required. |
| 22 | + |
| 23 | +<aside> |
| 24 | + |
| 25 | +Prefer to keep building with the web view? [Opting out](#is-the-web-view-still-an-option) of native UIs couldn't |
| 26 | +be simpler. |
| 27 | + |
| 28 | +</aside> |
| 29 | + |
| 30 | +## What SuperNative is not |
| 31 | + |
| 32 | +SuperNative is not a fully custom renderer, like Skia or Impeller. It does not attempt to create pixel-perfect |
| 33 | +cross-platform user interfaces. Instead it *embraces* the differences and simply smooths over them with a single |
| 34 | +consistent syntax. |
| 35 | + |
| 36 | +It's not another virtual machine on top of or adjacent to PHP trying to convert *all* instructions to/from native |
| 37 | +equivalents. It's explicitly focused on turning PHP objects that conform to a known interface into a fixed-length |
| 38 | +byte array that can be processed by an explicit native-side interpreter. |
| 39 | + |
| 40 | +It is also not a transpiler or HTML-to-native converter. We've built our own Blade engine that converts Blade components |
| 41 | +into a simplified binary format instead of HTML ([The Renderer](renderer)) and passes the |
| 42 | + |
| 43 | +## Try it now |
| 44 | + |
| 45 | +The fastest way to see SuperNative is to run the demo app, |
| 46 | +[`nativephp/super-native`](https://github.com/nativephp/super-native), on a simulator or device. |
| 47 | + |
| 48 | +You'll need a working NativePHP for Mobile [development environment](../getting-started/environment-setup) first |
| 49 | +(Xcode for iOS, Android Studio for Android). Then clone the demo, install it, and run it: |
| 50 | + |
| 51 | +```shell |
| 52 | +git clone https://github.com/nativephp/super-native |
| 53 | +cd super-native |
| 54 | +composer install |
| 55 | +php artisan native:install |
| 56 | +php artisan native:run |
| 57 | +``` |
| 58 | + |
| 59 | +`native:run` builds the app and launches it on your connected device or simulator. Explore the source to see how |
| 60 | +the screens are built, then start swapping in your own. |
| 61 | + |
| 62 | +## How it works |
| 63 | + |
| 64 | +SuperNative builds on three ideas working together: |
| 65 | + |
| 66 | +- **Shared memory with PHP** — the native layer and your PHP application share memory directly, so there's no |
| 67 | + network round-trip, no serialization overhead, and no waiting on a web view bridge. State changes flow between |
| 68 | + PHP and the native UI almost instantly. |
| 69 | +- **Livewire-like components** — each screen is driven by a PHP component class that holds its state and behavior, |
| 70 | + just like a Livewire component. User interactions call your methods, your properties update, and the UI |
| 71 | + re-renders to match. |
| 72 | +- **Blade components for DX** — you define your UI with the same [EDGE component](../edge-components/introduction) |
| 73 | + syntax you already know. Familiar, expressive Blade templates compile down to native SwiftUI and Compose views. |
| 74 | + |
| 75 | +If you've built anything with Livewire, you already know how to build with SuperNative. |
| 76 | + |
| 77 | +For a look under the hood — how Blade becomes SwiftUI and Compose, how state flows across the shared-memory |
| 78 | +boundary, and the threading model behind it — see the rest of the [Architecture](about-the-new-architecture) section. |
| 79 | + |
| 80 | +<aside> |
| 81 | + |
| 82 | +You **don't** need to read any of this to build apps with NativePHP. If you're here to ship an app, start with the |
| 83 | +[Quick Start](../getting-started/quick-start) and [The Basics](../the-basics/overview) instead. This section is for |
| 84 | +the curious — and for plugin authors and contributors who want to understand the machinery they're building on. |
| 85 | + |
| 86 | +</aside> |
| 87 | + |
| 88 | +## Why SuperNative? |
| 89 | + |
| 90 | +Two reasons above all: |
| 91 | + |
| 92 | +- **Performance** — native views render and animate at full platform speed. No web view startup cost, no DOM, no |
| 93 | + JavaScript bridge. Scrolling, transitions and gestures feel exactly the way users expect because they're powered |
| 94 | + by the same UI frameworks every other native app uses. |
| 95 | +- **Accessibility** — SwiftUI and Jetpack Compose come with the platform's accessibility support built in. |
| 96 | + Screen readers, dynamic type, contrast settings and assistive controls work with your app out of the box, |
| 97 | + rather than being approximated through a browser. |
| 98 | + |
| 99 | +There's more detail [in this blog article](/blog/supernative). |
| 100 | + |
| 101 | +## Is the web view still an option? |
| 102 | + |
| 103 | +Yes, but instead of being the default, it's now a component that you add to a native view. To make your app behave |
| 104 | +the same way that NativePHP for Mobile versions before v4 did, you can do something like this: |
| 105 | + |
| 106 | +```php |
| 107 | +// routes/mobile.php |
| 108 | +Route::native('/home', WebViewScreen::class); |
| 109 | + |
| 110 | +// webviewscreen.blade.php |
| 111 | +<webview url="/" fullscreen /> |
| 112 | + |
| 113 | +// routes/web.php |
| 114 | +Route::view('/', 'welcome'); |
| 115 | +``` |
| 116 | + |
| 117 | +Then just set `NATIVEPHP_START_URL=/home` in your `.env`. |
| 118 | + |
| 119 | +This way your existing web view-based app can keep on working and you can start adopt SuperNative one screen at a time |
| 120 | +whenever you're ready — or not at all. |
| 121 | + |
| 122 | +## For Plugin Developers |
| 123 | + |
| 124 | +SuperNative contains **no breaking changes** to our plugin architecture. |
| 125 | + |
| 126 | +It actually expands what your plugins are capable of by giving you a standardized target for UI elements. That means your |
| 127 | +plugins can ship fully native EDGE components that you know will work consistently for developers using your plugin. |
| 128 | + |
| 129 | +No need to make your plugins UI-less abstractions or support multiple flavors of front-end tooling; simply create and ship |
| 130 | +EDGE components and every consumer of your plugin will see the UI you intended. |
0 commit comments