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.
{
"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)
| Workload | iPhone 17 Pro · Starlight | iPhone 17 Pro · Yoga | Galaxy S10 5G · Starlight | Galaxy S10 5G · Yoga |
|---|---|---|---|---|
| Mount 32 feed rows | 17.40 | 17.40 | 52.40 | 53.95 |
| Update one feed row | 2.27 | 2.36 | 7.50 | 7.28 |
| Mount 341 native views | 25.65 | 26.33 | 88.80 | 82.51 |
| Mount 5,461 native views | 120.05 | 126.70 | 513.26 | 543.84 |
| Change one leaf’s width in the 5,461-view tree | 14.57 | 35.62 | 30.04 | 54.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
- 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 sharedNitroLayoutlibrary already implementsNLNodeFromHandleandNLNullNode. - Calculate frames in
NLSolveand deliver pending frames synchronously inNLApplyLayout. Implement dirty tracking, scale-aware rounding and content insets. A portal can passNaNfor a viewport dimension so the engine measures its content. - Ship the adapter and its engine in an npm package that exports
./package.json. Expose a SwiftPM library product namedNitroLayoutProviderthat depends onNitroLayoutfrom../nitro-ui-layout. On Android, expose a CMake target with the same name and link it toNitroLayout. - Install the package in an app, set
layoutEngineto 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