Skip to content

Commit

Permalink
issue #8: no listeners registered warnings (#9)
Browse files Browse the repository at this point in the history
* issue #8: no listeners registered warnings

* refactor: removed legacy listener
  • Loading branch information
kirillzyusko authored May 8, 2022
1 parent b2dff47 commit 8e400ef
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ PODS:
- React-jsinspector (0.68.1)
- React-logger (0.68.1):
- glog
- react-native-keyboard-controller (0.1.0):
- react-native-keyboard-controller (1.0.0-alpha.0):
- React-Core
- react-native-safe-area-context (4.2.4):
- RCT-Folly
Expand Down Expand Up @@ -583,7 +583,7 @@ SPEC CHECKSUMS:
React-jsiexecutor: 4a4bae5671b064a2248a690cf75957669489d08c
React-jsinspector: 218a2503198ff28a085f8e16622a8d8f507c8019
React-logger: f79dd3cc0f9b44f5611c6c7862badd891a862cf8
react-native-keyboard-controller: ea59466588875b147daf53910d3deb3d628d10e3
react-native-keyboard-controller: ec0d3c325c2d3b6fe9c704cdb7b708bbcc3fe7b5
react-native-safe-area-context: f98b0b16d1546d208fc293b4661e3f81a895afd9
React-perflogger: 30ab8d6db10e175626069e742eead3ebe8f24fd5
React-RCTActionSheet: 4b45da334a175b24dabe75f856b98fed3dfd6201
Expand Down
6 changes: 2 additions & 4 deletions example/src/screens/Examples/AwareScrollView/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
import { TextInput, LogBox, View, Dimensions } from 'react-native';
import { TextInput, View, Dimensions } from 'react-native';
import { KeyboardEvents } from 'react-native-keyboard-controller';
import Reanimated, {
useAnimatedRef,
Expand All @@ -8,10 +8,8 @@ import Reanimated, {
useSharedValue,
} from 'react-native-reanimated';

LogBox.ignoreAllLogs();

function randomColor() {
return '#' + Math.floor(Math.random() * 16777215).toString(16);
return '#' + Math.random().toString(16).slice(-6);
}

const screenHeight = Dimensions.get('window').height;
Expand Down
9 changes: 0 additions & 9 deletions example/src/screens/Examples/KeyboardAnimation/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import { Animated, TextInput, View } from 'react-native';
import {
KeyboardEvents,
useKeyboardAnimation,
useKeyboardAnimationReplica,
} from 'react-native-keyboard-controller';
Expand All @@ -11,14 +10,6 @@ export default function KeyboardAnimation() {
const { height, progress } = useKeyboardAnimation();
const { height: heightReplica } = useKeyboardAnimationReplica();

React.useEffect(() => {
const listener = KeyboardEvents.addListener('keyboardWillShow', (e) => {
console.debug(e);
});

return () => listener.remove();
}, []);

return (
<View style={styles.container}>
<View style={styles.row}>
Expand Down
15 changes: 15 additions & 0 deletions ios/KeyboardControllerModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import AVFoundation
@objc(KeyboardController)
class KeyboardController: RCTEventEmitter {
public static var shared: KeyboardController?
private var hasListeners = false

override class func requiresMainQueueSetup() -> Bool {
return false
Expand All @@ -35,4 +36,18 @@ class KeyboardController: RCTEventEmitter {
"KeyboardController::keyboardDidHide"
]
}

@objc open override func startObserving() {
hasListeners = true
}

@objc open override func stopObserving() {
hasListeners = false
}

@objc open override func sendEvent(withName name: String!, body: Any!) {
if (hasListeners) {
super.sendEvent(withName: name, body: body)
}
}
}

0 comments on commit 8e400ef

Please sign in to comment.