# azizak/react-native-detector architecture

> Architecture diagram of the GitHub repository azizak/react-native-detector, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/azizak/react-native-detector
- Repository: https://github.com/azizak/react-native-detector

## Overview

##### Main Components
- React Native Module: At the heart of the project is the JavaScript/TypeScript interface (located in the src folder and the package.json entry point) that the React Native application code will use.
- Android Native Module: Under the “android” directory and also further demonstrated in the “example/android” folder, there are native Kotlin/Java components (e.g., DetectorModule.kt, DetectorPackage.kt, ScreenshotDetectionDelegate.kt) that detect screenshot events. This part handles permissions (via AndroidManifest.xml edits) and logic to monitor filesystem changes or system events regarding screenshots.
- iOS Native Module: In the “ios” directory and corroborated by the files under “example/ios”, there is native Objective-C/Swift code (Detector.h, Detector.m, associated Xcode project files) that serves the same purpose as the Android side.
- Example Application: The “example” directory provides a demonstrative full application integrating the React Native library. This sample project shows how the library’s API is invoked, how native events are forwarded, and how UI components are assembled.

##### Relationships and Data Flows
- The React Native layer (JavaScript/TypeScript) acts as an abstraction and exposes API methods that wrap native functionality.
- When a screenshot event occurs on a device, the respective platform’s native module (Android or iOS) detects it.
- This native event is propagated via the React Native bridge back to the JavaScript layer where any added screenshot listeners get invoked.
- The example application demonstrates the lifecycle of this event handling and serves as a practical integration and testing ground.

##### Architectural Patterns and Design Principles
- Platform Abstraction: The library isolates native functionality from a unified JavaScript API which is important for cross-platform compatibility.
- Observer / Listener Pattern: The design uses listener callbacks (via addScreenshotListener and removeScreenshotListener) to notify the app when a screenshot is taken.
- Modular Design: Code is neatly separated into platform-specific folders and into “example” implementations, making the library maintainable and easier to integrate.

##### Relevant Technologies and Frameworks
- React Native for the JavaScript API.
- Kotlin/Java for Android native implementation.
- Objective‑C/Swift (and associated Xcode build tooling) for the iOS implementation.
- Gradle and Podspec for building and integrating the native modules.
- Standard build and CI tools (like .circleci config files) to ensure quality.

##### Elements
- Clear labels for each module/component (e.g., “React Native API”, “Android Detector Module”, “iOS Detector Module”, “Example App”).
- Indication of key dependencies such as permissions (READ_EXTERNAL_STORAGE for Android) and native configuration files (build.gradles, Podspec).

1. The React Native JavaScript layer that includes the public API.
2. The Android native module (with its respective Kotlin/Java files and permission handling).
3. The iOS native module (with its Objective-C/Swift files and Xcode project settings).
4. An example integration (demonstrated through the “example” directory) that shows how these components interact.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% React Native API Layer
    subgraph "React Native API Layer"
        RN_API["React Native API (src/index.tsx)"]:::react
    end

    %% Android Native Module
    subgraph "Android Native Module"
        Android_Package["DetectorPackage.kt"]:::android
        Android_Module["DetectorModule.kt"]:::android
        Android_Screenshot["ScreenshotDetectionDelegate.kt"]:::android
    end

    %% iOS Native Module
    subgraph "iOS Native Module"
        iOS_Detector_H["Detector.h"]:::ios
        iOS_Detector_M["Detector.m"]:::ios
        iOS_Xcode["Detector.xcodeproj"]:::ios
    end

    %% Example Integration
    subgraph "Example Integration"
        Example_Dir["Example Directory (example/)"]:::example
        Example_App["Example App (example/src/App.tsx)"]:::example
    end

    %% Relationships between components
    %% Example Integration calling the React Native API
    Example_App -->|"callsAPI"| RN_API

    %% React Native API bridging to native modules
    RN_API -->|"bridgesToAndroid"| Android_Module
    RN_API -->|"bridgesToiOS"| iOS_Detector_M

    %% Native modules sending back events
    Android_Screenshot -->|"eventDetected"| RN_API
    iOS_Detector_M -->|"eventDetected"| RN_API

    %% Android package composition
    Android_Package -->|"includes"| Android_Module
    Android_Package -->|"includes"| Android_Screenshot

    %% iOS project building iOS detectors
    iOS_Xcode -->|"builds"| iOS_Detector_H
    iOS_Xcode -->|"builds"| iOS_Detector_M

    %% Styles
    classDef react fill:#ffccff,stroke:#cc00cc,stroke-width:2px;
    classDef android fill:#ccffcc,stroke:#009900,stroke-width:2px;
    classDef ios fill:#cce5ff,stroke:#0066cc,stroke-width:2px;
    classDef example fill:#ffe6cc,stroke:#cc6600,stroke-width:2px;

    %% Click Events
    click RN_API "https://github.com/azizak/react-native-detector/blob/master/src/index.tsx"
    click Android_Module "https://github.com/azizak/react-native-detector/blob/master/android/src/main/java/com/reactnativedetector/DetectorModule.kt"
    click Android_Package "https://github.com/azizak/react-native-detector/blob/master/android/src/main/java/com/reactnativedetector/DetectorPackage.kt"
    click Android_Screenshot "https://github.com/azizak/react-native-detector/blob/master/android/src/main/java/com/reactnativedetector/ScreenshotDetectionDelegate.kt"
    click iOS_Detector_H "https://github.com/azizak/react-native-detector/blob/master/ios/Detector.h"
    click iOS_Detector_M "https://github.com/azizak/react-native-detector/blob/master/ios/Detector.m"
    click iOS_Xcode "https://github.com/azizak/react-native-detector/blob/master/ios/Detector.xcodeproj"
    click Example_App "https://github.com/azizak/react-native-detector/blob/master/example/src/App.tsx"
    click Example_Dir "https://github.com/azizak/react-native-detector/tree/master/example/"
```
