feat: display no results when profile field empty

This commit is contained in:
CMK 2022-02-14 16:22:03 +08:00
parent 66c1b71610
commit 0f3764e3af
3 changed files with 27 additions and 0 deletions

View File

@ -14,6 +14,7 @@ enum ProfileFieldItem: Hashable {
case field(field: FieldValue)
case editField(field: FieldValue)
case addEntry
case noResult
}
extension ProfileFieldItem {

View File

@ -107,6 +107,22 @@ extension ProfileFieldSection {
cell.backgroundConfiguration = backgroundConfiguration
}
let noResultCellRegistration = UICollectionView.CellRegistration<UICollectionViewListCell, ProfileFieldItem> { cell, indexPath, item in
guard case .noResult = item else { return }
var contentConfiguration = cell.defaultContentConfiguration()
contentConfiguration.text = L10n.Scene.Search.Searching.EmptyState.noResults // FIXME:
contentConfiguration.textProperties.alignment = .center
cell.contentConfiguration = contentConfiguration
var backgroundConfiguration = UIBackgroundConfiguration.listPlainCell()
backgroundConfiguration.backgroundColorTransformer = .init { _ in
return .secondarySystemBackground
}
cell.backgroundConfiguration = backgroundConfiguration
}
let dataSource = UICollectionViewDiffableDataSource<ProfileFieldSection, ProfileFieldItem>(collectionView: collectionView) { collectionView, indexPath, item in
switch item {
case .field:
@ -127,6 +143,12 @@ extension ProfileFieldSection {
for: indexPath,
item: item
)
case .noResult:
return collectionView.dequeueConfiguredReusableCell(
using: noResultCellRegistration,
for: indexPath,
item: item
)
}
}

View File

@ -74,6 +74,10 @@ extension ProfileAboutViewModel {
items.append(.addEntry)
}
if !isEditing, items.isEmpty {
items.append(.noResult)
}
snapshot.appendItems(items, toSection: .main)
diffableDataSource.apply(snapshot, animatingDifferences: false, completion: nil)