Skip to content

Latest commit

 

History

History
59 lines (40 loc) · 1.21 KB

README.md

File metadata and controls

59 lines (40 loc) · 1.21 KB

KeyboardObserver

Provides a reactive way to observe the changes of the keyboard's frame using Swift Combine.

demo

Requirements

  • iOS 13.0+
  • Swift 5.10

Get Started

  1. Attach your view's anchor to the keyboardAreaLayoutGuide of your view.
chatBarView.bottomAnchor.constraint(equalTo: view.keyboardAreaLayoutGuide.topAnchor)
  1. You can also observe the change of the keyboard
view.keyboardObserver.keyboardHeightChange
    .sink { change in
        print(change)
    }
  1. You can invalidate the observer at any time.
override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    view.keyboardObserver.validate()
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    view.keyboardObserver.invalidate()
}

Installation

Add the below line to your Package.swift file as a dependency:

.package(url: "https://github.com/DouKing/KeyboardObserver.git", .upToNextMajor(from: "1.0"))

Normally you'll want to depend on the KeyboardObserver target:

.product(name: "KeyboardObserver", package: "KeyboardObserver")

License

KeyboardObserver is under MIT license.