expo-modules
Skill8 starsChanged 3 months agoMITView on GitHub
Writing Swift/Kotlin native modules with the Expo Modules API, requireNativeModule, async functions, view modules, and the event-emitter pattern. Triggers on expo modules, native module, swift, kotlin, requireNativeModule, expo-module-scripts, expo.modules.json, view module, event emitter, native function, async function, native code, jsi.
In this repository63 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- ai-automationSkill
- consultingSkill
- contentSkill
- customer-successSkill
- data-analyticsSkill
- designSkill
- design-tokensSkill
- developmentSkill
- devopsSkill
- ecommerceSkill
- emailSkill
- expo-app-configSkill
- expo-config-pluginSkill
- expo-dev-clientSkill
- expo-eas-buildSkill
- expo-eas-submitSkill
- expo-eas-updateSkill
- expo-notificationsSkill
- expo-orchestratorSkill
- expo-prebuildSkill
- expo-routerSkill
- expo-troubleshootingSkill
- financeSkill
- frontend-tasteSkill
- marketingSkill
- market-researchSkill
- mobileSkill
- pentest-adSkill
- pentest-apiSkill
- pentest-bizlogicSkill
- pentest-bugbountySkill
- pentest-cicdSkill
- pentest-cloudSkill
- pentest-credentialsSkill
- pentest-ctfSkill
- pentest-detectionSkill
- pentest-engagementSkill
- pentest-exploit-chainSkill
- pentest-forensicsSkill
- pentest-llmSkill
- pentest-malwareSkill
- pentest-mobileSkill
- pentest-opsec-evidenceSkill
- pentest-orchestratorSkill
- pentest-privescSkill
- pentest-reconSkill
- pentest-reportSkill
- pentest-socialSkill
- pentest-stigSkill
- pentest-threat-modelSkill
- pentest-webSkill
- pentest-wirelessSkill
- productivitySkill
- productSkill
- salesSkill
- security-checkSkill
- securitySkill
- seo-crawl-budgetSkill
- seoSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 280
Start with a local module.
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
expo-modules
A guide to writing native modules in Swift (iOS) and Kotlin (Android) with the Expo Modules API. Function/view/event module structure, async definitions, autolinking, and TypeScript-binding discipline.
What It Does
- Creating a new module with
create-expo-module - Swift
Moduleand KotlinModuleclass structure Function,AsyncFunction,Property,Events,Viewdefinitions- TypeScript bindings and
requireNativeModuleusage - Local module (inside the project) vs publishable package
- Event emitter pattern
Creating a New Module
# New package (publishable to npm)
npx create-expo-module my-native-module
cd my-native-module
npm run build
npm run open:ios # open in Xcode
npm run open:android # open in Android Studio
# Local module (this project only)
npx create-expo-module@latest --local my-feature
# Creates it under modules/my-feature/Directory Structure
my-native-module/
android/
src/main/java/expo/modules/mynativemodule/
MyNativeModuleModule.kt
ios/
MyNativeModuleModule.swift
src/
index.ts # TypeScript binding
MyNativeModule.types.ts
MyNativeModuleModule.ts
MyNativeModuleView.tsx
expo-module.config.json
package.jsoniOS — Swift Module
// ios/MyNativeModuleModule.swift
import ExpoModulesCore
public class MyNativeModuleModule: Module {
public func definition() -> ModuleDefinition {
Name("MyNativeModule")
Constants([
"PI": Double.pi
])
Function("hello") {
return "Hello from Swift"
}
AsyncFunction("setValueAsync") { (value: String) in
UserDefaults.standard.set(value, forKey: "myValue")
}
AsyncFunction("getValueAsync") { () -> String? in
return UserDefaults.standard.string(forKey: "myValue")
}
Events("onChange")
OnStartObserving {
// when a listener is added
}
OnStopObserving {
// when a listener is removed
}
View(MyNativeModuleView.self) {
Prop("url") { (view: MyNativeModuleView, url: URL) in
view.url = url
}
Events("onLoad")
}
}
}Android — Kotlin Module
// android/src/main/java/expo/modules/mynativemodule/MyNativeModuleModule.kt
package expo.modules.mynativemodule
import expo.modules.kotlin.modules.Module
import expo.modules.kotlin.modules.ModuleDefinition
class MyNativeModuleModule : Module() {
override fun definition() = ModuleDefinition {
Name("MyNativeModule")
Constants(
"PI" to Math.PI
)
Function("hello") {
"Hello from Kotlin"
}
AsyncFunction("setValueAsync") { value: String ->
val prefs = appContext.reactContext?.getSharedPreferences("my", 0)
prefs?.edit()?.putString("myValue", value)?.apply()
}
AsyncFunction("getValueAsync") {
val prefs = appContext.reactContext?.getSharedPreferences("my", 0)
prefs?.getString("myValue", null)
}
Events("onChange")
View(MyNativeModuleView::class) {
Prop("url") { view: MyNativeModuleView, url: String ->
view.setUrl(url)
}
Events("onLoad")
}
}
}TypeScript Binding
// src/MyNativeModule.ts
import { requireNativeModule } from "expo-modules-core";
const NativeModule = requireNativeModule("MyNativeModule");
export default NativeModule;// src/index.ts
import { EventEmitter, Subscription } from "expo-modules-core";
import MyNativeModule from "./MyNativeModule";
export const PI: number = MyNativeModule.PI;
export function hello(): string {
return MyNativeModule.hello();
}
export async function setValueAsync(value: string): Promise<void> {
return await MyNativeModule.setValueAsync(value);
}
export async function getValueAsync(): Promise<string | null> {
return await MyNativeModule.getValueAsync();
}
const emitter = new EventEmitter(MyNativeModule);
export function addChangeListener(
listener: (event: { value: string }) => void
): Subscription {
return emitter.addListener("onChange", listener);
}
export { default as MyNativeModuleView } from "./MyNativeModuleView";View Module (Native UI)
// src/MyNativeModuleView.tsx
import { requireNativeViewManager } from "expo-modules-core";
import * as React from "react";
import { ViewProps } from "react-native";
type Props = { url: string; onLoad?: (e: { nativeEvent: { url: string } }) => void } & ViewProps;
const NativeView = requireNativeViewManager("MyNativeModule");
export default function MyNativeModuleView(props: Props) {
return <NativeView {...props} />;
}expo-module.config.json
{
"platforms": ["ios", "android"],
"ios": {
"modules": ["MyNativeModuleModule"]
},
"android": {
"modules": ["expo.modules.mynativemodule.MyNativeModuleModule"]
}
}Using a Local Module
app.json (automatic autolinking for the local module):
{
"expo": {
"autolinking": {
"nativeModulesDir": "./modules"
}
}
}Then prebuild:
npx expo prebuild --cleanFunction Types
| Type | Synchronous? | Usage |
Function | Synchronous | Fast getter, constant |
AsyncFunction | Async | I/O, network, background work |
Constants | Build-time | Static value |
Property | Getter/setter | View instance |
Events | Async event | onChange, onLoad |
Async Function Example (file I/O)
AsyncFunction("readFileAsync") { (uri: URL) -> String in
return try String(contentsOf: uri, encoding: .utf8)
}AsyncFunction("readFileAsync") { uri: String ->
java.io.File(uri).readText()
}Event Emit
sendEvent("onChange", ["value": newValue])sendEvent("onChange", mapOf("value" to newValue))Best Practices
- AsyncFunction for network/disk work — don't use Function
- Type strict parameters:
URL,Data, custom struct - Check permissions inside the module (warn the user)
- Clean up listeners with OnStartObserving / OnStopObserving (memory leak)
- Start with a local module; extract to a package if needed
- Mind Kotlin null-safety and Swift optionals — JS undefined mapping
Common Failure Patterns
Name("X")written DIFFERENTLY in Swift and Kotlin → JSrequireNativeModule("X")can't find itFunctioninstead ofAsyncFunction→ main thread block, ANR- Listener not removed → memory leak
- View prop type mismatch (Swift
URLbut JS string) → crash - Adding a module without running
prebuild→ autolink can't find it
Hard Refusal
- A module that uses private iOS APIs (Apple reject)
- A native module that reads the microphone/camera/location without user permission
- Native code for root/jailbreak bypass
- Dumping the contents of the user's keychain/keystore without permission
Output Format
- Module skeleton (Swift + Kotlin)
- TypeScript binding
expo-module.config.json- Prebuild + run command
- Function/Event type selection rationale
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

