feat: reintroduce scrolling

This commit was merged in pull request #9.
This commit is contained in:
2026-07-09 22:56:57 +02:00
parent dcb26e47b4
commit be5e513cbc
+39 -16
View File
@@ -59,8 +59,6 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
var scrollPos: CGPoint!
var hasSetContentOffset = false
var pageCount = 0
var pagesAvailable = 0
var chapterAndPages: [(Int, Int)] = []
var imageView = UIImageView()
var mode = PageTurnMode.leftToRight
@@ -136,9 +134,9 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
readerView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
readerView.widthAnchor.constraint(equalTo: view.widthAnchor),
])
setupScrollingCollectionView()
loadComics()
setupImageView()
setupScrollingCollectionView()
setupGestures()
setupBar()
setupHomeView()
@@ -594,7 +592,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
}
if let indexPath = scrollingCollectionView.indexPathForItem(at: scrollOffset) {
var theProgress = ProgressIndices(v: 0, c: 0, i: 0)
for _ in 0 ... indexPath.item {
for _ in 0 ..< indexPath.item {
theProgress = getProgressIndicesFromTurn(
turn: .next, progress: theProgress
)
@@ -632,9 +630,11 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
)
if let indexPath = scrollingCollectionView.indexPathForItem(at: centerPoint) {
let (chapter, page) = chapterAndPages[indexPath.item]
progress.c = chapter
progress.i = page
var newProgress = ProgressIndices(v: 0, c: 0, i: 0)
for _ in 0 ..< indexPath.item {
newProgress = getProgressIndicesFromTurn(turn: .next, progress: newProgress)
}
progress = newProgress
}
if scrollingCollectionView.isHidden == false {
saveLocalState()
@@ -694,7 +694,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
leftView.isHidden = true
rightView.isHidden = true
scrollingCollectionView.isHidden = false
// TODO: Fix scrolling again
scrollingCollectionView.reloadData()
}
func countFiles() -> Int {
@@ -1028,6 +1028,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
scrollingCollectionView.isHidden = mode != .scroll
leftView.isHidden = mode == .scroll
rightView.isHidden = mode == .scroll
imageView.isHidden = mode == .scroll
togglePageTurnDropdown()
saveLocalState()
}
@@ -1161,7 +1162,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
self?.updateInfo()
}
for _ in 0 ... preloadCount {
for _ in 0 ..< preloadCount {
newProgress = getProgressIndicesFromTurn(turn: .next, progress: newProgress)
let path = getImagePath(progress: newProgress)
imageLoader.preloadImage(at: path, scaling: scaling, screenSize: UIScreen.main.bounds.size)
@@ -1302,7 +1303,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
}
var newProgress = progress
for _ in 0 ... preloadCount {
for _ in 0 ..< preloadCount {
newProgress = getProgressIndicesFromTurn(turn: .next, progress: newProgress)
imageLoader.preloadImage(at: getImagePath(progress: newProgress), scaling: scaling, screenSize: UIScreen.main.bounds.size)
}
@@ -1375,7 +1376,13 @@ extension ViewController: UICollectionViewDataSource, UICollectionViewDelegateFl
if collectionView == comicCollectionView {
return comics.count
} else {
return pagesAvailable
var sum = 0
for volume in metadata.volumes {
for chapter in volume.chapters {
sum += chapter.images.count
}
}
return sum
}
}
@@ -1391,16 +1398,25 @@ extension ViewController: UICollectionViewDataSource, UICollectionViewDelegateFl
cell.imageView.image = comics[indexPath.item].cover
return cell
} else if collectionView == scrollingCollectionView {
// let scaling = UIView.ContentMode.scaleAspectFill
let scaling = UIView.ContentMode.scaleAspectFill
let cell =
collectionView.dequeueReusableCell(
withReuseIdentifier: "ScrollingImageCell", for: indexPath
)
as! ScrollingImageCell
if metadata == nil {
print("metadata is nil, should probably not be the case")
return cell
}
// TODO: Fix scrolling again
var newProgress = ProgressIndices(v: 0, c: 0, i: 0)
if indexPath.item != 0 {
for _ in 0 ..< indexPath.item {
newProgress = getProgressIndicesFromTurn(turn: .next, progress: newProgress)
}
}
imageLoader.loadImage(at: getImagePath(progress: newProgress), scaling: scaling, screenSize: UIScreen.main.bounds.size) { image in
cell.imageView.image = image
}
return cell
} else {
assertionFailure()
@@ -1417,7 +1433,7 @@ extension ViewController: UICollectionViewDataSource, UICollectionViewDelegateFl
func collectionView(
_ collectionView: UICollectionView,
layout _: UICollectionViewLayout,
sizeForItemAt _: IndexPath
sizeForItemAt indexPath: IndexPath
) -> CGSize {
if collectionView == comicCollectionView {
let spacing: CGFloat = 8
@@ -1429,8 +1445,15 @@ extension ViewController: UICollectionViewDataSource, UICollectionViewDelegateFl
if metadata == nil {
return CGSize()
}
// TODO: Fix scrolling again
return CGSize()
var newProgress = ProgressIndices(v: 0, c: 0, i: 0)
for _ in 0 ..< indexPath.item {
newProgress = getProgressIndicesFromTurn(turn: .next, progress: newProgress)
}
let imageMetadata = metadata.volumes[newProgress.v].chapters[newProgress.c].images[newProgress.i]
return CGSize(
width: readerView.bounds.width,
height: CGFloat(imageMetadata.size!.height) * readerView.bounds.width / CGFloat(imageMetadata.size!.width)
)
} else {
assertionFailure()
}