Skip to content
Preview: packages are not published yet.

Run and develop

Open your surfaces on a simulator or emulator and edit them with Fast Refresh. Start with the viewer, which needs no native app. Then run the same surfaces inside the real native app. You need a configured project, with the patches applied, and a registered surface: see Install and Your first surface.

The viewer is a small native app for working on surfaces without the real app. Boot a simulator or start an emulator, then run one command in the React project.

Terminal window
bun run nuib dev ios --viewer # the viewer on the booted simulator

The command starts the dev server, packages your project, builds the viewer and opens it. The first run compiles the native engine and takes a few minutes. Later runs reuse what did not change and take seconds.

The first screen lists every surface you registered. Tap PointsHistory.

The viewer builds a form from the props type. Change a value and tap Apply. The surface renders again with the new props and keeps its state.

Prop type Control
string Text field
number Text field, read when you tap Apply. If it is not a number, Apply shows an error and changes nothing.
boolean Switch
union of string literals Segmented picker on iOS, radio buttons on Android. A menu above four members.
optional prop A switch that sets the prop or leaves it out, then its control
object Indented section
array Items you can remove, plus Add

You can open the same surface in three frames: Screen (full screen), Block (a view whose width and height you set) and List cell (one surface per row of a native list).

Put a file named PointsHistory.presets.json next to the surface source. The viewer lists its presets for that surface. Tapping one fills the form and applies it.

src/surfaces/PointsHistory.presets.json
{
"presets": [
{ "name": "Last month", "props": { "userId": "42", "filter": "lastMonth" } },
{ "name": "Compact", "props": { "userId": "42", "compact": true } }
]
}

Each preset needs a unique, non-empty name. Its props must match the props type: required props present, matching types, no unknown keys and no null. An invalid preset is left out and reported in the terminal and on the viewer’s first screen.

Save a source file. Fast Refresh shows the change in the open surface and keeps its state. The dev server stays in the foreground and reads these keys:

Key Action
r Reload
m Open the developer menu
q Quit

New surfaces, changed props and new presets do not rebuild the viewer. Run the command again and they appear.

Now see the surface where users will see it. Tell nuib where the native app’s project is, in the brownfield key of package.json. Paths are relative to the React project. Add this inside "brownfield":

package.json
"dev": { "port": 8081 },
"hosts": {
"ios": "../ios-app",
"android": "../android-app"
}

When the Xcode project has several schemes, or the Android app module is not app, use the long form:

package.json
"hosts": {
"ios": { "path": "../ios-app", "scheme": "Shop", "configuration": "Debug" },
"android": { "path": "../android-app", "module": "app" }
}

The native app must already depend on the ShopReact artifact and open your surface somewhere. The native team sets this up once.

Terminal window
bun run nuib dev ios # the iOS app on the booted simulator

One command does all of this, in order:

  1. Picks the simulator or emulator. Pass --device when several are running.
  2. Packages the development variant of your project. Caches skip what did not change.
  3. Points the native app at that local build, without editing the native project.
  4. Builds the native app, and installs it unless the same build is already installed.
  5. On Android, forwards the dev server port to the emulator.
  6. Starts the dev server, unless one already answers on the port.
  7. Launches the app.

Open your surface in the app and save a source file. The change appears without a rebuild of the app.

Press q or Ctrl-C to end. nuib then points the native app back at its published dependency, so the native project has no changes left to commit. The app installed on the simulator keeps the development build.

Option Use
--viewer With ios or android: open the viewer and not the native app
--device <udid|name|serial> The simulator or emulator, when several are running
--port <n> The dev server port. Default: dev.port, else 8081
--project <dir> The React project. Default: the current directory

nuib dev without a platform starts the dev server and opens nothing.

In the terminal, nuib dev ios prints these lines among the build output (abridged):

$ nuib dev ios
nuib dev: ios host ../ios-app on <simulator>, dev server http://localhost:8081
nuib dev: started the dev server of <project> on port 8081 (pid <pid>)
nuib dev: <bundle id> is running on <simulator> with the project live in it.
q or Ctrl-C stops the server and points the host back at its
published dependency.

After you press q:

nuib dev: <native app> points at its published dependency again

In the app:

  • Your surface shows “Points history” and the member id the native screen passed.
  • A development indicator shows that the app loads from the dev server. Tap it for the developer menu.
  • A saved change appears in the open surface, and the surface keeps its state.

If the dev server does not answer when the app starts, the app shows the content packaged inside it and a short notice. It never shows a blank screen. Start the server with bun run nuib dev, then press Retry in the notice or launch the app again.

Message or symptom What to do
No "brownfield" key in … Add the brownfield key to package.json (Configure the project). Run nuib in the React project or pass --project.
brownfield has an unknown key "…" Remove or fix the field. The message lists the known keys.
No simulator is booted: boot one, then run the command again Boot an iOS simulator first.
No Android device is connected: start an emulator, then run the command again Start an Android emulator first.
2 simulators are booted (…): pass --device <udid> Pass --device with the UDID or name. On Android, pass the serial.
--viewer needs a platform Name the platform: nuib dev ios --viewer or nuib dev android --viewer.
nuib dev ios needs the native app: add "hosts" … Add hosts.ios or hosts.android (step 2), or open the viewer.
… has 2 schemes (…): name the one to build in brownfield.hosts.ios Use the long form of hosts.ios with scheme.
… has no Swift package dependency named ShopReact The native app does not depend on the artifact yet. Ask the native team to add the published package first.
surface "PointsHistory", property "…": … A prop type does not fit the props rules. Fix every listed prop.
nuib dev: invalid preset: <file>: <JSON path>: <reason> Fix the preset so that it matches the props type. The other presets still load.
the dev server did not answer at … within 60 s Read the dev server output above the message. Check that no other program uses the port, or pass --port.
nuib dev: the viewer did not open: … The dev server keeps running. Fix the cause in the message and run the command again.
The app shows old content and a notice The dev server did not answer. Start it with bun run nuib dev, then press Retry in the notice or launch the app again.
The surface fails to open in the native app Check that the name the native code opens is registered, and that the module with registerSurface is imported from the entry file.
nuib package or nuib publish refuses because of a link The message names the linked app. If an nuib dev ios or nuib dev android session is still running, end it with q. If a session was killed, run nuib dev again: it repairs the link and says so. If you made the link with nuib link, run nuib unlink <app>.