Skip to content
Lucent
SEARCH LUCENT

Search guides, APIs, and examples.

GitHub

Very early and experimental. The language, the generated native code and every package API change without notice. Do not use Lucent in production.

Port an Expo Module

Keep the TypeScript API, and write the Swift and Kotlin bodies as the two branches of one Lucent module.

  1. Copy the module's TypeScript API: its exported functions, types and enums. That's your module's export list.
  2. For each function, take the Swift and the Kotlin body and write them as the two branches of one Lucent function, if (PLATFORM === "ios") { … } else { … }.
  3. Keep the SDK calls; change the syntax. Swift's names work as they are, nested types join with _, and Kotlin's getters are properties.
  4. Replace AsyncFunction(…).runOnQueue(.main) with an async function whose SDK calls sit in main().
  5. Replace throw Exception(…) with throw error("ERR_CODE", message), keeping the original's codes, so JavaScript can test them.
  6. Replace events (sendEvent) with a callback parameter and a stop function. See Send events to JavaScript.
  7. Delete the Swift, the Kotlin, the podspec, the Gradle file and expo-module.config.json. Point the JavaScript imports at the .lucent module.
ClipboardModule.swift
AsyncFunction("hasStringAsync") { () -> Bool in
UIPasteboard.general.hasStrings
}

Test the port next to the original: call both from one screen and compare. The examples are ports of six Expo and community modules, each checked this way.