Layout Engine

Choose the native engine that sizes and positions views, compare Starlight and Yoga, or implement a provider.

NitroUI uses Lynx Starlight by default. When you build the app, it links one native layout provider. The renderer sends that provider each view’s layout props and changes to the view tree. The provider measures content such as text, calculates the frames, and delivers them to the native views. Your components use the same layout prop with either engine.

Use Yoga

Install nitro-ui-layout-yoga in your app at the same version as nitro-ui-renderer. Set the provider in your existing app.json.

app.json
{
  "layoutEngine": "nitro-ui-layout-yoga"
}

From the app directory, run bun run nitro-ui prepare and rebuild the native app. To select Starlight again, remove the field, run prepare, and rebuild. When switching engines, check text baselines, pixel rounding, scroll content sizes, and absolutely positioned children inside static ancestors. These can produce different frames.

Starlight and Yoga benchmarks

The original comparison alternated Starlight and Yoga Release builds on two physical phones. Both providers ran the same Hermes bytecode on each phone. Each cell reports milliseconds from a React update through native frame application. The benchmark took the median within each of four fresh launches, then the median across those launches. These measurements predate the static React framework build. Original benchmark and full results (PR #623)

WorkloadiPhone 17 Pro · StarlightiPhone 17 Pro · YogaGalaxy S10 5G · StarlightGalaxy S10 5G · Yoga
Mount 32 feed rows17.4017.4052.4053.95
Update one feed row2.272.367.507.28
Mount 341 native views25.6526.3388.8082.51
Mount 5,461 native views120.05126.70513.26543.84
Change one leaf’s width in the 5,461-view tree14.5735.6230.0454.87

Starlight’s largest gain came when one leaf changed in the large tree. That update took 59% less time on iPhone and 45% less on the Galaxy. On the smaller Galaxy workloads, Yoga mounted the 341-view tree and updated a single feed row faster.

Integrate another engine

Start with the Yoga provider as a working example. Its native adapter, Swift package and CMake project show the three pieces your provider needs. Yoga provider source · C interface in Layout.h

  1. Implement the provider functions in Layout.h. Each native view owns one node and parents borrow their children. Map tree edits and style setters to your engine. Use the native measurement callback for intrinsic sizes in points. The shared NitroLayout library already implements NLNodeFromHandle and NLNullNode.
  2. Calculate frames in NLSolve and deliver pending frames synchronously in NLApplyLayout. Implement dirty tracking, scale-aware rounding and content insets. A portal can pass NaN for a viewport dimension so the engine measures its content.
  3. Ship the adapter and its engine in an npm package that exports ./package.json. Expose a SwiftPM library product named NitroLayoutProvider that depends on NitroLayout from ../nitro-ui-layout. On Android, expose a CMake target with the same name and link it to NitroLayout.
  4. Install the package in an app, set layoutEngine to its package name, run prepare, and rebuild. On iOS and Android, check a measured text node, a child insertion and removal, a change to one leaf, and an intrinsically sized portal. Check both the resulting frames and the insets after a padding change.

If you maintain a native view from before alpha.16, expose its node as layoutNodePtr. Renderer extensions can call getViewLayoutNode(view) to obtain the opaque handle. Rebuild custom native modules against the updated view spec. Provider contract

On this page