fix: avoid crashing from nil values
This commit is contained in:
@@ -124,15 +124,17 @@ final class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
if let alert = pendingAlert {
|
||||
present(alert, animated: false, completion: nil)
|
||||
}
|
||||
if !hasSetContentOffset, let scrollPos = state[currentPath.lastPathComponent]?.scrollPos {
|
||||
if !hasSetContentOffset && scrollingCollectionView != nil {
|
||||
guard let path = currentPath else { return }
|
||||
guard let state = state[path.lastPathComponent] else { return }
|
||||
let screenSize = UIScreen.main.bounds.size
|
||||
var offset = scrollPos
|
||||
var offset = state.scrollPos
|
||||
if screenSize.width > screenSize.height {
|
||||
offset.y *= (screenSize.width / screenSize.height)
|
||||
}
|
||||
scrollingCollectionView.setContentOffset(offset, animated: false)
|
||||
hasSetContentOffset = true
|
||||
} else {
|
||||
} else if scrollingCollectionView != nil {
|
||||
let screenSize = UIScreen.main.bounds.size
|
||||
var offset = scrollingCollectionView.contentOffset
|
||||
offset.y *= (screenSize.width / screenSize.height)
|
||||
@@ -268,8 +270,8 @@ final class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
&& isDirectory.boolValue
|
||||
}.sorted { $0.path < $1.path }
|
||||
|
||||
for dir in directories {
|
||||
queue.async { [self] in
|
||||
queue.async { [self] in
|
||||
for dir in directories {
|
||||
if !fileManager.fileExists(atPath: dir.appendingPathComponent(metadataFilename).path) {
|
||||
getMetadataFromFilename(path: dir)
|
||||
if pendingAlert != nil {
|
||||
@@ -885,6 +887,7 @@ final class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
override func viewDidLayoutSubviews() {
|
||||
super.viewDidLayoutSubviews()
|
||||
guard view.bounds.size != lastLayoutSize else { return }
|
||||
if scrollingCollectionView == nil { return }
|
||||
lastLayoutSize = UIScreen.main.bounds.size
|
||||
if scrollingCollectionView.isHidden
|
||||
|| getMode() != .scroll
|
||||
|
||||
Reference in New Issue
Block a user