45 lines
1.5 KiB
Swift
45 lines
1.5 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 = UIEdgeInsets(top: 40, left: 16, bottom: 40, right: 16)
|
|
) {
|
|
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)
|
|
}
|
|
|
|
public var fixedContentInset: UIEdgeInsets {
|
|
var insets = safeAreaInsets
|
|
if userInterfaceIdiom != .phone {
|
|
insets = .zero
|
|
}
|
|
|
|
let horizontalInsets = max(insets.left, insets.right)
|
|
insets.left = horizontalInsets
|
|
insets.right = horizontalInsets
|
|
return insets
|
|
}
|
|
} |