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
Edit page
Learn how to create custom SwiftUI components and modifiers that integrate with Expo UI.
This guide explains how to create custom SwiftUI components and modifiers that integrate seamlessly with Expo UI.
3 requirements
3 requirements
1.
@expo/ui installedInstall @expo/ui in your project. See Building SwiftUI apps with Expo UI for more information.
2.
Expo UI is not available in Expo Go. Create a development build of your app.
3.
Basic familiarity with Expo Modules API and SwiftUI is recommended.
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
ExpoSwiftUI.Viewprotocol, which requires an@ObservedObjectprops property 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:
Using your custom component
Your custom component now works with all ExpoUI built-in 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:
2
Register your modifier with ViewModifierRegistry in your module definition. Use OnCreate to register and OnDestroy to unregister to avoid race conditions with the SwiftUI render thread:
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 ExpoUI component:
Next steps
Congratulations! You've learned how to extend Expo UI with custom SwiftUI components and modifiers. Your custom components now integrate seamlessly with the built-in modifier system.
Here are some ideas for what to build next:
- 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