Skip to content

Commit

Permalink
Properly close PDF Reader when switching current open item
Browse files Browse the repository at this point in the history
  • Loading branch information
mvasilak committed May 7, 2024
1 parent 3ce985d commit edc63ec
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Zotero/Scenes/Detail/PDF/Views/PDFReaderViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,12 @@ class PDFReaderViewController: UIViewController {
self?.coordinatorDelegate
},
completion: { [weak self] changedCurrentItem, openItemsChanged in
guard let self, !changedCurrentItem && openItemsChanged else { return }
openItemsController.setOpenItemsUserActivity(from: self, libraryId: viewModel.state.library.identifier, title: viewModel.state.displayTitle)
guard let self else { return }
if changedCurrentItem {
close(dismiss: false)
} else if openItemsChanged {
openItemsController.setOpenItemsUserActivity(from: self, libraryId: viewModel.state.library.identifier, title: viewModel.state.displayTitle)
}
}
)
let openItemsMenu = UIMenu(title: L10n.Accessibility.Pdf.openItems, options: [.displayInline], children: [deferredOpenItemsMenuElement])
Expand Down Expand Up @@ -309,7 +313,7 @@ class PDFReaderViewController: UIViewController {
let closeButton = UIBarButtonItem(image: UIImage(systemName: "chevron.left"), style: .plain, target: nil, action: nil)
closeButton.title = L10n.close
closeButton.accessibilityLabel = L10n.close
closeButton.rx.tap.subscribe(onNext: { [weak self] _ in self?.close() }).disposed(by: disposeBag)
closeButton.rx.tap.subscribe(onNext: { [weak self] _ in self?.close(dismiss: true) }).disposed(by: disposeBag)

let readerButton = UIBarButtonItem(image: Asset.Images.pdfRawReader.image, style: .plain, target: nil, action: nil)
readerButton.isEnabled = !viewModel.state.document.isLocked
Expand Down Expand Up @@ -657,12 +661,13 @@ class PDFReaderViewController: UIViewController {
.disposed(by: disposeBag)
}

private func close() {
private func close(dismiss: Bool) {
if let page = documentController?.pdfController?.pageIndex {
viewModel.process(action: .submitPendingPage(Int(page)))
}
viewModel.process(action: .changeIdleTimerDisabled(false))
viewModel.process(action: .clearTmpData)
guard dismiss else { return }
navigationController?.presentingViewController?.dismiss(animated: true, completion: nil)
}

Expand Down

0 comments on commit edc63ec

Please sign in to comment.