Shipping a Manga & Webtoon Reader to Android, Desktop, and Kotlin/Wasm from One Compose Codebase

2026-12-03来源 dev.toEnglish
Shipping a Manga & Webtoon Reader to Android, Desktop, and Kotlin/Wasm from One Compose Codebase

Live web build: app.fmo.qzz.io · Downloads & showcase: masfana.github.io/FanaCumik-App · Repo (MIT): MasFana/FanaCumik-App

I built Fana Cumik to target Android, Desktop (JVM), and Web (wasmJs) from one Compose Multiplatform module (shared/), backed by MasFana/FanaCumik-API.

Instead of splitting separate UI trees per platform, all five screens (Sources, Browse, Details, Reader, History), pagination, caching, and reading checkpoints live in common code. Platform folders (src@android, src@jvm, src@wasmJs, and an jvmAndAndroid alias) only implement storage drivers, network engines, window insets, and HD tile decoders.

Desktop Webtoon reader with docked chapter list

1. Architecture and Dependency Footprint

Fana Cumik uses the self-bootstrapping Kotlin Toolchain (./kotlin) and targets Java 21 LTS on Desktop. One app-scoped AppServices object owns a single Ktor HttpClient, Coil ImageLoader, MangaRepository, settings store, and history store across route transitions and Android configuration changes:

Layer Android (src@android) Desktop (src@jvm) Web (src@wasmJs)
HTTP Client Ktor OkHttp (3.6.2) Ktor OkHttp (3.6.2) Ktor JS (3.6.2) + Pages Functions
Image Pipeline Coil 3.4.0 + 48 MiB RAM / 128-1024 MB Disk Coil 3.4.0 + 48 MiB RAM / 128-1024 MB Disk Coil 3.4.0 (in-memory)
HD Webtoon Tiling BitmapRegionDecoder (<= 2048 px slices) Skia Surface + SamplingMode.MITCHELL Single-image fallback (FilterQuality.High)
Reading History Bundled SQLite (2.6.2) Bundled SQLite (2.6.2) localStorage via HistoryStore
Preferences DataStore (1.2.1) DataStore (1.2.1) localStorage via SettingsStore

2. Keeping Tall Webtoon Strips Sharp Without Blowing GPU Texture Limits

Webtoon chapters frequently pack an entire vertical scene into a 900x16000 px PNG or JPEG. Bounding Coil requests to safe GPU texture limits shrinks the horizontal width along with the height:

internal fun computeBucketedImageSize( viewportWidthPx: Int, viewportHeightPx: Int, mode: ReaderMode, ): ImageTargetSize { val safeW = viewportWidthPx.coerceAtLeast(128) val safeH = viewportHeightPx.coerceAtLeast(128) val bucketW = (((safeW + 127) / 128) * 128).coerceIn(128, 2048) val maxAreaHeight = (4_194_304 / bucketW).coerceIn(128, 4096) val targetH = when (mode) { ReaderMode.WEBTOON -> maxAreaHeight ReaderMode.PAGED_RTL, ReaderMode.PAGED_LTR -> { val bucketH = (((safeH + 127) / 128) * 128).coerceAtLeast(128) minOf(maxAreaHeight, bucketH) } } return ImageTargetSize(width = bucketW, height = targetH) } 

At bucketW = 1024, maxAreaHeight caps at 4096. For a 16,000 px strip, Scale.FIT downscales the width roughly 4x.

To recover crisp line art, ReaderScreen triggers decodeHdWebtoonTiles whenever a ready strip is taller than maxSingleHeightPx and rendered narrower than maxWidthPx:

  • Android (AppPlatform.android.kt): Reads the encoded file directly from Coil's images-v1 disk cache via BitmapRegionDecoder.newInstance(filePath, false) and decodes slices of 2048 px output height, skipping full-bitmap allocation.
  • Desktop (AppPlatform.jvm.kt): Decodes via org.jetbrains.skia.Image.makeFromEncoded, draws 2048 px strips onto raster Surface instances with SamplingMode.MITCHELL, and converts each snapshot with toComposeImageBitmap().
  • Flush strip seams: Ready Webtoon strips render without per-item .aspectRatio().background(...) wrapper boxes so sub-pixel rounding never leaves horizontal lines between consecutive panels.

3. Single Page Owner and Bounded 2-Job Scheduling

ReaderImageController (shared/src/ReaderImages.kt) prevents duplicate HTTP requests and duplicate image decodes:

  1. Visible slots and viewport dimensions stream from snapshotFlow.
  2. Active work is capped at MAX_ACTIVE_JOBS = 2, with at most MAX_SPECULATIVE_JOBS = 1.
  3. Every task keys on (url, targetWidth, targetHeight). If a user scrolls onto a page currently preloading, the scheduler promotes the in-flight job instead of cancelling or duplicating it.
  4. When the reader reaches within two pages of chapter end (and Android is on an unmetered network), it warms the next chapter's manifest and page 1 with identical bucketed dimensions.

On chapter tap, Compose's sharedBounds animates only the chapter title container over 220 ms (disabled automatically when Reduce motion or zero system animator scale is active). Chapter rows never hold thumbnails or trigger page decodes.

4. Compacted History & Fractional Webtoon Checkpoints

Inside manga details, readers need status on every chapter (Resume Ch. X or Read next chapter). On the global History tab, showing ten consecutive chapters for the same series crowds out every other title.

ReadingHistory.listRecent compacts rows per (source_id, manga_id) in SQLite while keeping per-chapter checkpoints intact in reading_history:

SELECT source_id, manga_id, chapter_id, manga_title, chapter_title, page_index, page_count, offset_fraction, completed, updated_at_ms, cover_url FROM ( SELECT *, ROW_NUMBER() OVER ( PARTITION BY source_id, manga_id ORDER BY updated_at_ms DESC, rowid DESC ) AS rn FROM reading_history ) WHERE rn = 1 ORDER BY updated_at_ms DESC, source_id ASC, manga_id ASC, chapter_id ASC LIMIT ? OFFSET ? 

In Webtoon mode, checkpoints save page_index plus offset_fraction (how far past the top edge of that strip the viewport scrolled). Writes flush immediately on completion, every 2 seconds during continuous scrolling, and 750 ms after motion settles.

Mobile Sources, Browse, Details, Webtoon Reader, and History screens

5. Handling CORS on the wasmJs Build

Upstream image CDNs do not send CORS headers, so wasmJs running in a browser cannot fetch() covers or chapter images directly.

Rather than adding proxy flags to native Android or Desktop builds, webApp routes requests through two Cloudflare Pages Functions deployed alongside dist/web:

  • functions/api/[[path]].js forwards API calls to https://api.fmo.qzz.io/ on the same origin.
  • functions/img.js validates https:// target URLs, checks content-type.startsWith("image/"), caps payloads at 20 MiB, and returns cache-control: public, max-age=31536000, immutable with access-control-allow-origin: *.

Kotlin/Wasm web build running on desktop viewport

Try It or Build from Source

The v1.0.1 release builds are stripped and packaged automatically via ./scripts/release.sh and GitHub Actions:

  • Android: 7.2 MiB signed R8-shrunk APK
  • Desktop: 47.0 MiB executable JAR (Java 21+) or 76.5 MiB Linux x64 jpackage bundle
  • Web (wasmJs): Live in browser at app.fmo.qzz.io
# Run shared unit & integration tests (Android, JVM, Wasm) ./kotlin test -m shared # Launch Desktop with Compose Hot Reload ./kotlin run -m desktopApp --compose-hot-reload # Build the WebAssembly bundle into dist/web ./scripts/build-web.sh 

Browse all screenshots, release artifacts, and checksums at https://masfana.github.io/FanaCumik-App/.

原文:https://www.a8q9.cn/en/article/shipping-a-manga-webtoon-reader-to-android-desktop-and-kotlin-wasm-from-one-comp-4535df.html

相关文章