Expo Module
OpenAIOfficialCreated by Expo TeamDistributed by OpenAI
- Skill
- Tool integration
- Software development
- MIT
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a complete reference for building native modules and views in Expo using Swift for iOS, Kotlin for Android, and TypeScript for the JavaScript interface. It covers the essential aspects of the Expo Modules API, including module definition DSL, native view components, lifecycle hooks, and configuration plugins. It also provides guidance on scaffolding new modules, managing native project files, and handling platform-specific requirements through autolinking.
What it does
- Provides a DSL for defining native modules and views in Swift and Kotlin.
- Explains how to scaffold new native modules using the create-expo-module tool.
- Details the implementation of native view components and their lifecycle.
- Covers the creation of config plugins to modify native project files like Info.plist and AndroidManifest.xml.
- Outlines lifecycle hooks for modules, iOS AppDelegate, and Android Activity/Application events.
- Describes how to configure autolinking and module registration.
When to use it
- When you need to create a new native module or native view for an Expo project.
- When you need to integrate platform-specific SDKs into a React Native environment.
- When you need to access native system APIs like camera or sensors.
- When you need to build config plugins to automate native project configuration.
Advantages
- Provides a unified approach to native development across iOS and Android.
- Includes standardized scaffolding to prevent common build errors.
- Offers clear patterns for bridging native code to TypeScript.
- Simplifies native project configuration through automated plugins.
Usage examples
- “How do I scaffold a new local Expo native module?”
- Use the command 'CI=1 npx create-expo-module@latest --local --name MyModule' to generate the necessary file structure for a local module.
- “How can I modify the AndroidManifest.xml using a config plugin?”
- Create a plugin function using 'withAndroidManifest' from 'expo/config-plugins' to programmatically add metadata or modify manifest entries.
- “Where do I define module functions in Swift?”
- Inside the 'definition()' method of your class inheriting from 'Module', use the 'Function' or 'AsyncFunction' blocks.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/openai/expo-module/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip expo-module.zip -d .agents/skills
Documentation by Expo Team
Writing Expo Modules
Complete reference for building native modules and views using the Expo Modules API. Covers Swift (iOS), Kotlin (Android), and TypeScript.
When to Use
Creating a new Expo native module or native view
Adding native functionality (camera, sensors, system APIs) to an Expo app
Wrapping platform SDKs for React Native consumption
Building config plugins that modify native project files
References
Consult these resources as needed:
references/
native-module.md Module definition DSL: Name, Function, AsyncFunction, Property, Constant, Events, type system, shared objects
native-view.md Native view components: View, Prop, EventDispatcher, view lifecycle, ref-based functions
lifecycle.md Lifecycle hooks: module, iOS app/AppDelegate, Android activity/application listeners
config-plugin.md Config plugins: modifying Info.plist, AndroidManifest.xml, reading values in native code
module-config.md expo-module.config.json fields and autolinking configurationQuick Start
Create a Local Module (in existing app)
Always scaffold with create-expo-module first, then modify the generated code. This ensures correct podspec, build.gradle, and module config — avoiding common build errors.
CI=1 npx create-expo-module@latest --local \
--name MyModule \
--description "My Expo module" \
--package expo.modules.mymoduleCI=1 skips interactive prompts and uses the provided flags.
Important: In
CI=1(non-interactive) mode, the scaffold always creates the directory asmodules/my-module/because the slug is derived fromcustomTargetPathwhich isundefinedfor--localmodules — the--nameflag only sets the native class name, not the directory. After scaffolding, rename it to a kebab-case name matching your module (e.g.,KeyValueStore→modules/key-value-store/), then runcd ios && pod installso CocoaPods picks up the correct path. Skipping the rename is fine functionally, but skippingpod installafter any rename causes iOS build failures ("Build input file cannot be found").
Available flags:
| Flag | Description | Example |
|---|---|---|
--name | Native module name (PascalCase) | --name KeyValueStore |
--description | Module description | --description "Native key-value storage" |
--package | Android package name | --package expo.modules.keyvaluestore |
--author-name | Author name | --author-name "dev" |
--author-email | Author email | --author-email "[email protected]" |
--author-url | Author profile URL | --author-url "https://github.com/dev" |
--repo | Repository URL | --repo "https://github.com/dev/repo" |
The scaffold generates both a native module (functions, events, constants) and a native view component (WebView example with props and events). After scaffolding:
Decide what you need: If you only need a native module (no UI), remove the view files. If you only need a native view, remove the module function boilerplate. If you need both, keep both and replace the implementations.
Remove unnecessary boilerplate: The scaffold includes example code (
hello()function,PIconstant,onChangeevent, WebView-based view withurlprop). Strip all of this and replace with your actual implementation.Remove web files if not needed: The scaffold generates
*.web.ts/*.web.tsxfiles for web platform support. Remove these if the module is native-only. Also remove"web"from theplatformsarray inexpo-module.config.json.
What to remove for a module-only (no native view):
Delete
ios/MyModuleView.swift,android/.../MyModuleView.ktDelete
src/MyModuleView.tsx,src/MyModuleView.web.tsxRemove the
View(...)block from the module definition in both Swift and KotlinRemove view-related types from
MyModule.types.tsand view export fromindex.ts
What to remove for a view-only (no module functions):
Remove
Function,AsyncFunction,Constant,Eventsblocks from the module definition (keepNameandView)Simplify the TypeScript module file to only export the view
Generated structure (after renaming from my-module to your module's kebab-case name):
modules/
my-module/ # Rename to kebab-case, e.g. key-value-store/
android/
build.gradle
src/main/java/expo/modules/mymodule/
MyModule.kt # Module definition (functions, events, view registration)
MyModuleView.kt # Native view (ExpoView subclass)
ios/
MyModule.podspec
MyModule.swift # Module definition
MyModuleView.swift # Native view (ExpoView subclass)
src/
MyModule.ts # Native module binding
MyModule.web.ts # Web implementation
MyModule.types.ts # Shared types
MyModuleView.tsx # Native view component
MyModuleView.web.tsx # Web view component
expo-module.config.json
index.ts # Re-exports module + viewCreate a Standalone Module (for publishing)
npx create-expo-module@latest my-moduleModule Structure Reference
The Swift and Kotlin DSL share the same structure. Both platforms are shown here for reference — in other reference files, Swift is shown as the primary language unless the Kotlin pattern meaningfully differs.
Swift (iOS):
import ExpoModulesCore
public class MyModule: Module {
public func definition() -> ModuleDefinition {
Name("MyModule")
Function("hello") { (name: String) -> String in
return "Hello \(name)!"
}
}
}Kotlin (Android):
package expo.modules.mymodule
import expo.modules.kotlin.modules.Module
import expo.modules.kotlin.modules.ModuleDefinition
class MyModule : Module() {
override fun definition() = ModuleDefinition {
Name("MyModule")
Function("hello") { name: String ->
"Hello $name!"
}
}
}TypeScript:
import { requireNativeModule } from "expo";
const MyModule = requireNativeModule("MyModule");
export function hello(name: string): string {
return MyModule.hello(name);
}expo-module.config.json
{
"platforms": ["android", "apple"],
"apple": {
"modules": ["MyModule"]
},
"android": {
"modules": ["expo.modules.mymodule.MyModule"]
}
}Note: iOS uses just the class name; Android uses the fully-qualified class name (package + class). See references/module-config.md for all fields.
Files
- ATTRIBUTION.mdAdded by AutoGineer812 B
- LICENSELicence file added by AutoGineer1.1 KiB
- SKILL.md6.8 KiB
- agents/openai.yaml367 B
- references/config-plugin.md2.0 KiB
- references/lifecycle.md3.7 KiB
- references/module-config.md1.1 KiB
- references/native-module.md5.7 KiB
- references/native-view.md3.5 KiB
references/native-module.md
Native Module DSL Reference
Swift is shown as the primary language. Kotlin follows the same DSL structure (see SKILL.md for both). Kotlin-specific syntax is noted where it meaningfully differs.
Name
Sets the module identifier used in JavaScript.
Name("MyModule")Constant
Computed once on first access, then cached.
Constant("PI") { 3.14159 }Function (Synchronous)
Blocks the JS thread until completion. Supports up to 8 arguments.
Function("add") { (a: Int, b: Int) -> Int in
return a + b
}AsyncFunction
Returns a Promise. Runs on a background thread by default.
AsyncFunction("fetchData") { (url: URL) -> String in
let data = try Data(contentsOf: url)
return String(data: data, encoding: .utf8) ?? ""
}
// Force main queue execution
AsyncFunction("updateUI") { () -> Void in
// UI work
}.runOnQueue(.main)Kotlin differences:
// Supports Kotlin coroutines
AsyncFunction("fetchData") Coroutine { url: java.net.URL ->
withContext(Dispatchers.IO) {
url.readText()
}
}Property
Getter/setter for JS object properties.
// Read-only
Property("version") { "1.0.0" }
// Read-write
Property("volume")
.get { () -> Float in self.volume }
.set { (newValue: Float) in self.volume = newValue }Events
Declares events the module can send to JS. Must be declared before using sendEvent.
// Declaration
Events("onChange", "onError")
// Sending from native (Swift)
sendEvent("onChange", ["value": newValue])Kotlin difference — uses bundleOf:
sendEvent("onChange", bundleOf("value" to newValue))JS subscription:
import { useEvent } from "expo";
import MyModule from "./MyModule";
// Hook-based (recommended)
const event = useEvent(MyModule, "onChange");
// Manual subscription
const subscription = MyModule.addListener("onChange", (event) => {
console.log(event.value);
});
// Clean up: subscription.remove()OnStartObserving / OnStopObserving
Called when the first listener attaches / last listener detaches. Can be scoped to specific events.
OnStartObserving("onChange") {
// Start producing events
}
OnStopObserving("onChange") {
// Stop producing events
}Type System
Primitives
| Swift | Kotlin | JS |
|---|---|---|
Bool | Boolean | boolean |
Int, Int32 | Int | number |
Int64 | Long | number |
Float, Float32 | Float | number |
Double | Double | number |
String | String | string |
URL | java.net.URL / android.net.Uri | string |
CGPoint | - | { x, y } |
CGSize | - | { width, height } |
CGRect | - | { x, y, width, height } |
UIColor / CGColor | android.graphics.Color | string (ProcessedColorValue) |
Data | kotlin.ByteArray | Uint8Array |
Records (Struct-like types)
struct UserRecord: Record {
@Field var name: String = ""
@Field var age: Int = 0
@Field var email: String?
}
Function("createUser") { (user: UserRecord) -> Bool in
return true
}Kotlin difference — uses class instead of struct, optional fields need explicit = null:
class UserRecord : Record {
@Field var name: String = ""
@Field var age: Int = 0
@Field var email: String? = null
}Enums (Enumerable)
enum Theme: String, Enumerable {
case light
case dark
case system
}
Function("setTheme") { (theme: Theme) in
// type-safe enum value
}Kotlin difference — uses enum class with explicit value property:
enum class Theme(val value: String) : Enumerable {
LIGHT("light"),
DARK("dark"),
SYSTEM("system")
}Either Types (Union types)
Function("process") { (input: Either<String, Int>) in
if let str = input.get(String.self) {
// handle string
} else if let num = input.get(Int.self) {
// handle number
}
}Also available: EitherOfThree<A, B, C>, EitherOfFour<A, B, C, D>.
JavaScript Values (Direct JS manipulation)
For advanced use in synchronous functions running on JS thread:
Function("callback") { (fn: JavaScriptFunction<String>) in
let result = fn("arg1", "arg2")
}Shared Objects
Bridge native class instances to JS with automatic lifecycle management. Instances are deallocated when neither JS nor native code holds a reference.
Defining a Shared Object
class ImageContext: SharedObject {
private var image: UIImage
init(image: UIImage) {
self.image = image
super.init()
}
func rotate(degrees: Double) {
image = image.rotated(degrees: degrees)
}
}Kotlin difference — takes RuntimeContext in constructor, override sharedObjectDidRelease() for cleanup:
class ImageContext(
runtimeContext: RuntimeContext,
private var bitmap: Bitmap
) : SharedObject(runtimeContext) {
fun rotate(degrees: Float) { /* ... */ }
override fun sharedObjectDidRelease() {
if (!bitmap.isRecycled) bitmap.recycle()
}
}Exposing via Class DSL
Class("Context", ImageContext.self) {
Constructor { (path: String) -> ImageContext in
return ImageContext(image: UIImage(contentsOfFile: path)!)
}
Function("rotate") { (ctx: ImageContext, degrees: Double) -> ImageContext in
ctx.rotate(degrees: degrees)
return ctx
}
Property("width")
.get { (ctx: ImageContext) -> Int in ctx.width }
}Other Class DSL components: StaticFunction, StaticAsyncFunction, AsyncFunction.
SharedRef
Specialized shared reference for passing typed objects between modules:
final class ImageRef: SharedRef<UIImage> {}JS Usage
const ctx = await ImageModule.create("/path/to/image.png");
ctx.rotate(90);
console.log(ctx.width);Requirements and compatibility
Written for: OpenAI Codex
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs Node.js
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- Expo Team
- Publisher
- OpenAI (Official)
- Distributed by
- OpenAI
- Source
- openai/plugins · plugins/expo/skills/expo-module · commit d420d13
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from plugins/expo/LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Expo Team or OpenAI.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download expo-module.zip