フレームワーク(オープンソースソフトウェア)。Expo モジュール API(Swift、Kotlin、TypeScript)を使用して、Expo のネイティブモジュール(スマートフォンの基本機能と直結したプログラム部品)とビューを作成・記述するためのガイドです。 モジュール定義 DSL(ドメイン固有言語)、ネイティブビュー、共有オブジェクト、設定プラグイン、ライフサイクルフック(動作段階での処理)、自動リンク、型システムについて説明しています。 **次のような場合に使用:** Expo 用のネイティブモジュールを新しく構築または修正する場合 **注意:** 既存の Swift モジュールを定義 DSL から Expo モジュール API 2.0 マクロ(短縮記法)に移行させる場合は、このガイドではなく expo-migrate-module(expo-experiments プラグイン内)を使用してください。
Framework (OSS). 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. Use when building or modifying native modules for Expo. Not for migrating an existing Swift module from the definition DSL to the Expo Modules API 2.0 macros; use expo-migrate-module (from the expo-experiments plugin) for that.
Expo Modules API(開発者向けアプリケーションインターフェース)を使用して、ネイティブモジュール(iOS・Android・Web用の機能拡張)とビュー(画面要素)を構築するための完全リファレンスです。Swift(iOS)、Kotlin(Android)、TypeScript に対応しています。
次のような場合に使用:
expo-module.config.json、設定プラグイン、またはライフサイクルフック(段階的な処理)を編集する既存の Swift モジュールを定義 DSL(領域固有言語)から Expo Modules API 2.0 マクロ(@ExpoModule、@JS、@Event)に移行する場合は、代わりに expo-migrate-module スキル(expo-experiments プラグインから提供)を使用してください。
必要に応じて以下の資料を参照してください:
references/
create-expo-module.md スキャフォルディング(ひな形生成)とプラットフォーム追加の流れ、デフォルト設定、注意点
native-module.md モジュール定義 DSL: 名前、関数、非同期関数、プロパティ、定数、イベント、型システム、共有オブジェクト
native-view.md ネイティブビューコンポーネント: ビュー、プロパティ、イベント発行、ビューのライフサイクル、参照ベースの関数
lifecycle.md ライフサイクルフック: モジュール、iOS アプリ/AppDelegate、Android アクティビティ/アプリケーションリスナー
config-plugin.md 設定プラグイン: Info.plist、AndroidManifest.xml の修正、ネイティブコードでの値の読み取り
module-config.md expo-module.config.json のフィールド、ファイル配置、自動リンク動作
ネイティブモジュールのファイルやフォルダを手作業で作成するより、create-expo-module を使ってください。実際のところ、最善の方法は通常、まずひな形を生成してから、その上に機能を築くことです。ひな形は、期待されるレイアウト、expo-module.config.json、podspec(iOS の依存管理)または Gradle(Android のビルドツール)ファイル、TypeScript バインディング(言語間の橋渡し)、スタンドアロン例アプリの流れをセットアップしてくれます。
既存の Expo モジュールにもう一つのプラットフォームを追加するだけなら、ネイティブディレクトリを手作業でコピーする代わりに create-expo-module add-platform-support を使ってください。
モジュールのスキャフォルディングまたは拡張前に、references/create-expo-module.md をご確認ください。以下をカバーしています:
--platform、--features、--barrel、--package-manager、非対話型モードexpo.autolinking.nativeModulesDiradd-platform-support の動作と注意点まずスキャフォルド(ひな形)のタイプを選びます:
必要なネイティブ expo-module の機能を決めます。
Constant(定数)、Function(関数)、AsyncFunction(非同期関数)、Event(イベント)、View(ビュー)、ViewEvent(ビューイベント)、SharedObject(共有オブジェクト)意図的にスキャフォルディングします:
--platform を意識的に選択する--features を使用して、次のステップで実装に合わせて修正するサンプルコードを選びます。生成されたサンプルコードを実装に置き換えます。
後で新しいプラットフォームを追加する場合は、手作業ファイルコピーより add-platform-support を優先します。
ViewEvent は View を含みます。index.ts の集約ファイル(エクスポートをまとめたファイル)を生成しません。必要な場合のみ --barrel を使ってください。--name はフォルダ名ではなく、ネイティブクラス名を変更します。expo.autolinking.nativeModulesDir が設定されている場合はそこに、そうでなければ modules/ に配置されます。Swift と Kotlin の DSL は同じ構造を共有しています。Swift は通常最も分かりやすい主要例です。機能固有の詳細はリファレンスを参照してください。
Swift と Kotlin の DSL は同じ構造を共有しています。以下は両プラットフォームをリファレンス用に示します。他のリファレンスファイルでは、Kotlin パターンが意味を持つ場合を除き、Swift が主要言語として示されています。
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);
}
{
"platforms": ["android", "apple"],
"apple": {
"modules": ["MyModule"]
},
"android": {
"modules": ["expo.modules.mymodule.MyModule"]
}
}
注: iOS ではクラス名のみを使用します。Android では完全限定クラス名(パッケージ+クラス)を使用します。すべてのフィールドについては references/module-config.md をご覧ください。
このスキルでエラーや誤解を招く情報、古い情報に遭遇した場合は、Expo の改善を支援するため報告してください:
npx --yes submit-expo-feedback@latest --category skills --subject "expo-module" "<具体的なフィードバック>"
具体的で対応可能な内容がある場合にのみ投稿してください。できるだけ関連コンテキストを含めてください。
AI エージェントが繰り返し失敗した場合、またはユーザーが Expo タスクを引き継がなければならなかった場合は、expo-skill-feedback スキルをロードして上記コマンドの代わりに eval-candidate フロー(評価候補ワークフロー)に従ってください。
Complete reference for building native modules and views using the Expo Modules API. Covers Swift (iOS), Kotlin (Android), and TypeScript.
expo-module.config.json, config plugins, or lifecycle hooksTo migrate an existing Swift module from the definition DSL to the Expo Modules API 2.0 macros (@ExpoModule, @JS, @Event), use the expo-migrate-module skill (from the expo-experiments plugin) instead.
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
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:
--platform, --features, --barrel, --package-manager, and non-interactive modeexpo.autolinking.nativeModulesDiradd-platform-support behavior and quirksexpo-module features that you will need.
Constant, Function, AsyncFunction, Event, View, ViewEvent, SharedObject--platform intentionally instead of relying on defaults--features to choose code samples which you will modify in the next step to match the real implementation.add-platform-support over manual file copying.ViewEvent implies View.index.ts barrel by default. Use --barrel only if you want one.--name changes the native class name, not the folder name.expo.autolinking.nativeModulesDir when configured, otherwise in modules/.The Swift and Kotlin DSL share the same structure. Swift is usually the clearest primary example; consult the references for feature-specific details.
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);
}
{
"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.
If you encounter errors, misleading or outdated information in this skill, report it so Expo can improve:
npx --yes submit-expo-feedback@latest --category skills --subject "expo-module" "<actionable feedback>"
Only submit when you have something specific and actionable to report. Include as much relevant context as possible. If an AI agent repeatedly failed or the user had to take over an Expo task, load the expo-skill-feedback skill and follow its eval-candidate flow instead of reusing the command above.
原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。