Setup and Codegen
This guide covers the required setup to define your navigation contract and generate bridge files for @callstack/brownfield-navigation.
Prerequisites
Before you start:
- Your React Native app has
@callstack/brownfield-navigationinstalled. - Your app has Babel dependencies available (
@babel/core,@react-native/babel-preset), which are used during codegen.
1) Create brownfield.navigation.ts
Create a new file named brownfield.navigation.ts in your React Native app root.
Example:
Supported method signatures
- Method name: any valid TypeScript identifier.
- Params: typed and optional params are supported (for example
userId?: string). - Return type:
voidis the common and recommended type for navigation actions. - Interface name:
BrownfieldNavigationSpec(orSpec) is supported by the parser.
Info
Prefer simple synchronous navigation methods (void).
Async Promise-based methods are not currently supported by the generated native code on iOS and Android — they will compile, but the generated implementations will reject with a not_implemented error.
2) Run codegen
From your app root:
3) What gets generated
Codegen updates @callstack/brownfield-navigation with your contract:
src/NativeBrownfieldNavigation.ts(TurboModule spec)src/index.ts(JavaScript API surface)ios/BrownfieldNavigationDelegate.swift(delegate protocol)ios/NativeBrownfieldNavigation.mm(native module implementation)- Android delegate/module files under:
android/src/main/java/com/callstack/nativebrownfieldnavigation/
4) Regenerate when contract changes
Any time you add, remove, or rename methods in brownfield.navigation.ts, rerun:
Then recompile native apps.
Next
- Continue with Native Integration
- Then wire JS calls from JavaScript Usage
