From 83e0c0e994c9d135697b0147bf2fbe7c29ffde17 Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Tue, 15 Nov 2022 23:26:58 +0100 Subject: [PATCH] Slash more todos (#540) - Apply some math for keyboard-dance - Onboarding will be reworked nevertheless --- .../Login/MastodonLoginViewController.swift | 14 +++++++++++--- .../MastodonPickServerViewController.swift | 1 - 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Mastodon/Scene/Onboarding/Login/MastodonLoginViewController.swift b/Mastodon/Scene/Onboarding/Login/MastodonLoginViewController.swift index a1daf77bd..6125955f4 100644 --- a/Mastodon/Scene/Onboarding/Login/MastodonLoginViewController.swift +++ b/Mastodon/Scene/Onboarding/Login/MastodonLoginViewController.swift @@ -129,10 +129,12 @@ class MastodonLoginViewController: UIViewController, NeedsDependency { //MARK: - Actions @objc func backButtonPressed(_ sender: Any) { + contentView.searchTextField.resignFirstResponder() delegate?.backButtonPressed(self) } @objc func nextButtonPressed(_ sender: Any) { + contentView.searchTextField.resignFirstResponder() delegate?.nextButtonPressed(self) } @@ -230,9 +232,15 @@ class MastodonLoginViewController: UIViewController, NeedsDependency { let duration = userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber else { return } - //FIXME: @zeitschlag on iPad - let adjustmentHeight = keyboardFrameValue.cgRectValue.height - view.safeAreaInsets.bottom - contentView.bottomConstraint?.constant = adjustmentHeight + // inspired by https://stackoverflow.com/a/30245044 + let keyboardFrame = keyboardFrameValue.cgRectValue + + let keyboardOrigin = view.convert(keyboardFrame.origin, from: nil) + let intersectionY = CGRectGetMaxY(view.frame) - keyboardOrigin.y; + + if intersectionY >= 0 { + contentView.bottomConstraint?.constant = intersectionY - view.safeAreaInsets.bottom + } UIView.animate(withDuration: duration.doubleValue, delay: 0, options: .curveEaseInOut) { self.view.layoutIfNeeded() diff --git a/Mastodon/Scene/Onboarding/PickServer/MastodonPickServerViewController.swift b/Mastodon/Scene/Onboarding/PickServer/MastodonPickServerViewController.swift index 11e12f3c8..7e832ddca 100644 --- a/Mastodon/Scene/Onboarding/PickServer/MastodonPickServerViewController.swift +++ b/Mastodon/Scene/Onboarding/PickServer/MastodonPickServerViewController.swift @@ -445,7 +445,6 @@ extension MastodonPickServerViewController: PickServerServerSectionTableHeaderVi } func pickServerServerSectionTableHeaderView(_ headerView: PickServerServerSectionTableHeaderView, searchTextDidChange searchText: String?) { - //TODO: @zeitschlag Deselect server? viewModel.searchText.send(searchText ?? "") } }