diff --git a/Mastodon/Scene/Authentication/Register/MastodonRegisterViewController.swift b/Mastodon/Scene/Authentication/Register/MastodonRegisterViewController.swift index 5361b3117..6eda242bd 100644 --- a/Mastodon/Scene/Authentication/Register/MastodonRegisterViewController.swift +++ b/Mastodon/Scene/Authentication/Register/MastodonRegisterViewController.swift @@ -142,7 +142,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency { let passwordCheckLabel: UILabel = { let label = UILabel() - label.numberOfLines = 4 + label.numberOfLines = 0 return label }() @@ -210,7 +210,7 @@ extension MastodonRegisterViewController { stackView.axis = .vertical stackView.distribution = .fill stackView.spacing = 40 - stackView.layoutMargins = UIEdgeInsets(top: 0, left: 4, bottom: 0, right: 4) + stackView.layoutMargins = UIEdgeInsets(top: 0, left: 4, bottom: 26, right: 4) stackView.isLayoutMarginsRelativeArrangement = true stackView.addArrangedSubview(largeTitleLabel) stackView.addArrangedSubview(photoView) @@ -293,21 +293,19 @@ extension MastodonRegisterViewController { signUpActivityIndicatorView.centerYAnchor.constraint(equalTo: signUpButton.centerYAnchor), ]) - Publishers.CombineLatest3( - KeyboardResponderService.shared.isShow.eraseToAnyPublisher(), + Publishers.CombineLatest( KeyboardResponderService.shared.state.eraseToAnyPublisher(), - KeyboardResponderService.shared.endFrame.eraseToAnyPublisher() + KeyboardResponderService.shared.willEndFrame.eraseToAnyPublisher() ) - .sink(receiveValue: { [weak self] isShow, state, endFrame in + .sink(receiveValue: { [weak self] state, endFrame in guard let self = self else { return } - guard isShow, state == .dock else { + guard state == .dock else { self.scrollview.contentInset.bottom = 0.0 self.scrollview.verticalScrollIndicatorInsets.bottom = 0.0 return } - // isShow AND dock state let contentFrame = self.view.convert(self.scrollview.frame, to: nil) let padding = contentFrame.maxY - endFrame.minY guard padding > 0 else { @@ -409,9 +407,10 @@ extension MastodonRegisterViewController: UITextFieldDelegate { // align to password label when overlap if textField === passwordTextField, KeyboardResponderService.shared.isShow.value, - KeyboardResponderService.shared.state.value == .dock { - let endFrame = KeyboardResponderService.shared.endFrame.value - let contentFrame = self.scrollview.convert(self.passwordCheckLabel.frame, to: nil) + KeyboardResponderService.shared.state.value == .dock + { + let endFrame = KeyboardResponderService.shared.willEndFrame.value + let contentFrame = scrollview.convert(passwordCheckLabel.frame, to: nil) let padding = contentFrame.maxY - endFrame.minY if padding > 0 { let contentOffsetY = scrollview.contentOffset.y diff --git a/Mastodon/Service/KeyboardResponderService.swift b/Mastodon/Service/KeyboardResponderService.swift index 1711680a0..b21737963 100644 --- a/Mastodon/Service/KeyboardResponderService.swift +++ b/Mastodon/Service/KeyboardResponderService.swift @@ -18,7 +18,8 @@ final class KeyboardResponderService { // output let isShow = CurrentValueSubject(false) let state = CurrentValueSubject(.none) - let endFrame = CurrentValueSubject(.zero) + let didEndFrame = CurrentValueSubject(.zero) + let willEndFrame = CurrentValueSubject(.zero) private init() { NotificationCenter.default.publisher(for: UIResponder.keyboardWillShowNotification, object: nil) @@ -37,6 +38,15 @@ final class KeyboardResponderService { NotificationCenter.default.publisher(for: UIResponder.keyboardDidChangeFrameNotification, object: nil) .sink { notification in + guard let endFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { return } + self.didEndFrame.value = endFrame + self.updateInternalStatus(notification: notification) + } + .store(in: &disposeBag) + NotificationCenter.default.publisher(for: UIResponder.keyboardWillChangeFrameNotification, object: nil) + .sink { notification in + guard let endFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { return } + self.willEndFrame.value = endFrame self.updateInternalStatus(notification: notification) } .store(in: &disposeBag) @@ -52,8 +62,6 @@ extension KeyboardResponderService { return } - self.endFrame.value = endFrame - guard isLocal else { self.state.value = .notLocal return