React Native & Expo (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
Native Module Authoring with Codegen specs in the New Architecture.
senior LevelCode ExampleSecurity & AuthSystem Design
In Simple Words: In the New Architecture, native modules are strictly type-safe across JavaScript and C++/Swift/Kotlin:
- Define the interface in TypeScript using Flow or TypeScript Spec:
typescript
// NativeBattery.ts import type { TurboModule } from 'react-native'; import { TurboModuleRegistry } from 'react-native'; export interface Spec extends TurboModule { getBatteryLevel(): Promise<number>; } export default TurboModuleRegistry.getEnforcing<Spec>('NativeBattery'); - Run Codegen: Generates C++ glue headers enforcing that your native Swift/Kotlin methods match the exact parameter types at compile time.