Skip to content

Provides a reactive way to observe the changes of keyboard using Swift Combine

License

Notifications You must be signed in to change notification settings

DouKing/KeyboardObserver

Repository files navigation

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.

About

Provides a reactive way to observe the changes of keyboard using Swift Combine

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages