Reactive Keyboard in iOS

Overview

RxKeyboard

Swift CocoaPods Build Status Carthage compatible

RxKeyboard provides a reactive way of observing keyboard frame changes. Forget about keyboard notifications. It also perfectly works with UIScrollViewKeyboardDismissMode.interactive.

rxkeyboard-message rxkeyboard-textview

Getting Started

RxKeyboard provides two Drivers.

/// An observable keyboard frame.
let frame: Driver<CGRect>

/// An observable visible height of keyboard. Emits keyboard height if the keyboard is visible
/// or `0` if the keyboard is not visible.
let visibleHeight: Driver<CGFloat>

/// Same with `visibleHeight` but only emits values when keyboard is about to show. This is
/// useful when adjusting scroll view content offset.
let willShowVisibleHeight: Driver<CGFloat>

Use RxKeyboard.instance to get singleton instance.

RxKeyboard.instance

Subscribe RxKeyboard.instance.frame to observe keyboard frame changes.

RxKeyboard.instance.frame
  .drive(onNext: { frame in
    print(frame)
  })
  .disposed(by: disposeBag)

Tips and Tricks

  • πŸ”— I want to adjust UIScrollView's contentInset to fit keyboard height.

    RxKeyboard.instance.visibleHeight
      .drive(onNext: { [scrollView] keyboardVisibleHeight in
        scrollView.contentInset.bottom = keyboardVisibleHeight
      })
      .disposed(by: disposeBag)
  • πŸ”— I want to adjust UIScrollView's contentOffset to fit keyboard height.

    RxKeyboard.instance.willShowVisibleHeight
      .drive(onNext: { [scrollView] keyboardVisibleHeight in
        scrollView.contentOffset.y += keyboardVisibleHeight
      })
      .disposed(by: disposeBag)
  • πŸ”— I want to make UIToolbar move along with the keyboard in an interactive dismiss mode. (Just like the wonderful GIF above!)

    If you're not using Auto Layout:

    RxKeyboard.instance.visibleHeight
      .drive(onNext: { [toolbar, view] keyboardVisibleHeight in
        toolbar.frame.origin.y = view.frame.height - toolbar.frame.height - keyboardVisibleHeight
      })
      .disposed(by: disposeBag)

    If you're using Auto Layout, you have to capture the toolbar's bottom constraint and set constant to keyboard visible height.

    RxKeyboard.instance.visibleHeight
      .drive(onNext: { [toolbarBottomConstraint] keyboardVisibleHeight in
        toolbarBottomConstraint.constant = -1 * keyboardVisibleHeight
      })
      .disposed(by: disposeBag)

    Note: In real world, you should use setNeedsLayout() and layoutIfNeeded() with animation block. See the example project for example.

  • Anything else? Please open an issue or make a Pull Request.

Dependencies

Requirements

  • Swift 4
  • iOS 8+

Contributing

In development, RxKeyboard manages dependencies with Swift Package Manager. Use the command below in order to generate a Xcode project file. Note that .xcodeproj file changes are not tracked via git.

$ swift package generate-xcodeproj

Installation

  • Using CocoaPods:

    pod 'RxKeyboard'
  • Using Carthage:

    binary "https://raw.githubusercontent.com/RxSwiftCommunity/RxKeyboard/master/RxKeyboard.json"
    

    ⚠️ With Carthage, RxKeyboard only supports binary installation:

    • 0.9.2
      • Xcode 10.1 (10B61)
      • Swift 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)
    • 0.9.0
      • Xcode 10 (10A255)
      • Swift 4.2 (swiftlang-1000.11.37.1 clang-1000.11.45.1)
    • 0.8.2
      • Xcode 9.3 (9E145)
      • Swift 4.1.0 (swiftlang-902.0.48 clang-902.0.37.1)
    • 0.7.1
      • Xcode 9.1 (9B55)
      • Swift 4.0.2 (swiftlang-900.0.69.2 clang-900.0.38)
    • 0.7.0
      • 9.0.1 (9A1004)
      • Swift 4.0 (swiftlang-900.0.65.2 clang-900.0.37)

License

RxKeyboard is under MIT license.

Comments
  • Carthage Build Failed

    Carthage Build Failed

    Log at Building Failed

    Skipped building RxKeyboard due to the error:
    Dependency "RxKeyboard" has no shared framework schemes for any of the platforms: iOS
    
    opened by daidongon 10
  • Cathage Build Failed

    Cathage Build Failed

    Building the framework throws the following error: Incompatible Swift version - framework was built with 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2) and the local version is 4.2 (swiftlang-1000.11.37.1 clang-1000.11.45.1).

    Which is weird because the project is updated to Swift 4.2

    opened by gordoneliel 9
  • Xcode 10 build fail

    Xcode 10 build fail

    I am trying to build my project using Xcode 10 and swift 4.2 with iOS Deployment Target set to iOS 10.0.

    I got RxKeyboard at version 0.9.0 using Carthage.

    This is the error message I get at the import RxKeyboard line when I try to build for simulator:

    Module file's minimum deployment target is ios12.0 v12.0: /Users/<my_username>/<my_folder>/<my_project>/Carthage/Build/iOS/RxKeyboard.framework/Modules/RxKeyboard.swiftmodule/x86_64.swiftmodule

    and this is the error message I get when I try to build for iPhone X real device:

    Module file's minimum deployment target is ios12.0 v12.0: /Users/<my_username>/<my_folder>/<my_project>/Carthage/Build/iOS/RxKeyboard.framework/Modules/RxKeyboard.swiftmodule/arm64.swiftmodule

    Does that mean I cannot use this lib if I want to support iOS 10.0 ?

    opened by jerzykiler 8
  • Should not list Carthage in Framework Search Paths

    Should not list Carthage in Framework Search Paths

    Currently FRAMEWORK_SEARCH_PATHS is set to $(PROJECT_DIR)/Carthage/Build/iOS. This gives a warning when building from source in a consuming workspace:

    ld: warning: directory not found for option '-F/Users/bejones/Development/project/Carthage/Checkouts/RxKeyboard/Carthage/Build/iOS'
    

    The correct setup is to not have this and to include RxSwift in the Workspace and use Xcode's Implicit Dependency Management. That way it knows how to compile both as a part of Carthage and in the workspace for development: https://www.quora.com/How-should-an-OSS-library-be-structured-for-distribution-with-both-Carthage-and-CocoaPods/answer/Justin-Spahr-Summers

    opened by brentleyjones 8
  • Swift 4.2 support

    Swift 4.2 support

    RxKeybaord doesn't compile on newest Xcode 10 beta

    Incompatible Swift version - framework was built with 4.1.2 (swiftlang-902.0.54 clang-902.0.39.2) and the local version is 4.2 (swiftlang-1000.0.32.1 clang-1000.10.39).

    opened by Axadiw 7
  • Carthage update error

    Carthage update error

    Swift version

    Apple Swift version 4.0 (swiftlang-900.0.65.2 clang-900.0.37) Target: x86_64-apple-macosx10.9

    Carthage version

    0.26.2

    Cartfile

    github "RxSwiftCommunity/RxKeyboard" ~> 0.7
    

    console

    $carthage update --platform iOS

    result

    *** Skipped building RxKeyboard due to the error: Dependency "RxKeyboard" has no shared framework schemes for any of the platforms: iOS

    If you believe this to be an error, please file an issue with the maintainers at https://github.com/RxSwiftCommunity/RxKeyboard/issues/new

    opened by noppefoxwolf 7
  • Runtime error has occurred in binary downloaded using carthage.

    Runtime error has occurred in binary downloaded using carthage.

    I tried to run a application then I got a following error message.

    dyld: Library not loaded: @rpath/RxCocoaRuntime.framework/RxCocoaRuntime Referenced from: /Users/yuri/Library/Developer/CoreSimulator/Devices/~~~/Yuri.app/Frameworks/RxKeyboard.framework/RxKeyboard Reason: image not found

    It seems RxKeyboard refers RxCocoaRuntime.

    opened by yurimingo 6
  • Compatibility with Swift 4.1

    Compatibility with Swift 4.1

    Hi, I'm using Xcode 9.3 beta 4 with Swift 4.1 and carthage for my dependencies.

    Please can you provide a binary compiled with the latest version of Xcode 9.3 for carthage ?

    Thanks

    opened by Aurazion 6
  • Fix memory leak error in the examples of the README file

    Fix memory leak error in the examples of the README file

    I think we should use a weak reference (not a strong) in our examples. By default, and when we use square brackets without explicitly specifying the type of reference, Swift uses a strong reference to external objects.

    opened by alspirichev 5
  • Fix compilation and memory leak errors in readme.md

    Fix compilation and memory leak errors in readme.md

    I understand that this code is provided just to "show the concept". But i don't think it's rational argument to give user incorrect code with memory leak. Imagine someone copy-pasted it and get leaked viewController.

    I didn't add guard let 'self' = self else { return } to keep code short.

    opened by MortyMerr 5
  • travis.yml: update to use the 11.3 SDK

    travis.yml: update to use the 11.3 SDK

    Hi!

    This commit bumps the iOS and tvOS versions to use when using Travis CI.

    But, we have to be very careful here since Swift 4.1 and Xcode 9.3 cause runtime issues with RxSwift. Please see: https://github.com/ReactiveX/RxSwift/issues/1555

    Thanks!

    opened by r-mckay 5
  • Bump tzinfo from 1.2.9 to 1.2.10

    Bump tzinfo from 1.2.9 to 1.2.10

    Bumps tzinfo from 1.2.9 to 1.2.10.

    Release notes

    Sourced from tzinfo's releases.

    v1.2.10

    TZInfo v1.2.10 on RubyGems.org

    Changelog

    Sourced from tzinfo's changelog.

    Version 1.2.10 - 19-Jul-2022

    Commits
    • 0814dcd Fix the release date.
    • fd05e2a Preparing v1.2.10.
    • b98c32e Merge branch 'fix-directory-traversal-1.2' into 1.2
    • ac3ee68 Remove unnecessary escaping of + within regex character classes.
    • 9d49bf9 Fix relative path loading tests.
    • 394c381 Remove private_constant for consistency and compatibility.
    • 5e9f990 Exclude Arch Linux's SECURITY file from the time zone index.
    • 17fc9e1 Workaround for 'Permission denied - NUL' errors with JRuby on Windows.
    • 6bd7a51 Update copyright years.
    • 9905ca9 Fix directory traversal in Timezone.get when using Ruby data source
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Wrong behavior with InputAccessoryView

    Wrong behavior with InputAccessoryView

    Looks like RxKeyboard has the wrong behavior when we have inputAccessory view. Because willShowVisibleHeight will not trigger on the keyboard because once it was triggered only on inputAccessory view. Same to isHidden

    opened by VitaliiDeveloper 0
  • Bump cocoapods-downloader from 1.4.0 to 1.6.3

    Bump cocoapods-downloader from 1.4.0 to 1.6.3

    Bumps cocoapods-downloader from 1.4.0 to 1.6.3.

    Release notes

    Sourced from cocoapods-downloader's releases.

    1.6.3

    Enhancements
    • None.
    Bug Fixes
    • None.

    1.6.2

    Enhancements
    • None.
    Bug Fixes
    • None.

    1.6.1

    Enhancements
    • None.
    Bug Fixes
    • None.

    1.6.0

    Enhancements
    • None.
    Bug Fixes
    • Adds a check for command injections in the input for hg and git.
      orta #124

    1.5.1

    Enhancements
    • None.
    Bug Fixes
    • Fix "can't modify frozen string" errors when pods are integrated using the branch option
      buju77 #10920

    1.5.0

    ... (truncated)

    Changelog

    Sourced from cocoapods-downloader's changelog.

    1.6.3 (2022-04-01)

    Enhancements
    • None.
    Bug Fixes
    • None.

    1.6.2 (2022-03-28)

    Enhancements
    • None.
    Bug Fixes
    • None.

    1.6.1 (2022-03-23)

    Enhancements
    • None.
    Bug Fixes
    • None.

    1.6.0 (2022-03-22)

    Enhancements
    • None.
    Bug Fixes
    • Adds a check for command injections in the input for hg and git.
      orta #124

    1.5.1 (2021-09-07)

    Enhancements
    • None.

    ... (truncated)

    Commits
    • c03e2ed Release 1.6.3
    • f75bccc Disable Bazaar tests due to macOS 12.3 not including python2
    • 52a0d54 Merge pull request #128 from CocoaPods/validate_before_dl
    • d27c983 Ensure that the git pre-processor doesn't accidentally bail also
    • 3adfe1f [CHANGELOG] Add empty Master section
    • 591167a Release 1.6.2
    • d2564c3 Merge pull request #127 from CocoaPods/validate_before_dl
    • 99fec61 Switches where we check for invalid input, to move it inside the download fun...
    • 96679f2 [CHANGELOG] Add empty Master section
    • 3a7c54b Release 1.6.1
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Might be wrong keyboard height

    Might be wrong keyboard height

    Hi, I am getting a bit strange (unusuable results) for this:

    RxKeyboard.instance.visibleHeight
             .drive(onNext: { [weak postCommentContainerConstraint] keyboardVisibleHeight in
                 print("Keyboard visible height \(keyboardVisibleHeight)")
                 
                 self.view.setNeedsLayout()
                 UIView.animate(withDuration: Constants.kCommentBoxAnimationDuration) {
                     
                     postCommentContainerConstraint?.constant = keyboardVisibleHeight
                         self.view.layoutIfNeeded()
                       }
             })
    

    postCommentContainerConstraint is constraint that defines distance between custom view bottom and a container view bottom. If I hardcode value, it works as it should. A pic from storyboard:

    the output is: Screenshot 2021-12-28 at 1 33 10 PM

    Keyboard visible height 291.0 Keyboard visible height 335.0 Keyboard visible height 0.0 Keyboard visible height 335.0 Keyboard visible height 0.0 Keyboard visible height 335.0 Keyboard visible height 0.0 Keyboard visible height 335.0

    The thing is the actual visible height of a keyboard (along with a toolbar) is around 260.

    Why I am getting different and wrong values?

    My current setup is, I have a tabbar, and a tableview. Over the tableview I have a custom view with a textView. I want to slide it up and down as keyboard shows/hides.

    What am I doing wrong?

    opened by Wh1rlw1nd 0
  • Is it possible to kick start keyboard dismiss interactively operation (Like WhatsApp) before the drag down operation touching the keyboard?

    Is it possible to kick start keyboard dismiss interactively operation (Like WhatsApp) before the drag down operation touching the keyboard?

    Currently, the keyboard only start kick start keyboard dismiss interactively operation when drag down operation touching keyboard edge.

    rx

    However, in WhatsApp app, the keyboard dismiss operation will kick start, when the drag operation touches the bottom bar edge, even before touching keyboard edge.

    ezgif-3-8113adc536bf

    Does anyone have idea what is the technique used by WhatsApp, to achieve such behavior? Thanks.

    opened by yccheok 0
Releases(2.0.0)
Owner
RxSwift Community
RxSwift ecosystem projects
RxSwift Community
Reactive Programming in Swift

Rx is a generic abstraction of computation expressed through Observable<Element> interface, which lets you broadcast and subscribe to values and other

ReactiveX 23.1k Jan 5, 2023
A reactive wrapper built around UIImagePickerController.

RxMediaPicker RxMediaPicker is a RxSwift wrapper built around UIImagePickerController consisting in a simple interface for common actions like picking

RxSwift Community 180 Apr 24, 2022
A Swift Reactive Programming Kit

ReactiveKit is a lightweight Swift framework for reactive and functional reactive programming that enables you to get into the reactive world today. T

Declarative Hub 1.2k Dec 29, 2022
RxSwift reactive wrapper for view gestures

RxGesture Usage To run the example project, clone the repo, in the Example folder open RxGesture.xcworkspace. You might need to run pod install from t

RxSwift Community 1.3k Dec 30, 2022
Simple and lightweight Functional Reactive Coding in Swift for the rest of us

The simplest Observable<T> implementation for Functional Reactive Programming you will ever find. This library does not use the term FRP (Functional R

Jens Ravens 1.1k Jan 3, 2023
Reactive WebSockets

RxWebSocket Reactive extensions for websockets. A lightweight abstraction layer over Starscream to make it reactive. Installation RxWebSocket is avail

FlΓ‘vio Caetano 57 Jul 22, 2022
RxReduce is a lightweight framework that ease the implementation of a state container pattern in a Reactive Programming compliant way.

About Architecture concerns RxReduce Installation The key principles How to use RxReduce Tools and dependencies Travis CI Frameworks Platform Licence

RxSwift Community 125 Jan 29, 2022
A Swift framework for reactive programming.

CwlSignal An implementation of reactive programming. For details, see the article on Cocoa with Love, CwlSignal, a library for reactive programming. N

Matt Gallagher 304 Oct 25, 2022
Swift Reactive Programming.

ReactKit Swift Reactive Programming. How to install See Wiki page. Example For UI Demo, please see ReactKit/ReactKitCatalog. Key-Value Observing // cr

ReactKit 1.2k Nov 6, 2022
RxSwift bindings for Permissions API in iOS.

RxPermission RxSwift bindings for Permission API that helps you with Permissions in iOS. Installation RxPermission is available through CocoaPods. I c

Luke 230 Dec 27, 2022
iOS & OSX Bluetooth library for RxSwift

RxBluetoothKit is a Bluetooth library that makes interaction with BLE devices much more pleasant. It's backed by RxSwift and CoreBluetooth and it prov

Polidea 1.3k Dec 16, 2022
A configurable api client based on Alamofire4 and RxSwift4 for iOS

SimpleApiClient A configurable api client based on Alamofire4 and RxSwift4 for iOS Requirements iOS 8.0+ Swift 4 Table of Contents Basic Usage Unwrap

Jay 67 Dec 7, 2020
Two-way data binding framework for iOS. Only one API to learn.

BindKit A simple to use two-way data binding framework for iOS. Only one API to learn. Supports Objective-C, Swift 5, Xcode 10.2, iOS 8 and above. Shi

Electric Bolt 13 May 25, 2022
🎌 Powerful navigation library for iOS based on the coordinator pattern

⚠️ We have recently released XCoordinator 2.0. Make sure to read this section before migrating. In general, please replace all AnyRouter by either Uno

QuickBird Studios 2k Dec 30, 2022
🟣 Verge is a very tunable state-management engine on iOS App (UIKit / SwiftUI) and built-in ORM.

Verge.swift ?? An effective state management architecture for iOS - UIKit and also SwiftUI ?? _ An easier way to get unidirectional data flow _ _ Supp

VergeGroup 478 Dec 29, 2022
Sample iOS application in SwiftUI presenting Redux architecture

SwiftUI-Redux-Demo Sample iOS application in SwiftUI presenting Redux architecture. My full article about Redux in detail you will find here: Redux ar

Wojciech Kulik 25 Nov 27, 2022
iOS app for open event

CircleCI Code Quality Chat Open Event iOS iOS app for Open Event Introduction This is an iOS app developed for FOSSASIA in mind. The Open Event Projec

FOSSASIA 1.6k Jan 5, 2023
Open Event Orga iOS App

Open Event Organizer iOS App Event management app for organizers using Open Event Platform Roadmap Make the app functionality and UI/UX similar to the

FOSSASIA 1.5k Dec 10, 2022
MVVM + FLUX iOS Instagram client in Swift, eliminates Massive View Controller in unidirectional event/state flow manner

CZInstagram MVVM + FLUX iOS Instagram client in Swift, eliminates Massive View Controller in unidirectional event/state flow manner. Unidirectional Da

Cheng Zhang 56 Nov 1, 2022