question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

_reactNative.Keyboard.removeListener is not a function

See original GitHub issue

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch react-native-gifted-chat@0.16.3 for the project I’m working on.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-gifted-chat/lib/MessageContainer.js b/node_modules/react-native-gifted-chat/lib/MessageContainer.js
index 193772a..e26443e 100644
--- a/node_modules/react-native-gifted-chat/lib/MessageContainer.js
+++ b/node_modules/react-native-gifted-chat/lib/MessageContainer.js
@@ -1,6 +1,6 @@
 import PropTypes from 'prop-types';
 import React from 'react';
-import { FlatList, View, StyleSheet, Keyboard, TouchableOpacity, Text, Platform, } from 'react-native';
+import { FlatList, View, StyleSheet, Keyboard, TouchableOpacity, Text, Platform } from 'react-native';
 import LoadEarlier from './LoadEarlier';
 import Message from './Message';
 import Color from './Color';
@@ -55,18 +55,26 @@ export default class MessageContainer extends React.PureComponent {
         this.attachKeyboardListeners = () => {
             const { invertibleScrollViewProps: invertibleProps } = this.props;
             if (invertibleProps) {
-                Keyboard.addListener('keyboardWillShow', invertibleProps.onKeyboardWillShow);
-                Keyboard.addListener('keyboardDidShow', invertibleProps.onKeyboardDidShow);
-                Keyboard.addListener('keyboardWillHide', invertibleProps.onKeyboardWillHide);
-                Keyboard.addListener('keyboardDidHide', invertibleProps.onKeyboardDidHide);
+                //Keyboard.addListener('keyboardWillShow', invertibleProps.onKeyboardWillShow);
+                //Keyboard.addListener('keyboardDidShow', invertibleProps.onKeyboardDidShow);
+                //Keyboard.addListener('keyboardWillHide', invertibleProps.onKeyboardWillHide);
+                //Keyboard.addListener('keyboardDidHide', invertibleProps.onKeyboardDidHide);
+                this.willShowSub = Keyboard.addListener('keyboardWillShow', invertibleProps.onKeyboardWillShow);
+                this.didShowSub = Keyboard.addListener('keyboardDidShow', invertibleProps.onKeyboardDidShow);
+                this.willHideSub = Keyboard.addListener('keyboardWillHide', invertibleProps.onKeyboardWillHide);
+                this.didHideSub = Keyboard.addListener('keyboardDidHide', invertibleProps.onKeyboardDidHide);
             }
         };
         this.detachKeyboardListeners = () => {
             const { invertibleScrollViewProps: invertibleProps } = this.props;
-            Keyboard.removeListener('keyboardWillShow', invertibleProps.onKeyboardWillShow);
-            Keyboard.removeListener('keyboardDidShow', invertibleProps.onKeyboardDidShow);
-            Keyboard.removeListener('keyboardWillHide', invertibleProps.onKeyboardWillHide);
-            Keyboard.removeListener('keyboardDidHide', invertibleProps.onKeyboardDidHide);
+            //Keyboard.removeListener('keyboardWillShow', invertibleProps.onKeyboardWillShow);
+            //Keyboard.removeListener('keyboardDidShow', invertibleProps.onKeyboardDidShow);
+            //Keyboard.removeListener('keyboardWillHide', invertibleProps.onKeyboardWillHide);
+            //Keyboard.removeListener('keyboardDidHide', invertibleProps.onKeyboardDidHide);
+            this.willShowSub?.remove();
+            this.didShowSub?.remove();
+            this.willHideSub?.remove();
+            this.didHideSub?.remove();
         };
         this.renderTypingIndicator = () => {
             if (Platform.OS === 'web') {

This issue body was partially generated by patch-package.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:20
  • Comments:18

github_iconTop GitHub Comments

4reactions
teamzz111commented, Sep 22, 2021

May you create a PR with these changes?

3reactions
ZainabShakeelcommented, Oct 14, 2021

Update MessageContainer.js with patch-package (install patch-package before) step 1 – vim node_modules/react-native-gifted-chat/lib/MessageContainer.js (open file with vim filename . Type i to switch into insert mode so that you can start editing the file. Enter or modify the text with your file. Once you’re done, press the escape key Esc to get out of insert mode and back to command mode. Type :wq to save and exit your file.

step 2 npx patch-package react-native-gifted-chat

run the app it will work fine

Read more comments on GitHub >

github_iconTop Results From Across the Web

Keyboard.removeListener is not a function #2090 - GitHub
Hello I started getting this error after the last update of react native because the removeListener function was removed in the last update....
Read more >
react native - _reactNative.Keyboard.removeListener is not a ...
Now I started to get this exception while trying to navigate between screens: _reactNative.Keyboard.removeListener is not a function. enter ...
Read more >
[Solved]-_reactNative.Keyboard.removeListener is not a ...
Coding example for the question _reactNative.Keyboard.removeListener is not a function-React Native.
Read more >
Keyboard - React Native
The Keyboard module allows you to listen for native events and react to them, as well as make changes to the keyboard, like...
Read more >
Keyboard · React Native
The Keyboard module allows you to listen for native events and react to them, as well as make changes to the keyboard, like...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found