Skip to content

Components Overview

React Native SwiftUI provides a comprehensive set of components that render native SwiftUI views. This page explains the architecture and patterns used throughout the library.

All SwiftUI components must be wrapped in a SwiftUI root container:

import { SwiftUI } from '@mgcrea/react-native-swiftui';
import { View } from 'react-native';
<View style={{ flex: 1 }}>
<SwiftUI style={{ flex: 1 }}>
{/* Components here */}
</SwiftUI>
</View>

The root component:

  • Creates a bridge between React and native SwiftUI
  • Manages the component tree and event handling
  • Renders all descendant components natively

When you use a SwiftUI component, it doesn’t render a React Native view. Instead, it:

  1. Registers itself in a virtual tree
  2. Returns null from the render function
  3. The native side reads this tree and renders actual SwiftUI views

This means you cannot inspect SwiftUI components in React DevTools, but they will appear in Xcode’s view debugger.

Input components for building forms:

ComponentDescription
TextFieldText input field
NumberFieldNumeric input with formatting
ToggleBoolean switch
SliderRange value selector
StepperIncrement/decrement control
DatePickerDate and time selection
PickerSingle value selection
MultiPickerMulti-column picker

Components for displaying content:

ComponentDescription
TextText display
ImageImage display
ButtonTappable button

Components for organizing content:

ComponentDescription
FormForm container with iOS styling
SectionGrouped content with header/footer
SheetModal sheet presentation
SheetPickerSearchable picker in a sheet

See the Layout section for:

  • HStack, VStack, ZStack
  • LazyVGrid
  • Spacer, Group, Rectangle

All interactive components follow a controlled component pattern:

const [value, setValue] = useState('');
<SwiftUI.TextField
text={value}
onChange={setValue}
/>

Events are passed as callback props:

<SwiftUI.Button
title="Submit"
onPress={() => handleSubmit()}
/>
<SwiftUI.TextField
text={value}
onChange={(newValue) => setValue(newValue)}
onFocus={() => console.log('Focused')}
onBlur={() => console.log('Blurred')}
/>

Components accept a style prop for customization:

<SwiftUI.Text
text="Styled text"
style={{
color: 'blue',
fontSize: 18,
fontWeight: 'bold',
}}
/>

See the Styling Guide for details on available style properties.

You cannot place React Native views inside the SwiftUI tree:

// ❌ Won't work
<SwiftUI style={{ flex: 1 }}>
<View> {/* Regular RN View inside SwiftUI */}
<SwiftUI.Text text="Hello" />
</View>
</SwiftUI>
// ✅ Correct
<SwiftUI style={{ flex: 1 }}>
<SwiftUI.VStack>
<SwiftUI.Text text="Hello" />
</SwiftUI.VStack>
</SwiftUI>

SwiftUI components only render on iOS. For cross-platform apps, you’ll need platform-specific code:

import { Platform } from 'react-native';
{Platform.OS === 'ios' ? (
<SwiftUI style={{ flex: 1 }}>
<SwiftUI.Form>...</SwiftUI.Form>
</SwiftUI>
) : (
<AndroidForm />
)}