This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
Extending with SwiftUI
Learn how to create custom SwiftUI components and modifiers that integrate with Expo UI.
This guide explains how to use the Expo Modules API to create custom SwiftUI components and modifiers that integrate with Expo UI.
3 requirements
3 requirements
1.
@expo/ui installedInstall @expo/ui in your project. See SwiftUI components in Expo UI for more information.
2.
A custom Expo module contains native code, which Expo Go cannot load. Create a development build of your app.
3.
This guide assumes basic familiarity with the Expo Modules API and SwiftUI.
Creating a custom component
Project setup
1
Create a local Expo module in your project:
2
Add ExpoUI as a dependency in your module's podspec file:
Creating a SwiftUI view
3
Create your SwiftUI view with two parts:
- Props class: Extends
UIBaseViewPropsfromExpoUIto get automatic support for themodifiersprop - View struct: Conforms to the
ExpoSwiftUI.Viewprotocol, which requires an@ObservedObjectpropsproperty and abody
4
Register the view in your module using ExpoUIView. This wraps your SwiftUI view with modifier support and makes it available to JavaScript:
5
Create a wrapper component that connects modifiers with event handling. The createViewModifierEventListener utility enables event-based modifiers like onTapGesture and onAppear to work with your custom view:
6
Export the component from your module's entry point:
Using your custom component
Adding a native source file to a local module does not add it to the iOS project. Run
npx expo prebuildbefore you rebuild. Otherwise, the build fails withcannot find 'MyCustomView' in scope.
Your custom component now works with all built-in Expo UI modifiers:
Creating custom modifiers
You can also create custom modifiers that work with any Expo UI component.
Modifiers are SwiftUI's way to configure views for styling, layout, behavior, and more. Learn more in Apple's ViewModifier documentation.
Native modifier implementation
1
Create a modifier struct that conforms to ViewModifier and Record:
This adds a second native source file, so run
npx expo prebuildagain before you rebuild.
2
Register your modifier with ViewModifierRegistry in your module definition. To avoid race conditions with the SwiftUI render thread, call register in OnCreate and unregister in OnDestroy:
JavaScript modifier function
3
Create a TypeScript function that generates the modifier config:
4
Export the modifier from your module:
Using custom modifiers
Your custom modifier works with any Expo UI component:
Next steps
Your custom components now work with the built-in modifier system. From here you can:
- Use the built-in SwiftUI components that come with Expo UI
- Build custom modifiers for app-specific styling patterns
- Wrap third-party SwiftUI libraries for use in React Native
- Share your components as an npm package for others to use