Calling Native Modules

Registering and Calling the Module from JavaScript

BookSharePackage extends BaseReactPackage: getModule() returns a BookShareModule when asked for NativeBookShare, and getReactModuleInfoProvider() marks it isTurboModule = true and needsEagerInit = false, so it is created on first use. A library would be autolinked; an app's own package must be added to MainApplication.kt, and after a prebuild BookNest's plugin (Config Plugins) has done that:

Checking the registration after prebuildShell
grep -n "BookShare" android/app/src/main/java/com/anonymous/booknest/MainApplication.kt
Output
7:import com.anonymous.booknest.share.BookSharePackage
26:          add(BookSharePackage())

JavaScript imports the spec's default export, which is the module object itself, typed by the Spec interface. BookNest's storage demo screen calls both methods:

src/demos/StorageBench.tsx: calling the Turbo Native Module (excerpt)TSX
      log(`shares so far: ${NativeBookShare.getShareCount()}`);     // synchronous, over JSI
  const share = async () => {
    const opened = await NativeBookShare.shareBook('Salt and Saffron',
      'https://booknest.example.com/book/3');
    log(`share sheet opened: ${opened}, count now ${NativeBookShare.getShareCount()}`);
  };
Output
 LOG  shares so far: 0
 LOG  share sheet opened: true, count now 1

Android's share sheet opened over BookNest with the text "Salt and Saffron https://booknest.example.com/book/3". Because the spec is typed, NativeBookShare.shareBook(3) is a TypeScript error. If the native side were missing, for example in Expo Go 6,418 , which cannot load your Kotlin, getEnforcing would throw "TurboModuleRegistry.getEnforcing(...): 'NativeBookShare' could not be found" the moment the spec file is imported.