Overview
Open Mushaf Native provides a robust offline reading experience by preloading and caching Mushaf pages locally. This ensures smooth navigation and instant page loading, even without an internet connection.How It Works
Image Preloading System
The app uses a smart preloading strategy implemented inuseImagePreloader.ts to cache pages ahead of time:
Adjacent Pages Calculation
Automatically identifies which pages to preload:
- Current page
- Previous page (currentPage - 1)
- Next two pages (currentPage + 1, currentPage + 2)
Implementation Details
hooks/useImagePreloader.ts
The preloader works for both Hafs and Warsh Riwayas, automatically selecting the correct image set based on your chosen Riwaya.
Storage Strategy
Asset Management
Pages are stored using Expo’s Asset system, which:- Caches images in the device’s native storage
- Persists across app sessions
- Manages storage efficiently
- Downloads assets only once
Cache Optimization
To prevent excessive storage usage:Benefits
Instant Navigation
Pages load instantly as you swipe because they’re already cached locally
No Internet Required
Read the entire Quran without any internet connection
Smart Caching
Only keeps nearby pages cached to save storage space
Cross-Riwaya Support
Works seamlessly with both Hafs and Warsh Mushafs
Technical Architecture
The offline system is built on several key components:useImagePreloader Hook
useImagePreloader Hook
Monitors current page and preloads adjacent pages in the background. Maintains a Set of preloaded page numbers to avoid redundant downloads.
useImagesArray Hook
useImagesArray Hook
Loads the actual image asset for the current page, selecting from the appropriate Riwaya image map (Hafs or Warsh).
Asset Loading
Asset Loading
Uses
Asset.fromModule() to load page images and downloadAsync() to cache them locally on the device.Performance Considerations
- Parallel Downloads: Multiple pages are downloaded simultaneously for faster caching
- Mounted State Checking: Prevents memory leaks by checking component mount status before setting state
- Conditional Loading: Only downloads assets that haven’t been cached yet
- Dynamic Image Maps: Switches between Hafs (604 pages) and Warsh image collections based on selected Riwaya
The preloader automatically pauses if the Riwaya is not yet selected, preventing unnecessary downloads.