Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed dynamic type issue with items list title #770

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Zotero/Scenes/Detail/Items/Models/ItemsAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enum ItemsAction {
case addAttachments([URL])
case assignItemsToCollections(items: Set<String>, collections: Set<String>)
case cacheItemTitle(key: String, title: String)
case clearTitleCache
case deleteItemsFromCollection(Set<String>)
case deleteItems(Set<String>)
case deselectItem(String)
Expand Down
5 changes: 3 additions & 2 deletions Zotero/Scenes/Detail/Items/Models/ItemsState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ struct ItemsState: ViewModelState {

let collection: Collection
let library: Library
let itemTitleFont: UIFont

var sortType: ItemsSortType
var searchTerm: String?
Expand All @@ -64,6 +63,9 @@ struct ItemsState: ViewModelState {
var bibliographyError: Error?
var attachmentToOpen: String?
var downloadBatchData: DownloadBatchData?
var itemTitleFont: UIFont {
return UIFont.preferredFont(for: .headline, weight: .regular)
}

var tagsFilter: Set<String>? {
let tagFilter = self.filters.first(where: { filter in
Expand Down Expand Up @@ -92,7 +94,6 @@ struct ItemsState: ViewModelState {
self.searchTerm = searchTerm
self.processingBibliography = false
self.itemTitles = [:]
self.itemTitleFont = UIFont.preferredFont(for: .headline, weight: .regular)
}

mutating func cleanup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ struct ItemsActionHandler: ViewModelActionHandler, BackgroundDbProcessingActionH
self.update(viewModel: viewModel) { state in
state.itemTitles[key] = self.htmlAttributedStringConverter.convert(text: title, baseAttributes: [.font: state.itemTitleFont])
}

case .clearTitleCache:
self.update(viewModel: viewModel) { state in
state.itemTitles = [:]
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions Zotero/Scenes/Detail/Items/Views/ItemsTableViewHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,10 @@ final class ItemsTableViewHandler: NSObject {
cell.set(accessory: self.cellAccessory(from: accessory))
}

func reloadAll(snapshot: Results<RItem>) {
self.snapshot = snapshot
func reloadAll(snapshot: Results<RItem>? = nil) {
if let snapshot {
self.snapshot = snapshot
}
self.tableView.reloadData()
}

Expand Down
14 changes: 12 additions & 2 deletions Zotero/Scenes/Detail/Items/Views/ItemsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -521,12 +521,22 @@ final class ItemsViewController: UIViewController {
.rx
.notification(.willEnterForeground)
.observe(on: MainScheduler.instance)
.subscribe(onNext: { [weak self] _ in
guard let self = self, self.searchBarNeedsReset else { return }
.subscribe(with: self, onNext: { `self`, _ in
guard self.searchBarNeedsReset else { return }
self.resetSearchBar()
self.searchBarNeedsReset = false
})
.disposed(by: self.disposeBag)

NotificationCenter.default
.rx
.notification(UIContentSizeCategory.didChangeNotification)
.observe(on: MainScheduler.instance)
.subscribe(with: self, onNext: { `self`, _ in
self.viewModel.process(action: .clearTitleCache)
self.tableViewHandler.reloadAll()
})
.disposed(by: self.disposeBag)
}

private func setupFileObservers() {
Expand Down
Loading