Skip to content

Commit 8e400ef

Browse files
authored
issue #8: no listeners registered warnings (#9)
* issue #8: no listeners registered warnings * refactor: removed legacy listener
1 parent b2dff47 commit 8e400ef

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ PODS:
282282
- React-jsinspector (0.68.1)
283283
- React-logger (0.68.1):
284284
- glog
285-
- react-native-keyboard-controller (0.1.0):
285+
- react-native-keyboard-controller (1.0.0-alpha.0):
286286
- React-Core
287287
- react-native-safe-area-context (4.2.4):
288288
- RCT-Folly
@@ -583,7 +583,7 @@ SPEC CHECKSUMS:
583583
React-jsiexecutor: 4a4bae5671b064a2248a690cf75957669489d08c
584584
React-jsinspector: 218a2503198ff28a085f8e16622a8d8f507c8019
585585
React-logger: f79dd3cc0f9b44f5611c6c7862badd891a862cf8
586-
react-native-keyboard-controller: ea59466588875b147daf53910d3deb3d628d10e3
586+
react-native-keyboard-controller: ec0d3c325c2d3b6fe9c704cdb7b708bbcc3fe7b5
587587
react-native-safe-area-context: f98b0b16d1546d208fc293b4661e3f81a895afd9
588588
React-perflogger: 30ab8d6db10e175626069e742eead3ebe8f24fd5
589589
React-RCTActionSheet: 4b45da334a175b24dabe75f856b98fed3dfd6201

example/src/screens/Examples/AwareScrollView/index.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useEffect } from 'react';
2-
import { TextInput, LogBox, View, Dimensions } from 'react-native';
2+
import { TextInput, View, Dimensions } from 'react-native';
33
import { KeyboardEvents } from 'react-native-keyboard-controller';
44
import Reanimated, {
55
useAnimatedRef,
@@ -8,10 +8,8 @@ import Reanimated, {
88
useSharedValue,
99
} from 'react-native-reanimated';
1010

11-
LogBox.ignoreAllLogs();
12-
1311
function randomColor() {
14-
return '#' + Math.floor(Math.random() * 16777215).toString(16);
12+
return '#' + Math.random().toString(16).slice(-6);
1513
}
1614

1715
const screenHeight = Dimensions.get('window').height;

example/src/screens/Examples/KeyboardAnimation/index.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react';
22
import { Animated, TextInput, View } from 'react-native';
33
import {
4-
KeyboardEvents,
54
useKeyboardAnimation,
65
useKeyboardAnimationReplica,
76
} from 'react-native-keyboard-controller';
@@ -11,14 +10,6 @@ export default function KeyboardAnimation() {
1110
const { height, progress } = useKeyboardAnimation();
1211
const { height: heightReplica } = useKeyboardAnimationReplica();
1312

14-
React.useEffect(() => {
15-
const listener = KeyboardEvents.addListener('keyboardWillShow', (e) => {
16-
console.debug(e);
17-
});
18-
19-
return () => listener.remove();
20-
}, []);
21-
2213
return (
2314
<View style={styles.container}>
2415
<View style={styles.row}>

ios/KeyboardControllerModule.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import AVFoundation
1313
@objc(KeyboardController)
1414
class KeyboardController: RCTEventEmitter {
1515
public static var shared: KeyboardController?
16+
private var hasListeners = false
1617

1718
override class func requiresMainQueueSetup() -> Bool {
1819
return false
@@ -35,4 +36,18 @@ class KeyboardController: RCTEventEmitter {
3536
"KeyboardController::keyboardDidHide"
3637
]
3738
}
39+
40+
@objc open override func startObserving() {
41+
hasListeners = true
42+
}
43+
44+
@objc open override func stopObserving() {
45+
hasListeners = false
46+
}
47+
48+
@objc open override func sendEvent(withName name: String!, body: Any!) {
49+
if (hasListeners) {
50+
super.sendEvent(withName: name, body: body)
51+
}
52+
}
3853
}

0 commit comments

Comments
 (0)