BookNest's Turbo Native Module opens Android's share sheet and counts how often it has. Its spec is the one Typing Turbo Modules typed, now in specs/:
import type { CodegenTypes, TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';
// The contract between JavaScript and Kotlin; Codegen turns it into NativeBookShareSpec
export interface Spec extends TurboModule {
shareBook(title: string, url: string): Promise<boolean>;
getShareCount(): CodegenTypes.Int32;
}
export default TurboModuleRegistry.getEnforcing<Spec>('NativeBookShare');The rules are strict because Codegen parses this file rather than running it. The file name starts with Native, the interface is called Spec and extends TurboModule, and the string passed to getEnforcing is the module's registered name. Only types Codegen understands are allowed: string, boolean, number, CodegenTypes.Int32 and friends, object types, arrays, Promise, callbacks, and nullable versions of these. getEnforcing throws when the module is first requested if the native side is missing; get returns null instead, for optional modules. Then tell Codegen where specs live, in package.json:
"codegenConfig": {
"name": "NativeBookShareSpec",
"type": "modules",
"jsSrcsDir": "specs",
"android": {
"javaPackageName": "com.anonymous.booknest.share"
}
}