Hotwire Native
Hotwire Native builds iOS and Android apps around the same pages. Each page opens as a native screen, with native navigation, modals and a top bar. The web app stays the product, and the server adds a few small things for the apps.
What the server does for the apps
It tells them apart. Their user agent contains Hotwire Native. src/turbo.tsx's
isNative(c) checks for it, and the layout leaves out the web navbar and dock, because the apps draw their own:
a top bar titled with the page's <title>, and native tabs (below).
It serves navigation rules. The apps fetch a path configuration: JSON rules that match URL paths and say
how to open them. The example serves them as static files from public/configurations/:
{
"settings": {},
"rules": [
{ "patterns": [".*"], "properties": { "context": "default", "pull_to_refresh_enabled": true } },
{ "patterns": ["/new$"], "properties": { "context": "modal", "pull_to_refresh_enabled": false } }
]
}
So /messages/new opens as a modal. Later rules override earlier ones. Android also needs a uri on each rule
(hotwire://fragment/web, which a modal context opens full screen, as on iOS; or
hotwire://fragment/web/modal/sheet for a bottom sheet, which leaves the page behind it reachable); see the
example's android_v1.json. Keep the file names versioned (ios_v1.json), and serve old versions for as long as old app
builds use them. Changing the server's copy changes installed apps, with no release needed.
It closes modals after forms. After the form on /messages/new succeeds, a browser is redirected to /.
An app is redirected to /refresh_historical_location instead: it closes the modal and reloads the screen
under it, without ever showing that page. That is refreshOrRedirect(c, "/"). The apps also understand
/recede_historical_location (go back) and /resume_historical_location (close the modal and do nothing
else). The router answers all three with a few words of HTML: Turbo follows a form's redirect only to an HTML
page, so an empty or plain-text answer leaves the modal open.
Reference: https://native.hotwired.dev/reference/path-configuration and https://native.hotwired.dev/reference/navigation
Tabs
The web app's top-level pages are in one list, src/components/nav.tsx, which the navbar
and dock are drawn from (Pages). The apps show the same pages as native tabs, each with a navigation
stack of its own, so going back in one tab never leaves it:
| iOS | Android | |
|---|---|---|
| The tabs | HotwireTab(title:image:url:) in App/SceneDelegate.swift |
HotwireBottomTab(title, iconResId, configuration) in MainActivity.kt |
| Shown by | HotwireTabBarController, the window's root |
HotwireBottomNavigationController, on a BottomNavigationView in activity_main.xml |
| Icons | SF Symbols (UIImage(systemName:)) |
Vector drawables in res/drawable/ |
Each Android tab names a navigator host of its own in activity_main.xml, and the bar hides itself while a modal is
open. A new top-level page goes in all three places: nav.tsx, SceneDelegate.swift and MainActivity.kt.
Android makes the activity again when the theme changes (Bridge components): MainActivity
saves the open tab and loads the tabs with it (load(tabs, selectedTabIndex)), or the bar would show About over the
Messages page. flows/navigation.yaml checks that both apps switch tabs and leave the web navbar out.
Bridge components
A bridge component lets the page ask the app for a native control. It is a Stimulus controller on the web, and
a Swift class and a Kotlin class with the same name in the apps. Before writing one, take it from
joemasilotti/bridge-components (MIT), whose ten components each
come in three parts, one version for all three: the npm package @joemasilotti/bridge-components (package.json), a
Swift package (native/ios/project.yml) and a JitPack library (native/android/app/build.gradle.kts). The example
uses all ten:
| Component | Where | In the apps | In a browser |
|---|---|---|---|
button |
Messages: "New message" | A button in the top bar | The link |
search |
Messages | A search bar, which filters the list (message_filter_controller.ts) |
A search field, which does the same |
form |
New message | Send in the top bar, greyed out while it sends | The form's own button |
haptic |
Both message forms | A tap of the phone as it sends | Nothing |
toast |
The notice after sending, "Message sent." | A native toast | A daisyUI toast |
menu |
Account, signed in | A menu in the top bar, with "Sign out" | The button |
alert |
"Sign out" | A native alert asks first | Signs out |
share |
About | A share button in the top bar, for the system's share sheet | Nothing: a browser has its own |
review-prompt |
About: "Rate this app" | The App Store's or Google Play's prompt | Hidden |
theme |
Every page, chosen on About | The app's own bars and screens, light or dark | daisyUI's data-theme |
On the web, src/controllers/index.ts registers the library's controllers by
their names (bridge--button, …); the apps register its native halves with the app's own passkey:
Hotwire.registerBridgeComponents(Bridgework.coreComponents + [PasskeyComponent.self]) in AppDelegate.swift, and
*Bridgework.coreComponents in ExampleApplication.kt. A component's controller loads only in an app that has its
native half: in a browser, or an app without it, the HTML works as it is (the passkey controller, which works in a
browser too, says otherwise: Signing in). Where the app draws the control natively,
src/app.css hides the web one:
[data-bridge-components~="button"] [data-controller~="bridge--button"] { display: none; }
Two are used through a controller of the example's own, in src/controllers/bridge/:
notice_controller.tsextends the library's toast controller, which shows when its element is clicked, to show as soon as the page has it: the notice the server renders after a redirect (a cookie,leaveNoticeinsrc/notice.ts), or streams with the inline form's answer.theme_controller.tsstands in for the library's web half, which sends""for "the device's", which neither app reads: an app set dark stayed dark until it restarted. It sendsnull, which both read as the device's.
The button, form, menu and share components each put their control on the right of the top bar, and the last
one there wins: one of them to a page. search goes under the top bar on iOS, and beside its buttons on Android.
The library's other web halves (barcode scanner, location, NFC and more) are for its paid Pro set's native halves,
whose licence forbids a public repository: not in this one. Its version 0.14.0 takes Hotwire Native iOS 1.2 and 1.3,
and declares Android 1.2 and 1.3; the example's Android app has 1.4.1, which Gradle takes and the flows check. Its
Android library needs compileSdk 36.
A component can also answer. The passkey component (Signing in) sends the passkey options it
fetched from the server, the app asks the system for the passkey, and replies with it, which the web half posts back.
In a browser the same controller uses WebAuthn itself. Neither the bridge nor the library has TypeScript types, so
the example declares what it uses in src/hotwire-native-bridge.d.ts and src/bridge-components.d.ts.
Running the apps
Both apps are in example/native/. On a Mac, in the app's directory (where its mise.toml
is):
mise install # once: the tools (Node, Vite+, Java, XcodeGen, Maestro, mkcert, Android's command-line tools)
vp install # once: the npm packages
vp run setup # once: mkcert's CA trusted, the simulators, the Android SDK and the emulators
vp run workspace # everything running, side by side; leave it open
vp run workspace starts the dev server, opens the web app in a window of its own, starts the Android emulator and
the iOS simulator (Device Hub, in Xcode 27) with the apps installed and pointed at the dev server, and tiles the
three windows across the screen: web, Android, iOS. The dev server runs in that terminal, and Ctrl-C stops it. Run
it again from another terminal at any time: what runs stays, an app is built only when its Swift or Kotlin
changed, and the windows are tiled again.
Moving other apps' windows needs Accessibility access for your terminal, and only you can switch that on: when it
is missing, the workspace opens that page of System Settings for you. Switch your terminal on there, then run
vp run workspace again.
Then most changes need no restart:
| You change | It shows |
|---|---|
| A route, a component, a helper (server code) | In the browser and both apps, by itself: the dev server tells every open page, which refreshes with Turbo's morph (hotwireRefresh in vite.config.ts) |
| CSS, a Stimulus controller (browser code) | In the browser and both apps, by itself, without a reload (Vite's hot updates; a controller is swapped in place by vite-plugin-stimulus-hmr) |
| A path configuration | In both apps, by itself: the dev server opens them again, as they read it only when they start |
vite.config.ts, or the dev server stopped and started |
In both apps, by itself: the dev server opens them again when it is back |
| Swift or Kotlin | vp run ios or vp run android: builds, installs, opens |
A page that fails to load, such as a server error from a half-finished change, shows as Hotwire Native's "Error loading page" in an app. That screen holds no page, so no refresh reaches it, and it would stay until you tapped Retry (iOS) or pulled down (Android). The dev server watches for it instead: after it has answered an app with a server error, your next save opens both apps again, and it says so in its terminal ("opened the iOS and Android app again"). The apps start over on their first tab.
vp run ios and vp run android alone run one app. To run them against a deployed app instead, give its address:
HOTWIRE_URL=https://my-app.example.workers.dev vp run ios.
The commands are tasks in vite.config.ts, and their code is TypeScript in
example/tasks/, which Node runs as it is. What they make (the dev certificate, the web
window's browser profile, the flows' screenshots) is in .dev/, which git ignores.
The apps' builds are tasks of their own, which Vite Task caches: build:ios (after generate:ios, XcodeGen) and
build:android, given the app's address after the name (vp run build:ios HOTWIRE_URL=…). An app is built again
only when its files or its address changed; otherwise the built app comes back from the cache, one entry for each
address, and vp run ios only installs and opens it. vp cache clean empties the cache.
https
The dev server is https, at one address for the browser and both apps (https://hotwire.localhost:5173): a name under
.localhost is this Mac to a browser and to the iOS simulator, and vp run android sends the emulator's port to the
Mac (adb reverse), so the name leads there too. It has a
certificate from mkcert's local CA, which vite.config.ts makes the first time
vp dev or vp preview runs (devHttps), in .dev/certs/. The apps trust that CA by themselves: the iOS task adds
it to the simulator (xcrun simctl keychain … add-root-cert), and Android debug builds carry it
(res/raw/dev_ca.pem, named by res/xml/network_security_config.xml). vp run setup:certs adds it to your Mac's
browsers too, and asks for your password once.
| iOS | Android | |
|---|---|---|
| The project | native/ios/project.yml: XcodeGen writes the Xcode project from it, so none is kept |
native/android/: a Gradle project, with its wrapper |
| The app | App/AppDelegate.swift, App/SceneDelegate.swift |
ExampleApplication.kt, MainActivity.kt |
| The bridge components | joemasilotti/bridge-components' Swift package, in project.yml; App/PasskeyComponent.swift |
Its JitPack library, in app/build.gradle.kts; PasskeyComponent.kt |
| What keeps a passkey (Signing in) | The simulator's own Passwords | The emulator's own keeper, Google Password Manager; for a name on your Mac, which Google can't read, keeper/: a second app, for tests, that vp run android installs beside it |
| The path configuration it starts with | public/configurations/ios_v1.json, the server's own file |
public/configurations/android_v1.json, the server's own file |
| The server's address | HOTWIRE_URL, a build setting |
-Photwire.url, a Gradle property |
Both apps have the same identifier, dev.hotwireskills.example. Neither needs signing to run in the simulator or the
emulator.
Testing the apps
vp run test:ios
vp run test:android
vp run test:all # everything: what CI runs, then iOS and Android
serve the web app in Vite's test mode, with data of its own, install each app pointed at it, and run the
Maestro flows in flows/ in it: the same files that vp run test:browser
runs in Chromium, as the pages are the same (Testing).
What only the apps have is in those files too, as steps for the apps alone: the web navbar is gone and the tabs
switch, the native "New" button opens the form as the modal the path configuration says, its native Send sends, and
the modal closes with the message listed and the notice as a native toast, of which the flow takes a screenshot.
The search is the native search bar, "Sign out" is in the native menu with its alert, and About opens the share
sheet and the review prompt (iOS) and turns the app's own bars dark and back.
What they can't check: the phone's tap (haptic: the simulator and the emulator have none), Google Play's review
prompt, which shows only in an app installed from it, and the toast's text, which neither app puts where Maestro reads
(iOS draws it over the window, Android's system draws it): the flow takes its screenshot at once, while it shows.
The tests have devices of their own, which vp run setup makes: the "Hotwire Test" simulator and the "hotwire-test"
emulator, each in a window of its own, to watch. A test run starts them, and stops them when it ends; when every
flow's last pass still stands, it starts nothing and replays them
(only the flows a change touched: a change to the app's Swift or Kotlin
runs all of that app's flows). Your workspace's
apps, devices and data are never touched, so the tests can run while you work. A tests' simulator that does not start
("Invalid argument", or "SpringBoard quit unexpectedly" again and again) is emptied and started again by the run: it
holds nothing to keep. They run on a Mac, never in CI
(Testing). The tests' emulator shows no error dialogs: a cold
boot on a busy Mac can leave "System UI isn't responding" over the app, which no flow gets past.
While you work on a flow, skip the build: with the workspace running, run the flows on its apps as they are, against the dev server, or one flow, or keep one running again on every save:
vp run flows:ios # the flows your changes touched, on the workspace's app
vp run flows:android new-message # one flow: flows/new-message.yaml
vp run flows:ios new-message --watch # that one now, and again at each save that changes a step
A new device shows what a well-used one hides. Its keyboard drops the first letters typed while it first opens, so
the flows type through flows/parts/type.yaml, a retry that checks the field holds the whole text. And an Android
emulator counts as having a stylus: the keyboard's first opening after each start brings up Gboard's "Try out your
stylus" over the app, which takes what is typed next. The tasks turn writing by stylus off when they start an
emulator (stylus_handwriting_enabled), yours too, so the Mac's keyboard types into the app. And when the
appearance changes, Android makes the activity again, after which Maestro can read the page incompletely: the whole
Appearance card on the screen, and missing from what it reads. So after each change about.yaml only waits there
(flows/parts/appearance.yaml), starts the app again and checks then, which also checks that the choice is kept.
That check found the Android app losing it: a web view keeps its cookies in
memory and writes them to the device only every so often, so an app closed right after a choice, or a sign-in,
started again without it. MainActivity.onStop writes them (CookieManager.getInstance().flush()) whenever the app
leaves the screen.
When a flow fails, its screenshots and the screen's elements for each step are in .dev/maestro/.
maestro studio shows the running app's elements, to write a step against.
Check, without the apps
app=https://hotwire.localhost:5173
curl -A 'Hotwire Native iOS;' $app/ # no <nav> in the page
curl -i -A 'Hotwire Native iOS;' -X POST --data-urlencode body=hi -d standalone=1 $app/messages
# 303 to /refresh_historical_location
curl $app/configurations/ios_v1.json
vp test checks the first two (Testing).