How huextrat/react-native-screenshot-aware works
Project’s Main Components
• React Native JavaScript Interface: This includes the React hooks (useScreenshotAware) and the API functions provided in the src/ directory. The codegenSpec (NativeScreenshotAware.ts) acts as the bridge definition for native modules.
• Native Android Module: Found in the android/ directory (and an example version under example/android) featuring Kotlin classes (ScreenshotAwareModule.kt, ScreenshotAwarePackage.kt) and separate implementations for the new and old architectures. The module uses Android’s screenshot detection APIs available from Android 14+ via the DETECT_SCREEN_CAPTURE permission.
• Native iOS Module: Contained under the ios/ directory (and example/ios folder) with Objective-C/Swift code (ScreenshotAware.h, ScreenshotAware.mm, ScreenshotAwareImpl.*) to toggle screenshot-detection functionality.
• Example App: Located in the example/ folder. This app demonstrates how to set up and call the exposed functions on both platforms, including project-specific configurations for Gradle (Android), Xcode (iOS), and the integration of the React Native layer.
• Configuration & Build Tools: Various config files (babel.config.js, tsconfig.json, metro.config.js, Gradle and Xcode project files) that govern builds, environments, and testing (note the Jest configuration, setupJest.ts).
Graph the Relationships and Interactions
• Within the native sections:
• For Android, show separate paths for the new architecture and old architecture components (as separate sub-components). Also indicate interactions with Android’s system-level screenshot detection capabilities.
• For iOS, illustrate how the native implementation (Objective-C/Swift) handles screenshot events and communicates back to the React Native layer.
• A side component for the Example Application which consumes the module.
• Optionally, add a testing/CI system component represented by the GitHub workflows, Jest mocks, and linting configurations that ensure quality across this multi-platform integration.
Architectural Patterns and Key Design Principles
• Event-Driven Communication: Show that native modules capture screenshot events and then emit these events to the JavaScript side through the React Native bridge.
• Modularity and Extensibility: Indicate that the project is set up to be easily integrated (via npm/yarn) and improved, with well-defined extension points (e.g., the exposed hooks and callback listeners).
• That every component accounted for in the file tree (and highlighted by the README such as the permissions and API functions) is represented.
This approach not only explains the structure of the project but also serves as a blueprint for future enhancements or debugging. Happy diagramming!