Skip to main content
InterviewHubPRO
Section Overview
Q21

Question 21 of 50

Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)

42%
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:

  1. Spec Definition: Define the TypeScript interface extending TurboModule:
    typescript
    export interface Spec extends TurboModule {
      getBatteryLevel(): Promise<number>;
    }
    
  2. Codegen: Generates C++ abstract base classes.
  3. Native Implementation:
    • iOS: Implement Swift/Obj-C class conforming to the generated protocol.
    • Android: Extend the generated Kotlin/Java base class.
  4. Registration: Expose via JSI with zero bridge serialization.