# tlow92/expo-key-event architecture

> Architecture diagram of the GitHub repository tlow92/expo-key-event, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tlow92/expo-key-event
- Repository: https://github.com/tlow92/expo-key-event

## Overview

##### Main Components
- Expo Module Core: This is the JavaScript/TypeScript layer found in the root “src” folder. It includes types, constants (mappings for iOS/Android and a common mapping), hooks (e.g., useKeyEvent, useKeyEventListener), and utility functions. This core exposes the unified API.
- Native Implementations:
- Android: Located in the “android” directory. Here you have native Kotlin modules such as ExpoKeyEventModule.kt and ExpoKeyEventView.kt, supported by the AndroidManifest and Gradle build configurations.
- iOS: Found within the “ios” folder featuring the Swift-based module (ExpoKeyEventModule.swift) and the podspec configuration for module packaging.
- Web Implementation: Although there is no dedicated “web” folder, platform-specific implementations are handled by separate hooks (for instance, useKeyEvent.web.ts in “src/hooks”) and web-specific mappings.
- Example Application: The “example” directory demonstrates how consumer apps integrate the module using the provided hooks in a full React Native environment.

##### Component Interactions
- Common Key Event Flow: Show that native key events are received, translated (using mapping constants such as in src/constants/KeyCodeMapping.*.ts), and then exposed to the React components via hooks.
- Hook Layers: Differentiate between the “automatic listening” via useKeyEvent and the “manual control” approach (useKeyEventListener), and show where these hooks interact with the API layer.
- Configuration and Build: Represent the configuration files (e.g., expo-module.config.json, Android build.gradle, iOS podspec) as supporting elements that ensure proper integration with the Expo ecosystem.

##### Architectural Patterns and Design Principles
- Abstraction and Unification: Emphasize how native platform-specific key event handling is abstracted into a single common API.
- Separation of Concerns: Highlight that native implementation details are isolated in the “android” and “ios” directories, while the cross-platform JavaScript code resides in “src”. There’s also a separation in handling web specifics with dedicated hooks.
- Modular Design: The project is designed as a module ready for integration into any Expo project. The file tree and usage examples demonstrate loosely-coupled components.

##### Relevant Technologies, Frameworks, and Libraries
- Expo SDK (with a requirement of SDK version 52 or above).
- React Native (for mobile platforms) and React (considering the hooks for component-based architecture).
- Kotlin and Swift for native module development.
- TypeScript for the API and mapping logic.
- Configuration and build tooling (Gradle for Android, Podspec for iOS, NPM for packaging).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Native Android Module Subgraph
    subgraph "Native Android Module"
        A1["ExpoKeyEventModule.kt"]:::native
        A2["ExpoKeyEventView.kt"]:::native
        A3["build.gradle"]:::config
        A4["AndroidManifest.xml"]:::config
    end

    %% Native iOS Module Subgraph
    subgraph "Native iOS Module"
        I1["ExpoKeyEventModule.swift"]:::native
        I2["ExpoKeyEvent.podspec"]:::config
    end

    %% Web Handlers Subgraph
    subgraph "Web Handlers"
        W1["useKeyEvent.web.ts"]:::web
        W2["useKeyEventListener.web.ts"]:::web
    end

    %% Expo-key-event Core (JS/TS) Subgraph
    subgraph "Expo-key-event Core (JS/TS)"
        J1["ExpoKeyEventModule.ts"]:::jsCore
        J2["index.ts"]:::jsCore
        J3["Constants & Types"]:::jsCore
        J4["Hooks & Utils"]:::jsCore
    end

    %% Example Application and Configuration Node
    E["Example Application"]:::app
    C["expo-module.config.json"]:::config

    %% Relationships - Native modules and Web handlers feed into JS Core
    A1 -->|"nativeEvent"| J3
    I1 -->|"nativeEvent"| J3
    W1 -->|"webEvent"| J4

    %% JS Core exports unified API to Example Application
    J1 -->|"exportsAPI"| E
    J2 -->|"exportsAPI"| E

    %% Configuration supports Native and JS layers
    C -.-> A3
    C -.-> I2
    C -.-> J3

    %% Styles
    classDef native fill:#99ccff,stroke:#333,stroke-width:2px;
    classDef jsCore fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef web fill:#ffcc99,stroke:#333,stroke-width:2px;
    classDef app fill:#ffddaa,stroke:#333,stroke-width:2px;
    classDef config fill:#d1c4e9,stroke:#333,stroke-width:2px;

    %% Click Events
    click J1 "https://github.com/tlow92/expo-key-event/blob/main/src/ExpoKeyEventModule.ts"
    click J2 "https://github.com/tlow92/expo-key-event/blob/main/src/index.ts"
    click J3 "https://github.com/tlow92/expo-key-event/tree/main/src/constants"
    click J4 "https://github.com/tlow92/expo-key-event/tree/main/src/hooks"

    click A1 "https://github.com/tlow92/expo-key-event/blob/main/android/src/main/java/expo/modules/keyevent/ExpoKeyEventModule.kt"
    click A2 "https://github.com/tlow92/expo-key-event/blob/main/android/src/main/java/expo/modules/keyevent/ExpoKeyEventView.kt"
    click A3 "https://github.com/tlow92/expo-key-event/blob/main/android/build.gradle"
    click A4 "https://github.com/tlow92/expo-key-event/blob/main/android/src/main/AndroidManifest.xml"

    click I1 "https://github.com/tlow92/expo-key-event/blob/main/ios/ExpoKeyEventModule.swift"
    click I2 "https://github.com/tlow92/expo-key-event/blob/main/ios/ExpoKeyEvent.podspec"

    click W1 "https://github.com/tlow92/expo-key-event/blob/main/src/hooks/useKeyEvent.web.ts"
    click W2 "https://github.com/tlow92/expo-key-event/blob/main/src/hooks/useKeyEventListener.web.ts"

    click E "https://github.com/tlow92/expo-key-event/tree/main/example/"
    click C "https://github.com/tlow92/expo-key-event/blob/main/expo-module.config.json"
```
