Skip to content

mgcrea/react-native-swiftui

Repository files navigation

logo

npm version npm total downloads npm monthly downloads npm license
build status dependencies status

Overview

Native SwiftUI components for React Native using the Fabric renderer. Build iOS forms and interfaces with SwiftUI's declarative syntax while maintaining a familiar React workflow.

Features

  • 🍎 Native SwiftUI - Real SwiftUI components, not web views or custom drawings
  • 🔧 No Dependencies - Safe from supply chain attacks
  • ⚡ Fabric Renderer - Built on React Native's modern architecture
  • 📝 TypeScript-first - Full type safety and autocomplete support
  • 🔄 Two-Way Binding - State syncs between JavaScript and SwiftUI
  • 📋 Form Components - TextField, Picker, DatePicker, Toggle, Stepper, Slider
  • 📐 Layout Components - Form, Section, HStack, VStack, ZStack, Spacer
  • 🎨 SF Symbols - Full SF Symbol support with rendering modes and variable values
  • 📱 Sheet Presentation - Native modal sheets with detent support
  • 🔌 Form Libraries - Works with react-hook-form, TanStack Form, and more

Note: This library is iOS-only. For Android, check out @mgcrea/react-native-jetpack-compose.

Demo

demo

Try it yourself with the Rxd AppStore application

Quick Start

Installation

npm install @mgcrea/react-native-swiftui
# or
pnpm add @mgcrea/react-native-swiftui
# or
yarn add @mgcrea/react-native-swiftui

Requirements

  • React Native 0.78.0+ (New Architecture required)
  • iOS 15.1+

Basic Usage

import { SwiftUI } from "@mgcrea/react-native-swiftui";
import { useState } from "react";
import { View } from "react-native";

export function ProfileForm() {
  const [name, setName] = useState("");
  const [active, setActive] = useState(false);

  return (
    <View style={{ flex: 1 }}>
      <SwiftUI style={{ flex: 1 }}>
        <SwiftUI.Form>
          <SwiftUI.Section header="Profile">
            <SwiftUI.TextField label="Name" text={name} onChange={setName} />
            <SwiftUI.Toggle label="Active" isOn={active} onChange={setActive} />
          </SwiftUI.Section>
        </SwiftUI.Form>
      </SwiftUI>
    </View>
  );
}

How It Works

SwiftUI components register themselves in a virtual tree that's rendered natively:

  1. React renders JSX - Components return null, registering nodes in a tree
  2. Tree serialization - The view tree is passed to native code as JSON
  3. SwiftUI renders - Native SwiftUI renders the entire tree
  4. Events bridge back - User interactions trigger React callbacks

This means 60fps native performance with no JavaScript layout overhead.

Documentation

📚 Full Documentation

Contributing

Contributions are welcome! To run the example project:

git clone https://github.com/mgcrea/react-native-swiftui.git
cd react-native-swiftui
pnpm install
pnpm run codegen:ios

cd example
pnpm install
pnpm run install:ios
pnpm run ios

Credits

Authors

MIT License

Copyright (c) 2025 Olivier Louvignes <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.