ReadViewSDK/Sources/RDReaderView/EPUBCore/RDEPUBNavigatorLayoutContext.swift
shenlei d0efe3f2cc 安全区域改为从 key window 动态获取
- 新增 RDEPUBSafeArea:参考 GKNavigationBarSwift 的 keyWindow 三级查找与临时 window 兜底
- 移除 reflowableContentInsets 中 top/bottom 40 的固定默认值,改按设备真实安全区生成
- 各取安全区处的 ?? .zero 兜底改为回退到 key window 值
- DEBUG 构建下为文本可读区域绘制红色边框,方便查看排版范围

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-06 15:04:22 +09:00

59 lines
2.2 KiB
Swift

import UIKit
public struct RDEPUBNavigatorLayoutContext: Equatable {
public var containerSize: CGSize
public var pagesPerScreen: Int
public var safeAreaInsets: UIEdgeInsets
public var userInterfaceIdiom: UIUserInterfaceIdiom
public var reflowableContentInsets: UIEdgeInsets
public init(
containerSize: CGSize,
pagesPerScreen: Int = 1,
safeAreaInsets: UIEdgeInsets = .zero,
userInterfaceIdiom: UIUserInterfaceIdiom = .phone,
reflowableContentInsets: UIEdgeInsets = RDEPUBSafeArea.defaultReflowableContentInsets()
) {
self.containerSize = containerSize
self.pagesPerScreen = max(1, pagesPerScreen)
self.safeAreaInsets = safeAreaInsets
self.userInterfaceIdiom = userInterfaceIdiom
self.reflowableContentInsets = reflowableContentInsets
}
public var viewportSize: CGSize {
let width: CGFloat
if pagesPerScreen > 1 {
width = containerSize.width / CGFloat(pagesPerScreen)
} else {
width = containerSize.width
}
return CGSize(width: width, height: containerSize.height)
}
/// Content insets that account for safe area (Dynamic Island / notch) on iPhone.
/// Uses the larger of safeAreaInsets and reflowableContentInsets for top/bottom
/// to ensure content is never hidden under the Dynamic Island or home indicator.
public var safeReflowableContentInsets: UIEdgeInsets {
let top = max(safeAreaInsets.top, reflowableContentInsets.top)
let bottom = max(safeAreaInsets.bottom, reflowableContentInsets.bottom)
let left = max(safeAreaInsets.left, reflowableContentInsets.left)
let right = max(safeAreaInsets.right, reflowableContentInsets.right)
return UIEdgeInsets(top: top, left: left, bottom: bottom, right: right)
}
/// Fixed layout content insets that respect safe areas on all devices including iPhone.
public var fixedContentInset: UIEdgeInsets {
var insets = safeAreaInsets
let horizontalInsets = max(insets.left, insets.right)
insets.left = horizontalInsets
insets.right = horizontalInsets
return insets
}
}