Writing Native Modules with Expo Modules

Call Kotlin and Swift code from JavaScript when no library exists, using the Expo Modules API.

Advanced · about 8 hours · difficulty 4/5

Learn first: The Expo Workflow: Dev Builds, Config & Environments, React Native Internals & the New Architecture

Sooner or later you need a platform API that no library exposes well: a vendor SDK, a special sensor, a system setting. Instead of forking a stale package, you can write a small native module.

Expo Modules API

Create a module with npx create-expo-module --local. You write Kotlin for Android and Swift for iOS using a small declarative DSL:

  • Function("getBatteryHealth") { ... } exposes a synchronous or async function.
  • Events("onChange") sends events to JavaScript.
  • View(MyNativeView::class) exposes a native UI component.

Then you import it in TypeScript like any other package. Because it is built on JSI and works with the New Architecture, you do not write bridge boilerplate.

Good practice

  • Keep the native surface small; do data shaping in TypeScript.
  • Type the JS API carefully and handle errors thrown from native code.
  • Wrap vendor SDK setup in a config plugin so prebuild stays reproducible.

When not to

Check the Expo SDK and well-maintained community libraries first. Native modules add maintenance cost on every OS and React Native upgrade.

Good enough to move on: you shipped a local module that returns a value from Kotlin and Swift and emits at least one event.

Key concepts

  • create-expo-module
  • Exposing functions
  • Sending events to JavaScript
  • Native views
  • Basic Kotlin and Swift for modules
  • Wrapping third-party SDKs

Mini project

Write a local Expo module that reports whether the device is in low-power mode and emits an event when it changes.

Check yourself

What should you check before deciding to write your own native module?

Free resources