Skip to content

Commit

Permalink
Add missing states (hidding and showing).
Browse files Browse the repository at this point in the history
  • Loading branch information
dmkskn committed Nov 24, 2022
1 parent 2450110 commit 1c10606
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Sources/KeyboardState/KeyboardObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import Combine
//
// - UIResponder.keyboardDidShowNotification
// - UIResponder.keyboardDidHideNotification
// - UIResponder.keyboardWillHideNotification
// - UIResponder.keyboardWillShowNotification

NotificationCenter.default
.publisher(for: UIResponder.keyboardDidShowNotification)
Expand All @@ -34,6 +36,22 @@ import Combine
self?.state = .hidden
}
.store(in: &cancellable)

NotificationCenter.default
.publisher(for: UIResponder.keyboardWillHideNotification)
.receive(on: RunLoop.main)
.sink { [weak self] _ in
self?.state = .hiding
}
.store(in: &cancellable)

NotificationCenter.default
.publisher(for: UIResponder.keyboardWillShowNotification)
.receive(on: RunLoop.main)
.sink { [weak self] _ in
self?.state = .showing
}
.store(in: &cancellable)
}

private var cancellable = Set<AnyCancellable>()
Expand Down
4 changes: 4 additions & 0 deletions Sources/KeyboardState/KeyboardVisibility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
case visible
/// Indicates that the keyboard is currently hidden
case hidden
/// Indicates that the keyboard is going to be hidden
case hiding
/// Indicates that the keyboard is going to be shown
case showing
}

#endif

0 comments on commit 1c10606

Please sign in to comment.