Skip to main content

JS specification

When all boilerplate is ready, let's navigate to src/NativeAppInfoModule.ts. To declare module spec, let's paste following content:

src/NativeAppInfoModule.ts
import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';

export interface Spec extends TurboModule {
getAppBuildNumber(): string
getAppBundleId(): string
getAppVersion(): string
}

export default TurboModuleRegistry.getEnforcing<Spec>('AppInfoModule');

This does 2 things:

  • declares module specification with 3 synchronous methods, each one returning a string value
  • declares that module, should be available under AppInfoModule name

You can run codegen to generate native classes and interfaces, and also check if specification is defined in correct way:

  • on iOS: run yarn codegen:ios, the code-generated classes should be available under your app's <rootDir>/ios/build/generated/ios directory

  • on Android: yarn codegen:android, the code-generated classes should be available under the package's <rootDir>/<packageDir>/android/build/generated/source/codegen directory

After that, let's finalize JS part by exporting module from index.ts

src/index.ts
export { default as AppInfoModule } from './NativeAppInfoModule';

JS part finished! Let's jump to iOS implementation.