What it is

React components that are SwiftUI views, and what that does and doesn't mean.

swiftui-react-native lets a React Native app describe its interface in React and have SwiftUI draw it. You write JSX, and every component in it is a real SwiftUI view.

<Form>
  <Toggle isOn={wifi}>Wi-Fi</Toggle>
  <Slider value={volume} in={[0, 1]} />
</Form>

That Form is SwiftUI's Form, the Toggle is SwiftUI's Toggle, and the slider is the system slider. Nothing in it is a React Native view styled to look like iOS. It's the same code a Swift app would run, so it looks, moves and behaves the same.

What you write and what runs

You keep writing React. State lives in hooks, data comes from wherever it already comes from, and components compose the way React components always do. What changes is what ends up on screen.

You writeWhat runs
<VStack spacing={8}>VStack(spacing: 8)
compose().padding().background('blue').padding().background(.blue)
useBinding(true)A SwiftUI Binding<Bool> that reads and writes your React state
withAnimation('snappy', () => …)withAnimation(.snappy) { … }
A React component inside a SwiftUI viewA React Native view embedded in SwiftUI, laid out by Yoga

The last row matters most. SwiftUI and React Native live in the same tree. A SwiftUI List can hold your own React components, and those components can hold more SwiftUI. You don't need separate roots or wrapper views, and you never pass sizes back and forth by hand.

How it fits together

Four pieces each do the job they're best at:

  • React decides what the tree is: which components, with which props, in which order.
  • Fabric, React Native's renderer, mounts that tree and keeps it in sync as state changes.
  • SwiftUI draws each view, runs its animations and handles its gestures. It also measures the view and reports the size back.
  • Yoga, React Native's layout engine, lays out the React content around and inside SwiftUI views, using the sizes SwiftUI reported.

Each SwiftUI component is a Fabric component whose native view hosts SwiftUI. Its shadow node, the part of Fabric that layout runs against, takes its size from SwiftUI. So Yoga and SwiftUI agree on how big everything is, without either one guessing. How it renders follows a component through each step.

Generated from Apple's SDK

Almost none of the API is written by hand. It's generated from the SwiftUI declarations that ship with Xcode:

  • Every view becomes a component, and its initializer's parameters become props.
  • Every modifier becomes a method on compose(), with one form for each Swift overload.
  • Every value type, such as Font, Color, Animation or ShapeStyle, becomes a typed JavaScript value.

The reference is generated from the same declarations, so it lists exactly what the package exports. It currently covers over 100 views, about 450 modifiers and about 490 value types. Each one comes with its parameters, its types and the iOS version it needs.

The generator isn't part of the package. You install the generated components and the native runtime they run on, and those compile into your app during the normal native build. Your app never compiles or looks up Swift while it runs.

What it isn't

  • Not a look-alike. It doesn't redraw iOS controls in JavaScript. If SwiftUI changes how a Toggle looks in the next iOS, your toggle changes with it.
  • Not a Swift-to-JavaScript converter. You don't write Swift, and it doesn't translate Swift source. It exposes Apple's API, typed, to React.
  • Not cross-platform. SwiftUI only exists on Apple platforms, so this is an iOS library. If you need Android too, you'll need a different component for each platform.
  • Not all of SwiftUI yet. Most APIs map directly onto React. Some need hand-written native support before they work, and a few can't be represented safely at all. The reference only lists what you can actually use.

Requirements

  • iOS, with the New Architecture
  • React Native 0.80 or newer
  • react-native-nitro-modules