@@ -19,6 +19,17 @@ public class RxKeyboard: NSObject {
1919 /// Get a singleton instance.
2020 public static let instance = RxKeyboard ( )
2121
22+ /// A view that receives pan gesture. The default value is the AppDelegate's window. Set this
23+ /// value with the root view controller's view if the target is an App Extension.
24+ public var gestureView : UIView ? {
25+ get { return self . _gestureView ?? self . application? . delegate? . window ?? nil }
26+ set {
27+ self . _gestureView = newValue
28+ self . panRecognizer. view? . removeGestureRecognizer ( self . panRecognizer)
29+ newValue? . addGestureRecognizer ( self . panRecognizer)
30+ }
31+ }
32+
2233 /// An observable keyboard frame.
2334 public let frame : Driver < CGRect >
2435
@@ -35,13 +46,12 @@ public class RxKeyboard: NSObject {
3546
3647 fileprivate let disposeBag = DisposeBag ( )
3748 fileprivate let panRecognizer = UIPanGestureRecognizer ( )
49+
3850 fileprivate let application : UIApplication ? = {
3951 let selector = NSSelectorFromString ( " sharedApplication " )
4052 return UIApplication . perform ( selector) ? . takeRetainedValue ( ) as? UIApplication
4153 } ( )
42- fileprivate var gestureView : UIView ? {
43- return self . application? . delegate? . window ?? nil
44- }
54+ fileprivate var _gestureView : UIView ?
4555
4656
4757 // MARK: Initializing
@@ -119,7 +129,8 @@ public class RxKeyboard: NSObject {
119129 NotificationCenter . default. rx. notification ( . UIApplicationDidFinishLaunching)
120130 . map { _ in Void ( ) }
121131 . startWith ( Void ( ) ) // when RxKeyboard is initialized before UIApplication.window is created
122- . subscribe ( onNext: { _ in
132+ . subscribe ( onNext: { [ weak self] _ in
133+ guard let `self` = self else { return }
123134 self . gestureView? . addGestureRecognizer ( self . panRecognizer)
124135 } )
125136 . addDisposableTo ( self . disposeBag)
0 commit comments