3.4 KiB
3.4 KiB
Phase 6: 页面几何与交互命中层 - Research
Date: 2026-05-22 Phase: 6
Research Question
What do we need to know to plan page geometry and interaction hit handling well for the native text path?
Current State
Sources/RDReaderView/EPUBUI/RDEPUBTextContentView.swiftstill renders native text throughUITextViewand derives selection fromselectedRange.RDEPUBTextContentViewcurrently converts the selected range intoRDEPUBSelectionby using page-relative offsets plusRDEPUBTextOffsetRangeInfoabsolute offsets.Sources/RDReaderView/EPUBUI/RDEPUBReaderController.swiftnormalizes selections, persists them, and remains the central coordination point for reader interactions.Sources/RDReaderView/EPUBTextRendering/RDEPUBTextLayouter.swiftalready computes page boundaries, break reasons, block ranges, attachment ranges, and trailing fragment IDs from CoreText frames.Sources/RDReaderView/EPUBTextRendering/RDEPUBTextLayoutFrame.swiftis currently only a metadata wrapper aroundcontentRangeplus pagination diagnostics.Sources/RDReaderView/EPUBTextRendering/RDEPUBTextBookBuilder.swiftpreserves absolute offsets, page continuity, and fragment offsets when assemblingRDEPUBTextBook.Sources/RDReaderView/EPUBCore/RDEPUBReadingModels.swiftalready keeps the offset-based reader contract alive throughpageStartOffset,pageEndOffset,fragmentOffsets, andRDEPUBTextOffsetRangeInfo.
What This Means
- The missing abstraction is a page-level geometry layer, not a new pagination pipeline.
- The right insertion point is beside the layout frame / pagination code, because that layer already knows page boundaries and fragment continuity.
- Selection should move first because the current user decision explicitly made selection the primary migrated interaction chain.
custom overlayis the right display model for Phase 6 becauseUITextViewselection visuals are still the black-box dependency we are trying to reduce.- Precision target should be glyph-level or fragment-level geometry, with the existing offset contract kept as the compatibility anchor.
Recommended Planning Shape
- Plan 06-01: add page geometry query APIs to the page frame / book layer.
- Plan 06-02: move selection presentation and hit handling onto a custom overlay while keeping offset-based selection data intact.
- Plan 06-03: verify selection geometry, offset continuity, and restore/search/highlight compatibility across the existing sample books.
Technical Risks
UITextViewcan provide selection behavior, but it is not a reliable source for a stable custom overlay pipeline if the overlay needs richer glyph-level rects.- If geometry is bolted into the reader controller, the phase will become a UI-layer patch instead of a reusable page geometry layer.
- Any new geometry result must remain consumable by future
search,highlight, andtap locatework without re-deriving offsets or page boundaries.
Validation Implications
- There is no dedicated test target in the repo, so plan verification will need to rely on simulator build/run plus observable runtime behavior.
- The phase should define concrete UI and log checks for selection overlay behavior, offset preservation, and current-location compatibility.
- The verification strategy should keep one manual check for glyph-level selection/overlay behavior because that is the user-visible risk area for this phase.