原生模块让 React Native (JavaScript) 访问原生平台代码和功能(iOS/Android),这些功能通过 JavaScript 无法获得 — 桥接到原生 API、SDK 或自定义原生功能。它们扩展了 React Native 超越 JS 单独提供的功能。
原生模块存在的原因
React Native's JavaScript can't directly access every native capability. NATIVE MODULES
bridge JS to native code (Swift/Objective-C on iOS, Kotlin/Java on Android):
→ access native APIs/SDKs not exposed to JS
→ use existing native libraries
→ implement performance-critical or platform-specific functionality in native code
→ The bridge between React Native's JS and the native platform.
使用原生模块(主要通过库)
→ MOST native functionality is available via EXISTING LIBRARIES (npm packages that
include native modules): camera, geolocation, Bluetooth, payments, push notifications, etc.
→ you usually INSTALL a library rather than writing native code yourself
→ EXPO provides many native APIs without writing native code (managed modules)
→ You WRITE a custom native module only when no library exists for your need
