react-native-keyboard-controller 1.9.1 → 1.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -25,6 +25,8 @@ let noFocusedInputEvent: [String: Any] = [
|
|
|
25
25
|
public class FocusedInputLayoutObserver: NSObject {
|
|
26
26
|
// class members
|
|
27
27
|
var onEvent: (NSDictionary) -> Void
|
|
28
|
+
// state variables
|
|
29
|
+
private var isMounted = false
|
|
28
30
|
// input tracking
|
|
29
31
|
private var currentInput: UIView?
|
|
30
32
|
private var hasKVObserver = false
|
|
@@ -37,6 +39,12 @@ public class FocusedInputLayoutObserver: NSObject {
|
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
@objc public func mount() {
|
|
42
|
+
if isMounted {
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
isMounted = true
|
|
47
|
+
|
|
40
48
|
NotificationCenter.default.addObserver(
|
|
41
49
|
self,
|
|
42
50
|
selector: #selector(keyboardWillShow),
|
|
@@ -52,6 +60,7 @@ public class FocusedInputLayoutObserver: NSObject {
|
|
|
52
60
|
}
|
|
53
61
|
|
|
54
62
|
@objc public func unmount() {
|
|
63
|
+
isMounted = false
|
|
55
64
|
// swiftlint:disable:next notification_center_detachment
|
|
56
65
|
NotificationCenter.default.removeObserver(self)
|
|
57
66
|
}
|
|
@@ -31,6 +31,7 @@ public class KeyboardMovementObserver: NSObject {
|
|
|
31
31
|
private var prevKeyboardPosition = 0.0
|
|
32
32
|
private var displayLink: CADisplayLink?
|
|
33
33
|
private var hasKVObserver = false
|
|
34
|
+
private var isMounted = false
|
|
34
35
|
// state variables
|
|
35
36
|
private var keyboardHeight: CGFloat = 0.0
|
|
36
37
|
private var duration = 0
|
|
@@ -45,6 +46,12 @@ public class KeyboardMovementObserver: NSObject {
|
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
@objc public func mount() {
|
|
49
|
+
if isMounted {
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
isMounted = true
|
|
54
|
+
|
|
48
55
|
NotificationCenter.default.addObserver(
|
|
49
56
|
self,
|
|
50
57
|
selector: #selector(keyboardWillDisappear),
|
|
@@ -138,6 +145,7 @@ public class KeyboardMovementObserver: NSObject {
|
|
|
138
145
|
}
|
|
139
146
|
|
|
140
147
|
@objc public func unmount() {
|
|
148
|
+
isMounted = false
|
|
141
149
|
// swiftlint:disable:next notification_center_detachment
|
|
142
150
|
NotificationCenter.default.removeObserver(self)
|
|
143
151
|
}
|
|
@@ -156,17 +156,36 @@ using namespace facebook::react;
|
|
|
156
156
|
|
|
157
157
|
if (newViewProps.enabled != oldViewProps.enabled) {
|
|
158
158
|
if (newViewProps.enabled) {
|
|
159
|
-
[
|
|
160
|
-
[keyboardObserver mount];
|
|
159
|
+
[self mount];
|
|
161
160
|
} else {
|
|
162
|
-
[
|
|
163
|
-
[keyboardObserver unmount];
|
|
161
|
+
[self unmount];
|
|
164
162
|
}
|
|
165
163
|
}
|
|
166
164
|
|
|
167
165
|
[super updateProps:props oldProps:oldProps];
|
|
168
166
|
}
|
|
169
167
|
|
|
168
|
+
- (void)willMoveToSuperview:(UIView *)newSuperview
|
|
169
|
+
{
|
|
170
|
+
if (newSuperview == nil) {
|
|
171
|
+
[self unmount];
|
|
172
|
+
} else {
|
|
173
|
+
[self mount];
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
- (void)mount
|
|
178
|
+
{
|
|
179
|
+
[inputObserver mount];
|
|
180
|
+
[keyboardObserver mount];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
- (void)unmount
|
|
184
|
+
{
|
|
185
|
+
[inputObserver unmount];
|
|
186
|
+
[keyboardObserver unmount];
|
|
187
|
+
}
|
|
188
|
+
|
|
170
189
|
Class<RCTComponentViewProtocol> KeyboardControllerViewCls(void)
|
|
171
190
|
{
|
|
172
191
|
return KeyboardControllerView.class;
|
|
@@ -24,11 +24,9 @@ class KeyboardControllerView: UIView {
|
|
|
24
24
|
@objc var enabled: ObjCBool = true {
|
|
25
25
|
didSet {
|
|
26
26
|
if enabled.boolValue {
|
|
27
|
-
|
|
28
|
-
keyboardObserver?.mount()
|
|
27
|
+
mount()
|
|
29
28
|
} else {
|
|
30
|
-
|
|
31
|
-
keyboardObserver?.unmount()
|
|
29
|
+
unmount()
|
|
32
30
|
}
|
|
33
31
|
}
|
|
34
32
|
}
|
|
@@ -37,6 +35,8 @@ class KeyboardControllerView: UIView {
|
|
|
37
35
|
self.bridge = bridge
|
|
38
36
|
eventDispatcher = bridge.eventDispatcher()
|
|
39
37
|
super.init(frame: frame)
|
|
38
|
+
inputObserver = FocusedInputLayoutObserver(handler: onInput)
|
|
39
|
+
keyboardObserver = KeyboardMovementObserver(handler: onEvent, onNotify: onNotify)
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
@available(*, unavailable)
|
|
@@ -44,21 +44,17 @@ class KeyboardControllerView: UIView {
|
|
|
44
44
|
fatalError("init(coder:) has not been implemented")
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
}
|
|
47
|
+
// for mounting/unmounting observers for lifecycle events we're using willMove(toSuperview) method
|
|
48
|
+
// not willMove(toWindow)
|
|
49
|
+
// see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/271
|
|
50
|
+
override func willMove(toSuperview newSuperview: UIView?) {
|
|
51
|
+
super.willMove(toSuperview: newSuperview)
|
|
54
52
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
keyboardObserver = KeyboardMovementObserver(handler: onEvent, onNotify: onNotify)
|
|
61
|
-
keyboardObserver?.mount()
|
|
53
|
+
if newSuperview == nil {
|
|
54
|
+
// The view is about to be removed from its superview (destroyed)
|
|
55
|
+
unmount()
|
|
56
|
+
} else {
|
|
57
|
+
mount()
|
|
62
58
|
}
|
|
63
59
|
}
|
|
64
60
|
|
|
@@ -90,4 +86,14 @@ class KeyboardControllerView: UIView {
|
|
|
90
86
|
func onNotify(event: String, data: Any) {
|
|
91
87
|
KeyboardController.shared()?.sendEvent(event, body: data)
|
|
92
88
|
}
|
|
89
|
+
|
|
90
|
+
private func mount() {
|
|
91
|
+
inputObserver?.mount()
|
|
92
|
+
keyboardObserver?.mount()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private func unmount() {
|
|
96
|
+
inputObserver?.unmount()
|
|
97
|
+
keyboardObserver?.unmount()
|
|
98
|
+
}
|
|
93
99
|
}
|
package/package.json
CHANGED