ReadViewSDK/Sources/RDEpubReaderView/EPUBCore/RDEPUBNavigatorLayoutContext.swift
shenlei d7fcda345d refactor: rename RDReaderView -> RDEpubReaderView, update pod config and docs
- Rename source module from RDReaderView to RDEpubReaderView
- Move all source files from Sources/RDReaderView/ to Sources/RDEpubReaderView/
- Update podspec: RDReaderView.podspec -> RDEpubReaderView.podspec
- Update Podfile, demo project, and CocoaPods config for new pod name
- Delete old RDReaderView pod support files from ReadViewDemo/Pods
- Add new RDEpubReaderView pod support files
- Update documentation (API ref, architecture, UML, conventions, etc.)
- Add FixedLayoutRotationTests
- Update .gitignore: exclude .DS_Store, manual unpack backups, _ssoft-output
2026-07-10 19:44:53 +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
}
}