LynxNativeModule
Call native code that the host app exposes, and share JavaScript modules within a page. import { LynxNativeModule, type NativeModuleMap } from '@blotch/angular-lynx';
A native module is an object that the host app (the native iOS or Android app that runs your bundle) registers, with methods written in Swift, Kotlin or another native language.
Usage
API
LynxNativeModule
Typed access to Lynx's native module bridge and its JavaScript module registry. Every method is safe to call outside Lynx: it does nothing, or returns undefined.
Lynx provides native modules and the module registry only on the background thread. On the main thread, which runs your event handlers and draws the UI, every method does nothing or returns undefined. A constructor runs on both threads, so the call in Usage reaches the host from the background copy. Results also arrive there, so showing them on screen isn't supported yet. See Threads.
LynxNativeModule.call()
Calls the host's bridge method name with params, which defaults to {}. Resolves with the first value the host passes back, or undefined when there is no bridge.
LynxNativeModule.on()
Listens for the bridge event name from the host. There's no way to stop listening.
LynxNativeModule.getNativeModule()
Returns the native module the host registered as name, or undefined. The return type comes from NativeModuleMap. Until you can extend that type (see below), cast the result to your module's interface.
LynxNativeModule.getJSModule()
Returns a JavaScript module registered in this page with registerJSModule(), or undefined.
LynxNativeModule.registerJSModule()
Registers module under name, so other code in this page, including native callbacks, can find it.
Types
NativeModuleMap
Maps module names to their types for getNativeModule(). It's meant to be extended with your own modules, but it's declared as a type, which TypeScript can't merge with your declarations. Cast instead:
