How zoontek/react-native-permissions works
The react-native-permissions project is a cross‐platform library that provides a unified API to handle device permissions for React Native applications. Its purpose is to abstract away the different permission flows and platform-specific behaviors on iOS, Android, and Windows, allowing developers to check, request, and manage permissions consistently across these platforms.
Main Components
• Core JS/TypeScript Layer: Located in the “src” folder, this layer provides the main API (e.g., methods like check, request, checkNotifications, etc.) and defines types, results, and permission contracts.
• Native Bridge Layer: This is the integration point between React Native’s JavaScript and the platform-specific native code. The native modules (for instance, in “android”, “ios”, and “windows” directories) are implemented using Kotlin/Java (Android), Objective-C/Swift (iOS), and C++/C#/IDL (Windows) respectively.
• Platform-Specific Handlers:
– In the “ios” folder, several subdirectories exist, each handling a different permission (e.g., Camera, Contacts, Location, etc.).
– In the “android” folder, similar implementations reside with separate classes and modules (with architectures like “oldarch” and “newarch”).
– In the “windows” folder, you have the native implementation with a Visual Studio solution, C++ source files, and code generation.
• Example Application: The “example” folder demonstrates how an app integrates and uses the library. This folder includes sample projects for Android, iOS, and Windows, showing complete integration with Gradle, Xcode, and Visual Studio.
• Configuration and Build Tools: Various configuration files (e.g., package.json, .eslintrc.js, Podspec, Gradle files, NuGet.config) indicate the project’s integration with multiple build systems, package managers, and CI/CD pipelines.
Relationships and Data Flow
• The JavaScript API (core layer in “src”) acts as the entry point, receiving calls from the React Native app code.
• These API calls funnel through the native bridge (provided by React Native’s linking mechanism) into platform-specific native modules.
• Each platform module handles interactions with the native operating system’s permission APIs (e.g., iOS calls to CoreLocation or Camera APIs, Android calls to manifest-declared permissions, and Windows calls to system settings).
Architectural Patterns and Design Principles
• Abstraction Layer: The library cleanly separates the cross-platform logic (JS/TS code) from platform-specific implementations.
• Modular Design: Each permission (e.g., Camera, Contacts, Location) is implemented as its own module in the native directories. This modularity is also evident in the separation of “oldarch” and “newarch” code for Android.
• Extensibility: The README and project structure suggest that the module is designed to be easily extended with additional permissions or custom behaviors on each platform.
• Integration with Build Tools: Multiple configuration and build scripts (Gradle for Android, Podspec & Podfile for iOS, solution files for Windows) indicate clear integration with platform-specific build systems.
Relevant Technologies and Frameworks
• React Native: The base framework for cross-platform apps.
• JavaScript/TypeScript: Used in the “src” folder for the core API.
• Android Development Tools: Kotlin/Java source files, Gradle build system.
• iOS Development Tools: Xcode, Podspecs, Objective-C/Swift source files.
• Windows Development Tools: Visual Studio, C++ (or C++/CX/WinRT), and NuGet package configuration.
• Code quality and testing tools: ESLint, Prettier, GitHub workflows, and Jest configuration (as seen in the README and associated configuration files).
Final Assembly
– iOS: Display a block for “iOS Native Modules” that further divides into multiple permission handlers (Camera, Contacts, etc.).
– Android: Show “Android Native Modules” with separate branches for “oldarch” and “newarch” implementations if needed.
– Windows: Show “Windows Native Module” and associated code generation elements.
• Annotation on each side to denote how platform-specific behaviors (such as permission statuses and manual linking instructions) are handled.
Happy diagramming!