React Native & Expo (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
How do you write a Custom Native Module using TurboModules in Swift and Kotlin?
senior LevelCode Examplereact-nativeAdvanced Internals
In Simple Words:
- Spec Definition: Define the TypeScript interface extending
TurboModule:typescriptexport interface Spec extends TurboModule { getBatteryLevel(): Promise<number>; } - Codegen: Generates C++ abstract base classes.
- Native Implementation:
- iOS: Implement Swift/Obj-C class conforming to the generated protocol.
- Android: Extend the generated Kotlin/Java base class.
- Registration: Expose via JSI with zero bridge serialization.