How nandorojo/galeria works
Project Type and Purpose
• This is a UI component library for image viewing that works with any image component. It is built to support React, React Native (both iOS and Android), and also plain web usage.
• The README highlights features like shared element transitions, pinch/double-tap zoom, multi-image support, and integration with various image components (including 3rd-party ones like FastImage and SolitoImage).
File Structure for Components
• Native Code:
• The “android” directory contains Kotlin source code (modules and native support via Android modules, e.g., GaleriaModule.kt, GaleriaView.kt, and native UI fragments).
• The “ios” directory includes native iOS implementations using Swift (e.g., GaleriaModule.swift, GaleriaView.swift, and the podspec file).
• Shared/JavaScript Code:
• The “src” folder houses the TypeScript definitions and platform-specific implementations of GaleriaView (with separate files for Android, iOS, and common logic).
• The package’s root-level files (package.json, tsconfig.json, etc.) form the cross-platform JS/TS layer.
• Example/Demo Integration:
• The “example” folder demonstrates different usage scenarios, integration with various technologies (e.g., FlashList, Next.js, Expo) and provides a live demo of the library in action.
• Configuration and Build Files:
• Files like expo-module.config.json, babel.config.js, metro.config.js, webpack.config.js, and various yarn files indicate multi-platform build and bundling support.
a. Main Components to Include:
• React/JS Layer: Core Galeria component code (found in src/ and package.json) that provides the API and common logic.
• Platform-Specific Native Modules:
• Android Module (in the android folder): Implements native image viewing features using Kotlin.
• iOS Module (in the ios folder): Implements native image viewing features using Swift.
• Example/Demo Applications:
• Example folder that illustrates integration scenarios with different frameworks (React Native, Next.js, etc.).
• Web Support: Highlight that the web version uses Framer Motion for transitions and simplified image viewing.
b. Data Flow and Interaction:
• The React component (Galeria) serves as a façade. It abstracts over the various native implementations:
• On Android and iOS, it bridges to their respective native modules when running on mobile.
• On web, it uses a fully JavaScript-based approach.
• The component accepts props and children (custom image components) and delegates behaviors (e.g., pinch, zoom) to either the native or web layer.
Architectural Patterns to Note
• Portability and Abstraction: The separation between platform-agnostic React/JS code and native platform implementations.
• Modularity: Clean API design that allows “bringing your own image component” (BYOIC) enhances flexibility.
• Cross-Platform Design: Conditional code branches and separate files (e.g., GaleriaView.android.tsx vs. GaleriaView.ios.tsx) using platform-specific file naming conventions.