Native code · senior
Writing a Turbo Native Module and a Fabric native component
To add native code on the New Architecture you write a typed spec (NativeX.ts for a module, XNativeComponent.ts for a view), declare it in codegenConfig, let Codegen generate interfaces, implement them in Kotlin and Objective-C++ (Swift behind a small wrapper), and register them so autolinking finds them.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Module spec: specs/NativeDeviceHealth.ts with interface Spec extends TurboModule { getBatteryLevel(): Promise<number>; isLowPowerMode(): boolean } and TurboModuleRegistry.getEnforcing<Spec>('NativeDeviceHealth').
- codegenConfig in package.json: name, type ("modules" or "components"), jsSrcsDir, android.javaPackageName, and ios.modulesProvider (modules) or ios.componentProvider (components).
- Android module: a Kotlin class extends the generated NativeDeviceHealthSpec; a BaseReactPackage returns it from getModule and marks isTurboModule = true in getReactModuleInfoProvider; register it in MainApplication.getPackages() (libraries autolink).
- iOS module: an .mm (Objective-C++) class conforms to the generated protocol, returns NativeDeviceHealthSpecJSI from getTurboModule:, and implements +moduleName. Swift code sits behind an Objective-C++ wrapper (or use Expo Modules / Nitro).
- Component spec: codegenNativeComponent<NativeProps>('CustomWebView') where NativeProps extends ViewProps; events typed with CodegenTypes.BubblingEventHandler or DirectEventHandler.
- Android component: a SimpleViewManager implementing the generated ManagerInterface with a ManagerDelegate, returned from createViewManagers. iOS component: an RCTViewComponentView subclass with updateProps:oldProps: and componentDescriptorProvider.
- Re-run Codegen after changing a spec (pod install on iOS, a Gradle build on Android). Do not commit generated code. Test release builds on both platforms.
The red pen
Common traps: mistake → fix
Mistake: "The spec file can have any name"
Fix: modules need the Native prefix; components need the NativeComponent suffix.
Mistake: "I changed the spec; iOS will pick it up"
Fix: run pod install so Codegen runs again.
Mistake: "Make every method synchronous"
Fix: only cheap reads should be sync.
Easy to hard
Questions interviewers ask, easy to hard
- Walk me through a Turbo Native Module that exposes async getBatteryLevel() and sync isLowPowerMode() on both platforms.
- Where do you register it on Android? What is BaseReactPackage?
- Why is the iOS file .mm? How would you write it in Swift?
- How is a Fabric native component different from a module? What does Codegen generate for it?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.