fix: checkmark display logic and account list not scrollable in PanModal issue

This commit is contained in:
CMK 2021-09-16 12:23:47 +08:00
parent 76efa7162e
commit 7dea01da1e
2 changed files with 22 additions and 11 deletions

View File

@ -21,7 +21,8 @@ final class AccountListViewModel {
// output // output
let authentications = CurrentValueSubject<[Item], Never>([]) let authentications = CurrentValueSubject<[Item], Never>([])
let activeUserID = CurrentValueSubject<Mastodon.Entity.Account.ID?, Never>(nil) let activeMastodonUserObjectID = CurrentValueSubject<NSManagedObjectID?, Never>(nil)
let dataSourceDidUpdate = PassthroughSubject<Void, Never>()
var diffableDataSource: UITableViewDiffableDataSource<Section, Item>! var diffableDataSource: UITableViewDiffableDataSource<Section, Item>!
init(context: AppContext) { init(context: AppContext) {
@ -34,16 +35,16 @@ final class AccountListViewModel {
.sink { [weak self] authentications, activeAuthentication in .sink { [weak self] authentications, activeAuthentication in
guard let self = self else { return } guard let self = self else { return }
var items: [Item] = [] var items: [Item] = []
var activeUserID: Mastodon.Entity.Account.ID? var activeMastodonUserObjectID: NSManagedObjectID?
for authentication in authentications { for authentication in authentications {
let item = Item.authentication(objectID: authentication.objectID) let item = Item.authentication(objectID: authentication.objectID)
items.append(item) items.append(item)
if authentication === activeAuthentication { if authentication === activeAuthentication {
activeUserID = authentication.userID activeMastodonUserObjectID = authentication.user.objectID
} }
} }
self.authentications.value = items self.authentications.value = items
self.activeUserID.value = activeUserID self.activeMastodonUserObjectID.value = activeMastodonUserObjectID
} }
.store(in: &disposeBag) .store(in: &disposeBag)
@ -58,7 +59,9 @@ final class AccountListViewModel {
snapshot.appendItems(authentications, toSection: .main) snapshot.appendItems(authentications, toSection: .main)
snapshot.appendItems([.addAccount], toSection: .main) snapshot.appendItems([.addAccount], toSection: .main)
diffableDataSource.apply(snapshot) diffableDataSource.apply(snapshot) {
self.dataSourceDidUpdate.send()
}
} }
.store(in: &disposeBag) .store(in: &disposeBag)
} }
@ -88,7 +91,7 @@ extension AccountListViewModel {
AccountListViewModel.configure( AccountListViewModel.configure(
cell: cell, cell: cell,
user: user, user: user,
activeUserID: self.activeUserID.eraseToAnyPublisher() activeMastodonUserObjectID: self.activeMastodonUserObjectID.eraseToAnyPublisher()
) )
return cell return cell
case .addAccount: case .addAccount:
@ -105,7 +108,7 @@ extension AccountListViewModel {
static func configure( static func configure(
cell: AccountListTableViewCell, cell: AccountListTableViewCell,
user: MastodonUser, user: MastodonUser,
activeUserID: AnyPublisher<Mastodon.Entity.Account.ID?, Never> activeMastodonUserObjectID: AnyPublisher<NSManagedObjectID?, Never>
) { ) {
// avatar // avatar
cell.configure(with: AvatarConfigurableViewConfiguration(avatarImageURL: user.avatarImageURL())) cell.configure(with: AvatarConfigurableViewConfiguration(avatarImageURL: user.avatarImageURL()))
@ -125,10 +128,10 @@ extension AccountListViewModel {
cell.usernameLabel.configure(content: usernameMetaContent) cell.usernameLabel.configure(content: usernameMetaContent)
// checkmark // checkmark
activeUserID activeMastodonUserObjectID
.receive(on: DispatchQueue.main) .receive(on: DispatchQueue.main)
.sink { userID in .sink { objectID in
let isCurrentUser = user.id == userID let isCurrentUser = user.objectID == objectID
cell.tintColor = .label cell.tintColor = .label
cell.accessoryType = isCurrentUser ? .checkmark : .none cell.accessoryType = isCurrentUser ? .checkmark : .none
} }

View File

@ -38,8 +38,8 @@ final class AccountListViewController: UIViewController, NeedsDependency {
tableView.register(AccountListTableViewCell.self, forCellReuseIdentifier: String(describing: AccountListTableViewCell.self)) tableView.register(AccountListTableViewCell.self, forCellReuseIdentifier: String(describing: AccountListTableViewCell.self))
tableView.register(AddAccountTableViewCell.self, forCellReuseIdentifier: String(describing: AddAccountTableViewCell.self)) tableView.register(AddAccountTableViewCell.self, forCellReuseIdentifier: String(describing: AddAccountTableViewCell.self))
tableView.backgroundColor = .clear tableView.backgroundColor = .clear
tableView.tableFooterView = UIView()
tableView.separatorStyle = .none tableView.separatorStyle = .none
tableView.tableFooterView = UIView()
return tableView return tableView
}() }()
@ -97,6 +97,14 @@ extension AccountListViewController {
managedObjectContext: context.managedObjectContext managedObjectContext: context.managedObjectContext
) )
viewModel.dataSourceDidUpdate
.receive(on: DispatchQueue.main)
.sink { [weak self] in
guard let self = self else { return }
self.panModalSetNeedsLayoutUpdate()
}
.store(in: &disposeBag)
if UIAccessibility.isVoiceOverRunning { if UIAccessibility.isVoiceOverRunning {
let dragIndicatorTapGestureRecognizer = UITapGestureRecognizer.singleTapGestureRecognizer let dragIndicatorTapGestureRecognizer = UITapGestureRecognizer.singleTapGestureRecognizer
dragIndicatorView.addGestureRecognizer(dragIndicatorTapGestureRecognizer) dragIndicatorView.addGestureRecognizer(dragIndicatorTapGestureRecognizer)