expo-module
它能做什么
这是一份指南,帮助你为 Expo 应用创建和编写“原生模块”(native modules)与“原生视图”(native views)。它使用一种名为 Expo Modules API 的专用接口,将 Swift(iOS)、Kotlin(Android)和 TypeScript 代码连接起来。
适用场景
- ✓当你需要为 Expo 应用添加现有功能中没有的新功能时。
- ✓当你需要集成没有直接 React Native 支持的平台 SDK(例如相机或传感器)时。
- ✓当你想创建在 iOS 和 Android 上都能运行的自定义视觉组件时。
技能链接
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/expo-module/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我该如何使用 Expo Modules API 为我的 Expo 应用创建一个新的原生模块?”
每周 5 个新技能,1 分钟读完。
工作原理
你可以使用 `create-expo-module` 命令生成模块的基本结构。然后,编辑生成的 Swift(iOS)和 Kotlin(Android)文件来定义功能,并使用 TypeScript 编写 JavaScript 部分。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
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
- Adding Android, Apple, or web support to an existing Expo module
- Editing
expo-module.config.json, config plugins, or lifecycle hooks
References
Consult these resources as needed:
references/
create-expo-module.md Scaffolding and add-platform-support workflow, defaults, and quirks
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, file placement, and autolinking behavior
Quick Start
Prefer create-expo-module over manually creating native module files and directories. In practice, the best path is usually to create the scaffold first and then build on top of it. The scaffold sets up the expected layout, expo-module.config.json, podspec or Gradle files, TypeScript bindings, and the standalone example app flow.
If an existing Expo module only needs another platform, use create-expo-module add-platform-support instead of manually copying native directories.
See references/create-expo-module.md before scaffolding or extending a module. It covers:
- local vs standalone modules
--platform,--features,--barrel,--package-manager, and non-interactive modeexpo.autolinking.nativeModulesDiradd-platform-supportbehavior and quirks
Recommended Workflow
- Choose the scaffold type first:
- Local module for one app
- Standalone module for reuse, monorepos, or publishing
- Determine native
expo-modulefeatures that you will need.- Based on the user's instructions determine which feature scaffolding will be useful.
- Available features:
Constant,Function,AsyncFunction,Event,View,ViewEvent,SharedObject
- Scaffold deliberately:
- pass an explicit slug or path
- choose
--platformintentionally instead of relying on defaults - use
--featuresto choose code samples which you will modify in the next step to match the real implementation.
- Replace generated example code with the real implementation.
- If you add a new platform later, prefer
add-platform-supportover manual file copying.
Practical Scaffolding Rules
- Feature examples are opt-in. A newly scaffolded module may be minimal if no features were selected.
ViewEventimpliesView.- Local modules do not generate an
index.tsbarrel by default. Use--barrelonly if you want one. - In non-interactive local scaffolding, pass the positional slug or path explicitly.
--namechanges the native class name, not the folder name. - Local modules live in
expo.autolinking.nativeModulesDirwhen configured, otherwise inmodules/. - Standalone modules have their own package metadata, scripts, and usually an example app. Local modules use the host app's tooling instead.
Core File Shapes
The Swift and Kotlin DSL share the same structure. Swift is usually the clearest primary example; consult the references for feature-specific details.
Module 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() {
…
常见问题
什么是“原生模块”和“原生视图”?
原生模块是直接在手机系统(iOS 或 Android)上运行的代码,你可以在 JavaScript 代码中调用它。原生视图则是同样用原生代码创建的视觉组件,比如按钮或列表。
使用这个功能需要懂 Swift 和 Kotlin 吗?
需要。你需要用 Swift 为 iOS 编写代码,用 Kotlin 为 Android 编写代码,来实现原生模块的逻辑。指南会讲解如何使用 Expo Modules API 来完成这些工作。
什么是“配置插件”(config plugins)?
配置插件是一项功能,可以在构建应用时自动修改项目的原生配置文件,比如 Android 上的 `AndroidManifest.xml` 或 iOS 上的 `Info.plist`。
详情
作者的原始描述
Guide for creating and writing Expo native modules and views using the Expo Modules API (Swift, Kotlin, TypeScript). Covers module definition DSL, native views, shared objects, config plugins, lifecycle hooks, autolinking, and type system.
热度
- GitHub 星标
- 48k
- 排名
- #4575
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
00-andruia-consultant
48k帮你的智能体启动或改进 AI 项目。它可以分析代码、推荐工具,并用西班牙语制定行动计划。
007
48k让你的智能体执行安全审计和威胁建模。它有助于保护项目免受攻击和漏洞的威胁。
10-andruia-skill-smith
48k帮你的智能体创建或改进 AI 工具。它可以定义工具的工作方式、编写文档,并验证其结构。
20-andruia-niche-intelligence
48k让你的智能体创建某个特定行业的摘要。它有助于借助可靠的信息来源,了解项目的背景、规则、使用模式和风险。