49 lines
2.1 KiB
Swift
49 lines
2.1 KiB
Swift
|
|
import UIKit
|
|
|
|
extension RDEpubReaderView: UICollectionViewDataSource, RDEpubReaderFlowLayoutDelegate, RDEpubReaderFlowLayoutDataSoure {
|
|
|
|
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
|
|
if let identifer = pageReuseIdentifier(for: indexPath.row) {
|
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifer, for: IndexPath(item: indexPath.row, section: 0)) as! RDEpubReaderContentCell
|
|
let preloadedView = preloadController.takePreloadedView(for: indexPath.row)
|
|
let reusableView = cell.containerView ?? preloadedView
|
|
let contentView = contentViewForPage(indexPath.row, reusableView: reusableView)
|
|
(contentView as? RDEpubReaderPageVisibilityHandling)?
|
|
.readerPageVisibilityDidChange(isVisible: false)
|
|
cell.containerView = contentView
|
|
DispatchQueue.main.async { [weak self] in
|
|
self?.updatePageContentVisibility()
|
|
}
|
|
|
|
if pageDirection == .rightToLeft && currentDisplayType != .verticalScroll {
|
|
cell.contentView.transform = CGAffineTransform(scaleX: -1, y: 1)
|
|
} else {
|
|
cell.contentView.transform = .identity
|
|
}
|
|
return cell
|
|
}
|
|
|
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: NSStringFromClass(UICollectionViewCell.self), for: indexPath)
|
|
|
|
return cell
|
|
}
|
|
|
|
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
return numberOfPages()
|
|
}
|
|
|
|
public func pageNum(flowLayout: RDEpubReaderFlowLayout, pageIndex: Int) {
|
|
if currentPage >= 0, currentPage != pageIndex {
|
|
predictedPageDirection = pageIndex >= currentPage
|
|
}
|
|
currentPage = pageIndex
|
|
primePageCache(around: pageIndex, preferredForward: predictedPageDirection)
|
|
}
|
|
|
|
public func heigtOfVerticalScrollPage(flowLayout: RDEpubReaderFlowLayout, pageIndex: Int) -> CGFloat? {
|
|
return nil
|
|
}
|
|
}
|