How folioreader/folioreaderkit works
Project type and purpose
• FolioReaderKit is an iOS framework (CocoaPod/Carthage) written in Swift that parses and renders ePub files, provides UI for reading, highlights, TTS, Media Overlays, and exposes delegate hooks to the host app.
File structure
• Top-level “Source” folder: contains Swift source code organized by feature (EPUBCore parser, UI components, models, resources, extensions).
• “Example” folder: sample apps demonstrating programmatic and storyboard integration.
• “Vendor” & “docs”: packaged JavaScript bridge, CSS, Jazzy documentation.
• Config, Podspec, Package.swift: define packaging/dependency setup.
• Tests: unit tests for parsing and sharing provider.
Key insights from README
• Core features: EPUB 2/3 parsing, custom fonts, highlights, themes, TTS, Media Overlays, multi-instance support.
• Usage patterns: call FolioReader.presentReader, subclass FolioReaderContainer, implement FolioReaderDelegate to receive events.
Main components to portray
a. Parsing Layer (green)
• FREpubParser → FRBook, FRSpine, FRResources, FRResource, FRMetadata, FRTocReference, FRSmilElement
• Media overlay sync (SMIL) feeds to audio player
b. Rendering & UI Layer (blue)
• FolioReaderContainer (UIViewController subclass)
• FolioReaderCenter (singleton/controller orchestrator)
• FolioReaderWebView (WKWebView + Bridge.js injection + Style.css)
• PageViewController / FolioReaderPage (UIPageViewController + page indicator)
• Menus: FontsMenu, PlayerMenu, ChapterList, HighlightList, QuoteShare
c. Audio & TTS (orange)
• FolioReaderAudioPlayer (AVFoundation for Media Overlays & TTS)
d. Models & Storage (yellow)
• Model, QuoteImage, UserDefaults wrapper (FolioReaderUserDefaults)
e. Host App Integration (purple)
• FolioReaderDelegate & FolioReaderCenterDelegate (protocols)
• Host passes epub path + config (FolioReaderConfig) → receives callbacks
f. Resources (gray)
• Bridge.js, CSS, Fonts, Images
Relationships & data flow
• Input: App provides .epub file → FREpubParser builds FRBook
• Parser outputs resources & HTML/CSS → loaded into WKWebView via FolioReaderWebView
• PageViewController drives navigation; UI menus invoke actions on FolioReaderCenter
• Bridge.js posts events (highlight tapped, location changed) back to Swift via message handlers
• FolioReaderAudioPlayer requests SMIL timings → plays audio overlay or TTS; updates UI via FolioReaderCenter
• Actions update model & persist via UserDefaults → reflected in UI
• Delegate callbacks propagate reading events back to host app
Architectural patterns & principles
• MVC / Coordinator: FolioReaderCenter coordinates between model (parser, highlights, audio) and view (webView, menus)
• Delegation: host integration via protocols
• Composition: container view controllers + child page controllers
• Bridge pattern: JavaScript ↔ Swift communication
• Single Responsibility: parser, UI, audio, storage each isolated