     }
 
     @objc func onKeyboardWillHide(notification: NSNotification) {
-        guard let duration = notification.userInfo?[UIKeyboardAnimationDurationUserInfoKey] as? TimeInterval
+        guard keyboardIsShowing,
+            let duration = notification.userInfo?[UIKeyboardAnimationDurationUserInfoKey] as? TimeInterval
             else { return }
+
+        keyboardIsShowing = false
+
         UIView.animate(withDuration: duration, delay: 0, options: [.beginFromCurrentState], animations: {
             self.scrollView.contentInset = self.originalContentInset
             self.scrollView.scrollIndicatorInsets = self.originalContentInset

    private let scrollView: UIScrollView
    private var originalContentInset: UIEdgeInsets = .zero
    private weak var viewController: UIViewController?

    init(scrollView: UIScrollView, viewController: UIViewController) {
        self.scrollView = scrollView

    // MARK: Notifications

    @objc func onKeyboardWillShow(notification: NSNotification) {
        guard !keyboardIsShowing,
            let frame = notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? CGRect,
            let duration = notification.userInfo?[UIKeyboardAnimationDurationUserInfoKey] as? TimeInterval,
            let viewController = self.viewController
            else { return }

        keyboardIsShowing = true

        var inset = scrollView.contentInset
        originalContentInset = inset
