@@ -26,6 +26,10 @@ public class RxKeyboard: NSObject {
26
26
/// or `0` if the keyboard is not visible.
27
27
public let visibleHeight : Driver < CGFloat >
28
28
29
+ /// Same with `visibleHeight` but only emits values when keyboard is about to show. This is
30
+ /// useful when adjusting scroll view content offset.
31
+ public let willShowVisibleHeight : Driver < CGFloat >
32
+
29
33
30
34
// MARK: Private
31
35
@@ -45,6 +49,13 @@ public class RxKeyboard: NSObject {
45
49
let frameVariable = Variable < CGRect > ( defaultFrame)
46
50
self . frame = frameVariable. asDriver ( )
47
51
self . visibleHeight = self . frame. map { UIScreen . main. bounds. height - $0. origin. y }
52
+ self . willShowVisibleHeight = NotificationCenter . default. rx. notification ( . UIKeyboardWillShow)
53
+ . map { notification -> CGFloat in
54
+ let rectValue = notification. userInfo ? [ UIKeyboardFrameEndUserInfoKey] as? NSValue
55
+ let keyboardFrame = rectValue? . cgRectValue ?? defaultFrame
56
+ return UIScreen . main. bounds. height - keyboardFrame. origin. y
57
+ }
58
+ . asDriver { _ in . empty( ) }
48
59
49
60
super. init ( )
50
61
@@ -79,7 +90,7 @@ public class RxKeyboard: NSObject {
79
90
}
80
91
81
92
// pan gesture
82
- let didPan = self . panRecognizer. rx. event
93
+ let didPan = self . panRecognizer. rx. event. debug ( " pan " )
83
94
. withLatestFrom ( frameVariable. asObservable ( ) ) { ( $0, $1) }
84
95
. flatMap { ( gestureRecognizer, frame) -> Observable < CGRect > in
85
96
guard let window = UIApplication . shared. windows. first,
0 commit comments