How tlow92/expo-key-event works
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).