Merge pull request #832 from kiwix/831-fix-ui-warning-of-tab-reconfiguration-plus-improve-the-look-of-icons

Fix tab cell recycle, and favicon look for dark mode
This commit is contained in:
Kelson 2024-06-23 17:27:52 +02:00 committed by GitHub
commit ab96882dca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 9 deletions

View File

@ -160,9 +160,7 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
to: .tabs,
animatingDifferences: dataSource.snapshot(for: .tabs).items.count > 0
) {
// [iOS 15] when a tab is selected, reload it to refresh title and icon
guard #unavailable(iOS 16),
let indexPath = self.collectionView.indexPathsForSelectedItems?.first,
guard let indexPath = self.collectionView.indexPathsForSelectedItems?.first,
let item = self.dataSource.itemIdentifier(for: indexPath),
case .tab = item else { return }
var snapshot = self.dataSource.snapshot()
@ -190,9 +188,21 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
private func configureCell(cell: UICollectionViewListCell, indexPath: IndexPath, item: NavigationItem) {
if case let .tab(objectID) = item, let tab = try? Database.viewContext.existingObject(with: objectID) as? Tab {
cell.contentConfiguration = UIHostingConfiguration {
TabLabel(tab: tab)
var config = cell.defaultContentConfiguration()
config.text = tab.title ?? "common.tab.menu.new_tab".localized
if let zimFile = tab.zimFile, let category = Category(rawValue: zimFile.category) {
config.textProperties.numberOfLines = 1
if let imgData = zimFile.faviconData {
config.image = UIImage(data: imgData)
} else {
config.image = UIImage(named: category.icon)
}
config.imageProperties.maximumSize = CGSize(width: 22, height: 22)
config.imageProperties.cornerRadius = 3
} else {
config.image = UIImage(systemName: "square")
}
cell.contentConfiguration = config
} else {
var config = cell.defaultContentConfiguration()
config.text = item.name

View File

@ -28,10 +28,7 @@ struct Favicon: View {
}
var body: some View {
ZStack(alignment: .center) {
Color.white.clipShape(RoundedRectangle(cornerRadius: 3, style: .continuous))
image.scaledToFit().cornerRadius(2).padding(1)
}
image.scaledToFit().cornerRadius(3)
.aspectRatio(1, contentMode: .fit)
.onAppear {
guard let imageURL = imageURL, imageData == nil else { return }