SwiftUI integration with Expo modules — native iOS views, bridging patterns, and module API
Expo Modules API is Swift-first. A Module subclass with a Definition() body exposes functions, constants, and views to JavaScript — no Objective-C bridging or .m files required.
Define the module, name it, and register any functions and views in definition(). The Name() call must match the string used in requireNativeModule() on the JS side.
Expo views subclass ExpoView (not UIView). To host a SwiftUI view, wrap it in a UIHostingController and add the hosting controller's view as a subview. Override layoutSubviews() to keep the hosted view's frame in sync with bounds.
Props are declared with Prop in the module Definition() and applied to the ExpoView subclass. Events use on the view class and are registered with in the definition. Fire them by calling the dispatcher with a plain dictionary payload.
@EventDispatcherEvents()Call any iOS SDK directly from the module or view. APIs requiring permissions need a config plugin that adds the NSUsageDescription key to Info.plist — never edit Info.plist manually since expo prebuild regenerates it.
ExpoView lifecycle: didMoveToWindow(), willMove(toSuperview:), and SwiftUI .onAppear / .onDisappear inside the hosted view. Module-level lifecycle uses OnCreate and OnDestroy in the definition body.
To push native UIKit screens from within a module, access the root view controller via appContext?.utilities?.currentViewController(). Avoid doing this in props — use a module function that JS calls explicitly.
See references/process.md for full Swift module code, UIHostingController setup, config plugin patterns, testing native modules, debugging on-device, and anti-patterns.