@@ -32,7 +32,7 @@ public class KeyboardMovementObserver: NSObject {
32
32
33
33
private var _windowsCount : Int = 0
34
34
private var prevKeyboardPosition = 0.0
35
- private var displayLink : CADisplayLink ?
35
+ private var displayLink : CADisplayLink !
36
36
private var interactiveKeyboardObserver : NSKeyValueObservation ?
37
37
private var isMounted = false
38
38
// state variables
@@ -57,6 +57,18 @@ public class KeyboardMovementObserver: NSObject {
57
57
self . onNotify = onNotify
58
58
self . onRequestAnimation = onRequestAnimation
59
59
self . onCancelAnimation = onCancelAnimation
60
+
61
+ super. init ( )
62
+
63
+ displayLink = CADisplayLink ( target: self , selector: #selector( updateKeyboardFrame) )
64
+ displayLink. preferredFramesPerSecond = 120 // will fallback to 60 fps for devices without Pro Motion display
65
+ displayLink. add ( to: . main, forMode: . common)
66
+ displayLink. isPaused = true
67
+ }
68
+
69
+ deinit {
70
+ displayLink. invalidate ( )
71
+ displayLink = nil
60
72
}
61
73
62
74
@objc public func mount( ) {
@@ -109,7 +121,7 @@ public class KeyboardMovementObserver: NSObject {
109
121
110
122
private func keyboardDidMoveInteractively( changeValue: CGPoint ) {
111
123
// if we are currently animating keyboard -> we need to ignore values from KVO
112
- if displayLink != nil {
124
+ if !displayLink . isPaused {
113
125
return
114
126
}
115
127
// if keyboard height is not equal to its bounds - we can ignore
@@ -232,18 +244,15 @@ public class KeyboardMovementObserver: NSObject {
232
244
// sometimes `will` events can be called multiple times.
233
245
// To avoid double re-creation of listener we are adding this condition
234
246
// (if active link is present, then no need to re-setup a listener)
235
- if displayLink != nil {
247
+ if !displayLink . isPaused {
236
248
return
237
249
}
238
250
239
- displayLink = CADisplayLink ( target: self , selector: #selector( updateKeyboardFrame) )
240
- displayLink? . preferredFramesPerSecond = 120 // will fallback to 60 fps for devices without Pro Motion display
241
- displayLink? . add ( to: . main, forMode: . common)
251
+ displayLink. isPaused = false
242
252
}
243
253
244
254
@objc func removeKeyboardWatcher( ) {
245
- displayLink? . invalidate ( )
246
- displayLink = nil
255
+ displayLink. isPaused = true
247
256
}
248
257
249
258
func initializeAnimation( fromValue: Double , toValue: Double ) {
0 commit comments