# huextrat/react-native-screenshot-aware architecture

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

- Interactive diagram: https://gitdiagram.com/huextrat/react-native-screenshot-aware
- Repository: https://github.com/huextrat/react-native-screenshot-aware

## Overview

##### 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!

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["React Native API"]:::reactnative

    subgraph "Native Android Module"
        B1["ScreenshotAwareModule"]:::android
        B2["ScreenshotAwarePackage"]:::android
        B3["New Architecture Implementation"]:::android
        B4["Old Architecture Implementation"]:::android
    end

    subgraph "Native iOS Module"
        C1["ScreenshotAware Header"]:::ios
        C2["ScreenshotAware ObjC"]:::ios
        C3["ScreenshotAware Implementation Header"]:::ios
        C4["ScreenshotAware Implementation ObjC"]:::ios
    end

    subgraph "Example App"
        D1["React Native Integration"]:::example
        D2["Android Example"]:::example
        D3["iOS Example"]:::example
    end

    subgraph "Configuration & Build Tools"
        F1["babel.config.js"]:::config
        F2["tsconfig.json"]:::config
        F3["metro.config.js"]:::config
        F4["android/build.gradle"]:::config
        F5["android/gradle.properties"]:::config
        F6[".github/workflows/"]:::config
        F7["setupJest.ts"]:::config
    end

    A -->|"calls"| B1
    A -->|"calls"| C1
    B1 -->|"emitsEvent"| A
    C1 -->|"emitsEvent"| A
    D1 -->|"integrates"| A
    F1 -->|"build&test"| A

    %% Click Events for React Native JavaScript Interface
    click A "https://github.com/huextrat/react-native-screenshot-aware/blob/main/src/index.tsx"
    click A "https://github.com/huextrat/react-native-screenshot-aware/blob/main/src/codegenSpec/NativeScreenshotAware.ts"

    %% Click Events for Native Android Module
    click B1 "https://github.com/huextrat/react-native-screenshot-aware/blob/main/android/src/main/java/com/screenshotaware/ScreenshotAwareModule.kt"
    click B2 "https://github.com/huextrat/react-native-screenshot-aware/blob/main/android/src/main/java/com/screenshotaware/ScreenshotAwarePackage.kt"
    click B3 "https://github.com/huextrat/react-native-screenshot-aware/blob/main/android/src/newarch/ScreenshotAware.kt"
    click B4 "https://github.com/huextrat/react-native-screenshot-aware/blob/main/android/src/oldarch/ScreenshotAware.kt"

    %% Click Events for Native iOS Module
    click C1 "https://github.com/huextrat/react-native-screenshot-aware/blob/main/ios/ScreenshotAware.h"
    click C2 "https://github.com/huextrat/react-native-screenshot-aware/blob/main/ios/ScreenshotAware.mm"
    click C3 "https://github.com/huextrat/react-native-screenshot-aware/blob/main/ios/ScreenshotAwareImpl.h"
    click C4 "https://github.com/huextrat/react-native-screenshot-aware/blob/main/ios/ScreenshotAwareImpl.mm"

    %% Click Events for Example App
    click D1 "https://github.com/huextrat/react-native-screenshot-aware/blob/main/example/src/App.tsx"
    click D2 "https://github.com/huextrat/react-native-screenshot-aware/tree/main/example/android/"
    click D3 "https://github.com/huextrat/react-native-screenshot-aware/tree/main/example/ios/"
    click D1 "https://github.com/huextrat/react-native-screenshot-aware/tree/main/example/"

    %% Click Events for Configuration & Build Tools
    click F1 "https://github.com/huextrat/react-native-screenshot-aware/blob/main/babel.config.js"
    click F2 "https://github.com/huextrat/react-native-screenshot-aware/blob/main/tsconfig.json"
    click F3 "https://github.com/huextrat/react-native-screenshot-aware/blob/main/metro.config.js"
    click F4 "https://github.com/huextrat/react-native-screenshot-aware/blob/main/android/build.gradle"
    click F5 "https://github.com/huextrat/react-native-screenshot-aware/blob/main/android/gradle.properties"
    click F6 "https://github.com/huextrat/react-native-screenshot-aware/tree/main/.github/workflows/"
    click F7 "https://github.com/huextrat/react-native-screenshot-aware/blob/main/setupJest.ts"

    classDef reactnative fill:#f9f,stroke:#333,stroke-width:2px;
    classDef android fill:#ccf,stroke:#333,stroke-width:2px;
    classDef ios fill:#cfc,stroke:#333,stroke-width:2px;
    classDef example fill:#fc9,stroke:#333,stroke-width:2px;
    classDef config fill:#cff,stroke:#333,stroke-width:2px;
```
