Do the keyboard-dance (#540)
This commit is contained in:
parent
f293d17884
commit
e7b8870329
|
@ -19,6 +19,7 @@ class MastodonLoginView: UIView {
|
||||||
let tableView: UITableView
|
let tableView: UITableView
|
||||||
private var tableViewWrapper: UIView
|
private var tableViewWrapper: UIView
|
||||||
let navigationActionView: NavigationActionView
|
let navigationActionView: NavigationActionView
|
||||||
|
var bottomConstraint: NSLayoutConstraint?
|
||||||
|
|
||||||
override init(frame: CGRect) {
|
override init(frame: CGRect) {
|
||||||
|
|
||||||
|
@ -50,6 +51,7 @@ class MastodonLoginView: UIView {
|
||||||
tableView = ContentSizedTableView()
|
tableView = ContentSizedTableView()
|
||||||
tableView.translatesAutoresizingMaskIntoConstraints = false
|
tableView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
tableView.backgroundColor = Asset.Scene.Onboarding.textFieldBackground.color
|
tableView.backgroundColor = Asset.Scene.Onboarding.textFieldBackground.color
|
||||||
|
tableView.keyboardDismissMode = .onDrag
|
||||||
|
|
||||||
tableViewWrapper = UIView()
|
tableViewWrapper = UIView()
|
||||||
tableViewWrapper.translatesAutoresizingMaskIntoConstraints = false
|
tableViewWrapper.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
@ -77,6 +79,9 @@ class MastodonLoginView: UIView {
|
||||||
}
|
}
|
||||||
|
|
||||||
private func setupConstraints() {
|
private func setupConstraints() {
|
||||||
|
|
||||||
|
let bottomConstraint = safeAreaLayoutGuide.bottomAnchor.constraint(equalTo: navigationActionView.bottomAnchor)
|
||||||
|
|
||||||
let constraints = [
|
let constraints = [
|
||||||
|
|
||||||
headerStackView.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor),
|
headerStackView.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor),
|
||||||
|
@ -100,8 +105,10 @@ class MastodonLoginView: UIView {
|
||||||
|
|
||||||
navigationActionView.leadingAnchor.constraint(equalTo: leadingAnchor),
|
navigationActionView.leadingAnchor.constraint(equalTo: leadingAnchor),
|
||||||
navigationActionView.trailingAnchor.constraint(equalTo: trailingAnchor),
|
navigationActionView.trailingAnchor.constraint(equalTo: trailingAnchor),
|
||||||
bottomAnchor.constraint(equalTo: navigationActionView.bottomAnchor),
|
bottomConstraint,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
self.bottomConstraint = bottomConstraint
|
||||||
NSLayoutConstraint.activate(constraints)
|
NSLayoutConstraint.activate(constraints)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@ class MastodonLoginViewController: UIViewController {
|
||||||
viewModel.delegate = self
|
viewModel.delegate = self
|
||||||
|
|
||||||
navigationItem.hidesBackButton = true
|
navigationItem.hidesBackButton = true
|
||||||
|
//TODO: @zeitschlag consider keyboard, do the notification-dance
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||||||
|
@ -66,6 +67,9 @@ class MastodonLoginViewController: UIViewController {
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShowNotification(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHideNotification(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
|
||||||
|
|
||||||
let dataSource = UITableViewDiffableDataSource<MastodonLoginViewSection, Mastodon.Entity.Server>(tableView: contentView.tableView) { [weak self] tableView, indexPath, itemIdentifier in
|
let dataSource = UITableViewDiffableDataSource<MastodonLoginViewSection, Mastodon.Entity.Server>(tableView: contentView.tableView) { [weak self] tableView, indexPath, itemIdentifier in
|
||||||
guard let cell = tableView.dequeueReusableCell(withIdentifier: MastodonLoginServerTableViewCell.reuseIdentifier, for: indexPath) as? MastodonLoginServerTableViewCell,
|
guard let cell = tableView.dequeueReusableCell(withIdentifier: MastodonLoginServerTableViewCell.reuseIdentifier, for: indexPath) as? MastodonLoginServerTableViewCell,
|
||||||
let self = self else {
|
let self = self else {
|
||||||
|
@ -191,6 +195,36 @@ class MastodonLoginViewController: UIViewController {
|
||||||
contentView.navigationActionView.nextButton.isEnabled = false
|
contentView.navigationActionView.nextButton.isEnabled = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Notifications
|
||||||
|
@objc func keyboardWillShowNotification(_ notification: Notification) {
|
||||||
|
|
||||||
|
guard let userInfo = notification.userInfo,
|
||||||
|
let keyboardFrameValue = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue,
|
||||||
|
let duration = userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber
|
||||||
|
else { return }
|
||||||
|
|
||||||
|
let adjustmentHeight = keyboardFrameValue.cgRectValue.height - view.safeAreaInsets.bottom
|
||||||
|
contentView.bottomConstraint?.constant = adjustmentHeight
|
||||||
|
|
||||||
|
UIView.animate(withDuration: duration.doubleValue, delay: 0, options: .curveEaseInOut) {
|
||||||
|
self.view.layoutIfNeeded()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func keyboardWillHideNotification(_ notification: Notification) {
|
||||||
|
|
||||||
|
guard let userInfo = notification.userInfo,
|
||||||
|
let duration = userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber
|
||||||
|
else { return }
|
||||||
|
|
||||||
|
contentView.bottomConstraint?.constant = 0
|
||||||
|
|
||||||
|
UIView.animate(withDuration: duration.doubleValue, delay: 0, options: .curveEaseInOut) {
|
||||||
|
self.view.layoutIfNeeded()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - OnboardingViewControllerAppearance
|
// MARK: - OnboardingViewControllerAppearance
|
||||||
|
|
Loading…
Reference in New Issue