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
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>!
init(context: AppContext) {
@ -34,16 +35,16 @@ final class AccountListViewModel {
.sink { [weak self] authentications, activeAuthentication in
guard let self = self else { return }
var items: [Item] = []
var activeUserID: Mastodon.Entity.Account.ID?
var activeMastodonUserObjectID: NSManagedObjectID?
for authentication in authentications {
let item = Item.authentication(objectID: authentication.objectID)
items.append(item)
if authentication === activeAuthentication {
activeUserID = authentication.userID
activeMastodonUserObjectID = authentication.user.objectID
}
}
self.authentications.value = items
self.activeUserID.value = activeUserID
self.activeMastodonUserObjectID.value = activeMastodonUserObjectID
}
.store(in: &disposeBag)
@ -58,7 +59,9 @@ final class AccountListViewModel {
snapshot.appendItems(authentications, toSection: .main)
snapshot.appendItems([.addAccount], toSection: .main)
diffableDataSource.apply(snapshot)
diffableDataSource.apply(snapshot) {
self.dataSourceDidUpdate.send()
}
}
.store(in: &disposeBag)
}
@ -88,7 +91,7 @@ extension AccountListViewModel {
AccountListViewModel.configure(
cell: cell,
user: user,
activeUserID: self.activeUserID.eraseToAnyPublisher()
activeMastodonUserObjectID: self.activeMastodonUserObjectID.eraseToAnyPublisher()
)
return cell
case .addAccount:
@ -105,7 +108,7 @@ extension AccountListViewModel {
static func configure(
cell: AccountListTableViewCell,
user: MastodonUser,
activeUserID: AnyPublisher<Mastodon.Entity.Account.ID?, Never>
activeMastodonUserObjectID: AnyPublisher<NSManagedObjectID?, Never>
) {
// avatar
cell.configure(with: AvatarConfigurableViewConfiguration(avatarImageURL: user.avatarImageURL()))
@ -125,10 +128,10 @@ extension AccountListViewModel {
cell.usernameLabel.configure(content: usernameMetaContent)
// checkmark
activeUserID
activeMastodonUserObjectID
.receive(on: DispatchQueue.main)
.sink { userID in
let isCurrentUser = user.id == userID
.sink { objectID in
let isCurrentUser = user.objectID == objectID
cell.tintColor = .label
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(AddAccountTableViewCell.self, forCellReuseIdentifier: String(describing: AddAccountTableViewCell.self))
tableView.backgroundColor = .clear
tableView.tableFooterView = UIView()
tableView.separatorStyle = .none
tableView.tableFooterView = UIView()
return tableView
}()
@ -97,6 +97,14 @@ extension AccountListViewController {
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 {
let dragIndicatorTapGestureRecognizer = UITapGestureRecognizer.singleTapGestureRecognizer
dragIndicatorView.addGestureRecognizer(dragIndicatorTapGestureRecognizer)