Claude Skill

ux-native

Symfony UX Native: Hotwire Native iOS and Android apps, modal navigation and native bridges for Symfony sites. Use for ux_is_native(), JSON path configuration, #[AsNativeConfiguration], ux:native:build-configs, NativeNavigator, historical locations and make:native-bridge-controll

LLM Mart · 0 points · 0 views 0 listing impressions 0 install-command copies
Download smnandre-symfony-ux-skills-skills_ux-native-78c25ed.zip · 3 KB

Install

skills CLI npx skills add https://github.com/smnandre/symfony-ux-skills/tree/main/skills/ux-native
Claude Code claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install smnandre-symfony-ux-skills@llmmart
Git git clone https://github.com/smnandre/symfony-ux-skills.git

The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole smnandre/symfony-ux-skills collection as a plugin from our marketplace. Git is the plain clone.

Skill manifest

UX Native

Serve a Hotwire Native iOS or Android app from your Symfony site. The bundle detects requests from the app, builds the JSON path configurations the app downloads, sends the app navigation actions after a form, and scaffolds Bridge controllers.

The package is experimental: its API may still change. It builds on Turbo (symfony/ux-turbo).

Installation

composer require symfony/ux-native

Flex adds @hotwired/hotwire-native-bridge and @hotwired/stimulus to importmap.php (AssetMapper) or package.json (Encore, Reprise).

Quick Reference

{% if ux_is_native() %}                         Request from the app (User-Agent contains "Hotwire Native")
NativeNavigator::isNative()                     Same check in PHP
#[AsNativeConfigurationProvider]                Class holding path configurations
#[AsNativeConfiguration('/config/ios_v1.json')] Method returning a Configuration
php bin/console ux:native:build-configs         Write the JSON files for production
NativeNavigator::redirectOrToRoute(...)         Dismiss / refresh in the app, redirect in a browser
php bin/console make:native-bridge-controller   Bridge component skeleton

Native or Browser

{% if not ux_is_native() %}
    {{ include('_navbar.html.twig') }}    {# the app shows its own navigation #}
{% endif %}
use Symfony\UX\Native\Navigation\NativeNavigator;

public function show(NativeNavigator $navigator): Response
{
    $template = $navigator->isNative() ? 'note/show_native.html.twig' : 'note/show.html.twig';
    // ...
}

Every Hotwire Native client sends Hotwire Native in its User-Agent; the bundle flags the request on kernel.request. Outside a request (console, workers), ux_is_native() returns false.

Path Configuration

The app downloads JSON describing how to present each URL (modal, pull to refresh, native screen). Declare each file as a method:

namespace App\Native;

use Symfony\UX\Native\Attribute\AsNativeConfiguration;
use Symfony\UX\Native\Attribute\AsNativeConfigurationProvider;
use Symfony\UX\Native\Configuration\Configuration;
use Symfony\UX\Native\Configuration\Rule;

#[AsNativeConfigurationProvider]
final class PathConfiguration
{
    #[AsNativeConfiguration('/config/ios_v1.json')]
    public function iosV1(): Configuration
    {
        return new Configuration(
            settings: ['feature_flags' => ['new_editor' => true]],
            rules: [
                new Rule(patterns: ['.*'], properties: ['context' => 'default', 'pull_to_refresh_enabled' => true]),
                new Rule(patterns: ['/new$', '/edit$'], properties: ['context' => 'modal', 'pull_to_refresh_enabled' => false]),
            ],
        );
    }

    #[AsNativeConfiguration('/config/android_v1.json')]
    public function androidV1(): Configuration
    {
        return $this->iosV1();
    }
}

Methods must be public, non-static and return Configuration. settings and rule properties are free-form arrays: the keys (context, pull_to_refresh_enabled, uri, presentation...) are the ones the Hotwire Native path configuration understands. Version the paths (ios_v1.json) so an old app release keeps its file.

Without attributes, tag a Configuration service with ux_native.configuration and a path:

services:
    app.native.ios_v1:
        class: Symfony\UX\Native\Configuration\Configuration
        factory: ['@App\Native\PathConfiguration', 'iosV1']
        tags:
            - { name: ux_native.configuration, path: /config/ios_v1.json }

Development: in debug mode, the bundle answers these paths on the fly from the PHP objects: edit and reload the app.

Production: write the files to disk as part of the deployment, so the web server serves them statically:

php bin/console ux:native:build-configs    # public/config/ios_v1.json, public/config/android_v1.json
# config/packages/ux_native.yaml
ux_native:
    output_dir: '%kernel.project_dir%/public'   # default

Navigating After a Form

Inside the app, a form opened as a modal should close and refresh the list under it, instead of loading the next page in the modal. Since Symfony UX 3.7+, NativeNavigator redirects the app to a historical location that Hotwire Native 1.2+ intercepts, and a browser to a regular page:

# config/routes/ux_native.yaml
ux_native:
    resource: '@UXNativeBundle/config/routes.php'
use Symfony\UX\Native\Navigation\HistoricalLocation;
use Symfony\UX\Native\Navigation\NativeNavigator;

#[Route('/notes/new', name: 'app_note_new', methods: ['GET', 'POST'])]
public function new(Request $request, NativeNavigator $navigator): Response
{
    // ... handle the form
    if ($form->isSubmitted() && $form->isValid()) {
        $this->addFlash('success', 'Note created!');

        return $navigator->redirectOrToRoute(HistoricalLocation::Refresh, 'app_notes');
    }
    // ...
}
Location In the app
HistoricalLocation::Recede Dismiss the modal, or go back one screen
HistoricalLocation::Refresh Dismiss the modal, then reload the visible screen
HistoricalLocation::Resume Dismiss the modal and stay
Method In a browser
redirectOrToRoute($location, $route, $parameters) Redirect to the route
redirectOr($location, $url) Redirect to the URL
redirectOrBackOr($location, $fallbackUrl) Redirect to the same-origin Referer, else the fallback
redirect($location) Throws LogicException: call it only after isNative()

All of them answer 303 See Other, as Turbo expects after a form. Flash messages survive to the reloaded screen.

Bridge Controllers

Hotwire Native Bridge lets a Stimulus controller talk to native code (a native submit button, a menu, a share sheet). Requires symfony/maker-bundle:

php bin/console make:native-bridge-controller contact_form
// assets/controllers/contact_form_controller.js
import { BridgeComponent } from '@hotwired/hotwire-native-bridge';

export default class extends BridgeComponent {
    static component = 'contact_form';    // must match the component registered in the app

    connect() {
        super.connect();
    }

    disconnect() {
        super.disconnect();
    }
}
<form data-controller="contact-form">...</form>

Gotchas

  • redirectOr*() without the imported routes fails with a missing ux_native_*_historical_location route. A route prefix works (/app/refresh_historical_location); keep the path names themselves, since the apps match them exactly.
  • In production, skip ux:native:build-configs and the app gets a 404 for its configuration: run it on every deploy.
  • Pages differ between the app and browsers for the same URL: behind a shared HTTP cache, add Vary: User-Agent or keep those responses private.
  • Hide web navigation with ux_is_native(); leave content and forms shared, so one Turbo page serves both.

References

See Also

  • turbo: Drive, Frames and Streams power every screen of the app
  • stimulus: Bridge components are Stimulus controllers
Files (symfony-ux-skills)
  • SKILL.md 8.1 KB
    ---
    name: ux-native
    description: 'Symfony UX Native: Hotwire Native iOS and Android apps, modal navigation and native bridges for Symfony sites. Use for ux_is_native(), JSON path configuration, #[AsNativeConfiguration], ux:native:build-configs, NativeNavigator, historical locations and make:native-bridge-controller.'
    license: MIT
    metadata:
      author: Simon André
      url: https://smnandre.dev
    ---
    
    # UX Native
    
    Serve a [Hotwire Native](https://native.hotwired.dev/) iOS or Android app from your Symfony site. The bundle detects requests from the app, builds the JSON path configurations the app downloads, sends the app navigation actions after a form, and scaffolds Bridge controllers.
    
    The package is **experimental**: its API may still change. It builds on Turbo (`symfony/ux-turbo`).
    
    ## Installation
    
    ```bash
    composer require symfony/ux-native
    ```
    
    Flex adds `@hotwired/hotwire-native-bridge` and `@hotwired/stimulus` to `importmap.php` (AssetMapper) or `package.json` (Encore, Reprise).
    
    ## Quick Reference
    
    ```
    {% if ux_is_native() %}                         Request from the app (User-Agent contains "Hotwire Native")
    NativeNavigator::isNative()                     Same check in PHP
    #[AsNativeConfigurationProvider]                Class holding path configurations
    #[AsNativeConfiguration('/config/ios_v1.json')] Method returning a Configuration
    php bin/console ux:native:build-configs         Write the JSON files for production
    NativeNavigator::redirectOrToRoute(...)         Dismiss / refresh in the app, redirect in a browser
    php bin/console make:native-bridge-controller   Bridge component skeleton
    ```
    
    ## Native or Browser
    
    ```twig
    {% if not ux_is_native() %}
        {{ include('_navbar.html.twig') }}    {# the app shows its own navigation #}
    {% endif %}
    ```
    
    ```php
    use Symfony\UX\Native\Navigation\NativeNavigator;
    
    public function show(NativeNavigator $navigator): Response
    {
        $template = $navigator->isNative() ? 'note/show_native.html.twig' : 'note/show.html.twig';
        // ...
    }
    ```
    
    Every Hotwire Native client sends `Hotwire Native` in its `User-Agent`; the bundle flags the request on `kernel.request`. Outside a request (console, workers), `ux_is_native()` returns `false`.
    
    ## Path Configuration
    
    The app downloads JSON describing how to present each URL (modal, pull to refresh, native screen). Declare each file as a method:
    
    ```php
    namespace App\Native;
    
    use Symfony\UX\Native\Attribute\AsNativeConfiguration;
    use Symfony\UX\Native\Attribute\AsNativeConfigurationProvider;
    use Symfony\UX\Native\Configuration\Configuration;
    use Symfony\UX\Native\Configuration\Rule;
    
    #[AsNativeConfigurationProvider]
    final class PathConfiguration
    {
        #[AsNativeConfiguration('/config/ios_v1.json')]
        public function iosV1(): Configuration
        {
            return new Configuration(
                settings: ['feature_flags' => ['new_editor' => true]],
                rules: [
                    new Rule(patterns: ['.*'], properties: ['context' => 'default', 'pull_to_refresh_enabled' => true]),
                    new Rule(patterns: ['/new$', '/edit$'], properties: ['context' => 'modal', 'pull_to_refresh_enabled' => false]),
                ],
            );
        }
    
        #[AsNativeConfiguration('/config/android_v1.json')]
        public function androidV1(): Configuration
        {
            return $this->iosV1();
        }
    }
    ```
    
    Methods must be public, non-static and return `Configuration`. `settings` and rule `properties` are free-form arrays: the keys (`context`, `pull_to_refresh_enabled`, `uri`, `presentation`...) are the ones the [Hotwire Native path configuration](https://native.hotwired.dev/reference/path-configuration) understands. Version the paths (`ios_v1.json`) so an old app release keeps its file.
    
    Without attributes, tag a `Configuration` service with `ux_native.configuration` and a `path`:
    
    ```yaml
    services:
        app.native.ios_v1:
            class: Symfony\UX\Native\Configuration\Configuration
            factory: ['@App\Native\PathConfiguration', 'iosV1']
            tags:
                - { name: ux_native.configuration, path: /config/ios_v1.json }
    ```
    
    **Development:** in debug mode, the bundle answers these paths on the fly from the PHP objects: edit and reload the app.
    
    **Production:** write the files to disk as part of the deployment, so the web server serves them statically:
    
    ```bash
    php bin/console ux:native:build-configs    # public/config/ios_v1.json, public/config/android_v1.json
    ```
    
    ```yaml
    # config/packages/ux_native.yaml
    ux_native:
        output_dir: '%kernel.project_dir%/public'   # default
    ```
    
    ## Navigating After a Form
    
    Inside the app, a form opened as a modal should close and refresh the list under it, instead of loading the next page in the modal. Since Symfony UX 3.7+, `NativeNavigator` redirects the app to a historical location that Hotwire Native 1.2+ intercepts, and a browser to a regular page:
    
    ```yaml
    # config/routes/ux_native.yaml
    ux_native:
        resource: '@UXNativeBundle/config/routes.php'
    ```
    
    ```php
    use Symfony\UX\Native\Navigation\HistoricalLocation;
    use Symfony\UX\Native\Navigation\NativeNavigator;
    
    #[Route('/notes/new', name: 'app_note_new', methods: ['GET', 'POST'])]
    public function new(Request $request, NativeNavigator $navigator): Response
    {
        // ... handle the form
        if ($form->isSubmitted() && $form->isValid()) {
            $this->addFlash('success', 'Note created!');
    
            return $navigator->redirectOrToRoute(HistoricalLocation::Refresh, 'app_notes');
        }
        // ...
    }
    ```
    
    | Location | In the app |
    |----------|-----------|
    | `HistoricalLocation::Recede` | Dismiss the modal, or go back one screen |
    | `HistoricalLocation::Refresh` | Dismiss the modal, then reload the visible screen |
    | `HistoricalLocation::Resume` | Dismiss the modal and stay |
    
    | Method | In a browser |
    |--------|--------------|
    | `redirectOrToRoute($location, $route, $parameters)` | Redirect to the route |
    | `redirectOr($location, $url)` | Redirect to the URL |
    | `redirectOrBackOr($location, $fallbackUrl)` | Redirect to the same-origin `Referer`, else the fallback |
    | `redirect($location)` | Throws `LogicException`: call it only after `isNative()` |
    
    All of them answer `303 See Other`, as Turbo expects after a form. Flash messages survive to the reloaded screen.
    
    ## Bridge Controllers
    
    [Hotwire Native Bridge](https://native.hotwired.dev/reference/bridge-installation) lets a Stimulus controller talk to native code (a native submit button, a menu, a share sheet). Requires `symfony/maker-bundle`:
    
    ```bash
    php bin/console make:native-bridge-controller contact_form
    ```
    
    ```javascript
    // assets/controllers/contact_form_controller.js
    import { BridgeComponent } from '@hotwired/hotwire-native-bridge';
    
    export default class extends BridgeComponent {
        static component = 'contact_form';    // must match the component registered in the app
    
        connect() {
            super.connect();
        }
    
        disconnect() {
            super.disconnect();
        }
    }
    ```
    
    ```twig
    <form data-controller="contact-form">...</form>
    ```
    
    ## Gotchas
    
    - `redirectOr*()` without the imported routes fails with a missing `ux_native_*_historical_location` route. A route prefix works (`/app/refresh_historical_location`); keep the path names themselves, since the apps match them exactly.
    - In production, skip `ux:native:build-configs` and the app gets a 404 for its configuration: run it on every deploy.
    - Pages differ between the app and browsers for the same URL: behind a shared HTTP cache, add `Vary: User-Agent` or keep those responses private.
    - Hide web navigation with `ux_is_native()`; leave content and forms shared, so one Turbo page serves both.
    
    ## References
    
    - [Symfony UX package and app examples](https://ux.symfony.com/native) ([Markdown summary](https://ux.symfony.com/native.md)) · [`symfony/ux-native` on Packagist](https://packagist.org/packages/symfony/ux-native).
    - For path configuration, bridge controllers and native navigation, see the [Symfony UX Native documentation](https://symfony.com/bundles/ux-native).
    - For how the iOS and Android adapters match URLs to navigation rules, see [Hotwire Native path configuration](https://native.hotwired.dev/overview/path-configuration).
    
    ## See Also
    
    - **turbo**: Drive, Frames and Streams power every screen of the app
    - **stimulus**: Bridge components are Stimulus controllers
    

Comments

Sign in to join the conversation.

No comments yet. Start the conversation.

Reviews (0)

No reviews yet.