How oblador/react-native-image-progress works
Project Type and Purpose
• Type: An open-source React Native component library
• Purpose: Wrap React Native’s core <Image> component to show a progress indicator (e.g., spinner, bar, pie) while images download.
Core Components and Their Roles
A high-level view shows these main pieces:
1. Consumer App (Example/ or any RN app)
• Hosts Metro bundler, integrates JS code into native shells (Android/iOS).
2. react-native-image-progress (Library Code)
• Exposes <Image> wrapper (in index.js/index.d.ts).
• Uses createImageProgress() to generate a custom Image component when needed.
3. react-native-progress (Dependency)
• Provides progress indicator components (Bar, Pie, etc.).
4. React Native Core
• Image lifecycle events: onLoadStart, onProgress, onLoad, onError.
• Bridges JS → Native for networking and rendering.
5. Native Platforms
• Android (Java/Kotlin, Gradle, JNI bridge)
• iOS (Objective-C/Swift, Xcode project, CocoaPods)
6. Network / External Image Server
• Hosts remote image assets the app fetches.
Relationships & Data Flows
• App Startup → Metro Bundler → Loads JS bundle
• Library Component
– Wraps RN <Image> and listens to onProgress callbacks.
– For each progress event, it invokes the chosen indicator (from react-native-progress) with progress & indeterminate props.
– On error, calls renderError; on load, passes through onLoad* events back to the app.
• Native Bridge
– JS <Image> → Native download module → streams data → fires progress events back to JS.
• UI Rendering
– Indicator component overlays inner image until download completes.
Architectural Patterns & Principles
• Decorator Pattern: Enhances core Image by wrapping it and hooking into its events.
• Pluggable Strategy: Indicator injection via indicator prop or renderIndicator().
• Separation of Concerns: Network logic handled by RN core/native, UI logic in JS library.
• Extensibility: Custom image implementations via createImageProgress().
Essential Elements
• Components:
• Consumer RN App (Example)
• react-native-image-progress JS module
• react-native-progress indicators
• React Native Core Image Loader
• Native Modules (Android & iOS)
• Network / Image CDN
• Interactions:
• Import & render flows
• Event callbacks: onLoadStart → onProgress → onLoad / onError
• Data flow: HTTP GET → bytes streamed → progress %
• Styling/Notation: