RxSwiftCommunity / RxKeyboard

Reactive Keyboard in iOS
MIT License
1.6k stars 176 forks source link

Make RxKeyboard conform to RxKeyboarding protocol #49

Closed gilgol closed 6 years ago

gilgol commented 6 years ago

I was wondering how can I test the logic of the entity that will use RxKeyboard (as it is a singleton), and thought this could be a great addition to RxKeyboard.

Having it conform to such protocol, will make mocking very easy, and one could just inject RxKeyboard.instance as a dependancy or the mock for the tests instead of just using the global instance:

protocol RxKeyboarding {
    /// An observable keyboard frame.
    var frame: Driver<CGRect> { get }

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

    /// Same with `visibleHeight` but only emits values when keyboard is about to show. This is
    /// useful when adjusting scroll view content offset.
    var willShowVisibleHeight: Driver<CGFloat>  { get }
}
devxoul commented 6 years ago

Yeah I think this is a great idea. #50 is a PR for this issue.