fix: searchTextField cover by keyboard issue. resolve #375

This commit is contained in:
CMK 2022-04-18 18:11:31 +08:00
parent c9a8834ff7
commit a9a83315b2
2 changed files with 11 additions and 23 deletions

View File

@ -12,6 +12,7 @@ import GameController
import AuthenticationServices import AuthenticationServices
import MastodonAsset import MastodonAsset
import MastodonLocalization import MastodonLocalization
import MastodonUI
final class MastodonPickServerViewController: UIViewController, NeedsDependency { final class MastodonPickServerViewController: UIViewController, NeedsDependency {
@ -145,6 +146,13 @@ extension MastodonPickServerViewController {
pickServerCellDelegate: self pickServerCellDelegate: self
) )
KeyboardResponderService
.configure(
scrollView: tableView,
layoutNeedsUpdate: viewModel.viewDidAppear.eraseToAnyPublisher()
)
.store(in: &disposeBag)
viewModel viewModel
.selectedServer .selectedServer
.map { $0 != nil } .map { $0 != nil }
@ -238,6 +246,7 @@ extension MastodonPickServerViewController {
super.viewDidAppear(animated) super.viewDidAppear(animated)
tableView.flashScrollIndicators() tableView.flashScrollIndicators()
viewModel.viewDidAppear.send()
} }
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
@ -416,28 +425,6 @@ extension MastodonPickServerViewController: UITableViewDelegate {
viewModel.selectedServer.send(nil) viewModel.selectedServer.send(nil)
} }
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
guard let diffableDataSource = viewModel.diffableDataSource else { return }
guard let item = diffableDataSource.itemIdentifier(for: indexPath) else { return }
switch item {
// case .categoryPicker:
// guard let cell = cell as? PickServerCategoriesCell else { return }
// guard let diffableDataSource = cell.diffableDataSource else { return }
// let snapshot = diffableDataSource.snapshot()
//
// let item = viewModel.selectCategoryItem.value
// guard let section = snapshot.indexOfSection(.main),
// let row = snapshot.indexOfItem(item) else { return }
// cell.collectionView.selectItem(at: IndexPath(item: row, section: section), animated: false, scrollPosition: .centeredHorizontally)
// case .search:
// guard let cell = cell as? PickServerSearchCell else { return }
// cell.searchTextField.text = viewModel.searchText.value
default:
break
}
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
guard let diffableDataSource = viewModel.diffableDataSource else { return nil } guard let diffableDataSource = viewModel.diffableDataSource else { return nil }
let snapshot = diffableDataSource.snapshot() let snapshot = diffableDataSource.snapshot()

View File

@ -45,6 +45,7 @@ class MastodonPickServerViewModel: NSObject {
let indexedServers = CurrentValueSubject<[Mastodon.Entity.Server], Never>([]) let indexedServers = CurrentValueSubject<[Mastodon.Entity.Server], Never>([])
let unindexedServers = CurrentValueSubject<[Mastodon.Entity.Server]?, Never>([]) // set nil when loading let unindexedServers = CurrentValueSubject<[Mastodon.Entity.Server]?, Never>([]) // set nil when loading
let viewWillAppear = PassthroughSubject<Void, Never>() let viewWillAppear = PassthroughSubject<Void, Never>()
let viewDidAppear = CurrentValueSubject<Void, Never>(Void())
// output // output
var diffableDataSource: UITableViewDiffableDataSource<PickServerSection, PickServerItem>? var diffableDataSource: UITableViewDiffableDataSource<PickServerSection, PickServerItem>?