Part 8 · Applications

Expo Module DSL in Kotlin and Swift

Prerequisites: 03-module-interface-map, 04-platform-ownership

Definition to runtime

A declarative Expo module maps the JS API to platform implementations. Nodes: JS facade, ModuleDefinition, Swift / iOS, Kotlin / Android.
A declarative Expo module maps the JS API to platform implementations. [S11] [S12]

Sync versus async

AsyncFunction dispatches by default; UI work requires an explicit main-queue decision. Nodes: Function, Quick native work, AsyncFunction, Native queue, Main queue.
AsyncFunction dispatches by default; UI work requires an explicit main-queue decision. [S12]

Mental model verified

Name exposes the JS module. Function is synchronous; AsyncFunction returns a Promise. View defines a native visual component, Events declares signals, and lifecycle hooks observe module/app/activity changes. Expo handles much of the type conversion.

[S12] [S11]

Worked flow synthesis

A payment scanner wrapper might expose Function("isSupported") for a small cached Boolean and AsyncFunction("scanAsync") for SDK work. Both Kotlin and Swift implement the contract; the exact SDK calls and error types are platform-specific. This is pseudocode, not a complete module.

[S12]

Engineering decision verified

Use AsyncFunction for I/O or long work. Explicitly dispatch UI-related operations to the main queue; do not assume an arbitrary async native function is on main. Keep a TS facade that maps platform errors to stable results.

[S12]

Failure mode and improvement verified

JavaScriptValue is tied to the JS runtime thread. Do not capture it into AsyncFunction worker work; convert it first or use a native shared object with a defined lifetime.

[S12] [S13]
Keep this: A module definition publishes functions, views and events while choosing native execution queues.
Check yourself: What is the difference between Function and AsyncFunction?

Function runs synchronously on the JS caller thread; AsyncFunction returns a Promise and normally dispatches native work away from it.

Sources & further reading

  1. [S11] Expo Modules API: Overview

    Expo · official documentation or maintainer source · accessed 2026-10-09 · current documentation as accessed; examples conceptual

    Supports: Expo Modules design and choice versus TurboModules.

    Inspect the implementation boundary described by this source.

  2. [S12] Module API Reference

    Expo · official documentation or maintainer source · accessed 2026-10-09 · current documentation as accessed; examples conceptual

    Supports: Function, AsyncFunction, queues, views, events and lifecycle.

    Inspect the implementation boundary described by this source.

  3. [S13] Using shared objects

    Expo · official documentation or maintainer source · accessed 2026-10-09 · current documentation as accessed; examples conceptual

    Supports: Long-lived native instances, JS references and deallocation.

    Inspect the implementation boundary described by this source.