expo-module

bởi expo

Hướng dẫn tạo và viết các mô-đun gốc và chế độ xem của Expo bằng Expo Modules API (Swift, Kotlin, TypeScript). Bao gồm DSL định nghĩa mô-đun, gốc…

npx skills add https://github.com/expo/skills --skill expo-module

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 mode
  • expo.autolinking.nativeModulesDir
  • add-platform-support behavior and quirks

Recommended Workflow

  1. Choose the scaffold type first:
    • Local module for one app
    • Standalone module for reuse, monorepos, or publishing
  2. Determine native expo-module features 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
  3. Scaffold deliberately:
    • pass an explicit slug or path
    • choose --platform intentionally instead of relying on defaults
    • use --features to choose code samples which you will modify in the next step to match the real implementation.
  4. Replace generated example code with the real implementation.
  5. If you add a new platform later, prefer add-platform-support over manual file copying.

Practical Scaffolding Rules

  • Feature examples are opt-in. A newly scaffolded module may be minimal if no features were selected.
  • ViewEvent implies View.
  • Local modules do not generate an index.ts barrel by default. Use --barrel only if you want one.
  • In non-interactive local scaffolding, pass the positional slug or path explicitly. --name changes the native class name, not the folder name.
  • Local modules live in expo.autolinking.nativeModulesDir when configured, otherwise in modules/.
  • 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() {
  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.

Thêm skills từ expo

android-e2e-testing
expo
Kiểm tra các tính năng Expo Router trên trình giả lập Android bằng ADB. Sử dụng sau khi triển khai các tính năng Android gốc hoặc khi xác minh hành vi giao diện người dùng trên Android.
official
deep-code-review
expo
Đánh giá mã chuyên sâu tập trung vào thiết kế - hiểu ngữ cảnh mã nguồn trước khi đánh giá các thay đổi trong PR, đăng phản hồi có cấu trúc lên GitHub
official
building-native-ui
expo
Hướng dẫn đầy đủ để xây dựng ứng dụng Expo gốc với routing, tạo kiểu, component và quy ước nền tảng. Bao gồm các kiến thức cơ bản về Expo Router, tab gốc, stack navigation, modal và form sheet với quy ước cấu trúc route chi tiết. Bao gồm các quy tắc tạo kiểu tuân theo Nguyên tắc Giao diện Người dùng Apple: bố cục flexbox, xử lý vùng an toàn, hoạt ảnh, đổ bóng qua CSS boxShadow và các mẫu thiết kế đáp ứng. Ghi lại các tùy chọn thư viện (expo-image cho SF Symbols, expo-audio, expo-video,...)
official
eas-update-insights
expo
Kiểm tra tình trạng của các bản cập nhật EAS đã phát hành: tỷ lệ sập, số lần cài đặt/khởi chạy, người dùng duy nhất, kích thước tải trọng và sự phân chia giữa người dùng nhúng và OTA theo…
official
expo-api-routes
expo
Các route API trong Expo Router dành cho logic phía máy chủ, bí mật và tích hợp bên thứ ba trên EAS Hosting. Tạo route với hậu tố +api.ts trong thư mục app; xuất các hàm có tên cho các phương thức HTTP (GET, POST, PUT, DELETE). Xử lý tham số truy vấn, header, nội dung JSON và các đoạn route động; thêm header CORS cho client web. Truy cập bí mật phía máy chủ qua process.env; đặt biến cục bộ trong .env hoặc qua eas env:create cho môi trường production. Triển khai lên EAS Hosting (Cloudflare Workers) với eas...
official
expo-cicd-workflows
expo
Viết và xác thực các tệp YAML quy trình CI/CD EAS cho các dự án Expo. Tải lược đồ JSON mới nhất từ API của Expo để đảm bảo các loại công việc, tham số, trình kích hoạt và cấu hình runner luôn cập nhật. Hỗ trợ biểu thức động sử dụng cú pháp ${{ }} với các ngữ cảnh cho sự kiện GitHub, đầu vào quy trình, đầu ra công việc và kết quả bước. Bao gồm tập lệnh xác thực tích hợp kiểm tra cấu trúc quy trình so với lược đồ và báo cáo lỗi trước khi triển khai. Cung cấp tài liệu tham khảo về cú pháp,...
official
expo-deployment
expo
Triển khai tự động các ứng dụng Expo lên iOS App Store, Android Play Store, web hosting và môi trường xem trước. Hỗ trợ xây dựng và gửi bản production cho iOS (App Store và TestFlight) và Android (Google Play Store) chỉ với một lệnh duy nhất. Bao gồm EAS Hosting cho triển khai web với URL xem trước PR tự động và hỗ trợ tên miền production. Cung cấp tự động hóa quy trình CI/CD qua EAS Workflows cho các bản build và gửi được kích hoạt khi có push mã. Quản lý phiên bản tự động với từ xa...
official
expo-dev-client
expo
Xây dựng các bản phát triển Expo tùy chỉnh để kiểm tra mã gốc trên thiết bị vật lý qua EAS Build hoặc cục bộ. Chỉ cần thiết khi sử dụng các mô-đun gốc tùy chỉnh, mục tiêu Apple (widget, app clips) hoặc mã gốc của bên thứ ba không có trong Expo Go; hãy thử Expo Go trước với lệnh npx expo start. Hỗ trợ xây dựng đám mây với tính năng tự động gửi lên TestFlight hoặc xây dựng cục bộ trên máy của bạn, xuất ra tệp .ipa (iOS) hoặc .apk / .aab (Android). Yêu cầu cấu hình eas.json với một hồ sơ phát triển thiết lập...
official