Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyboard.removeListener is not a function #2090

Closed
mustafauyysl opened this issue Aug 19, 2021 · 29 comments
Closed

Keyboard.removeListener is not a function #2090

mustafauyysl opened this issue Aug 19, 2021 · 29 comments

Comments

@mustafauyysl
Copy link

Simulator Screen Shot - iPhone 12 - 2021-08-19 at 12 55 38

Hello I started getting this error after the last update of react native because the removeListener function was removed in the last update.

@horo42
Copy link

horo42 commented Aug 19, 2021

in MessageContainer.js constructor

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);
+        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);
+    this.willShowSub?.remove();
+    this.didShowSub?.remove();
+    this.willHideSub?.remove();
+    this.didHideSub?.remove();
};

you can apply this fix with https://github.com/ds300/patch-package until the maintainers fix this

@kundankarna1994
Copy link

Screenshot_20210824-121457_SwissBot

I tried the above code and its throwing above error

@horo42
Copy link

horo42 commented Aug 24, 2021

I updated my answer, adding optional chaining operators to the remove() method calls. That should fix your issue.

@gogroup-official
Copy link

image
Changer to

@Faiaz-Rahman
Copy link

Faiaz-Rahman commented Aug 26, 2021

This helped a lot! You saved my day! 💚💚❤❤💜💜

@marister
Copy link

marister commented Sep 1, 2021

Anyone knows whats the status of this?
Is there a PR open for this?
can someone merge it please? 😄 👯 💘

@adhip94
Copy link

adhip94 commented Sep 3, 2021

@xcarpentier Is it possible to do a quick release with a fix as this issue is affecting all users on RN 0.65 and above?

@mrcustodio
Copy link

Yep, I'm on the same boat... Every time having to manually change the listener to remove the errors...

@morphytron
Copy link

Receiving same issue on latest release.

thomas-pipithkul added a commit to thomas-pipithkul/Glai-message-app that referenced this issue Sep 4, 2021
…because removeListener() in official gifted chat is deprecated in RN 0.65 and broke gifted chat completely. See more here: FaridSafi/react-native-gifted-chat#2090
@mrshahzeb7
Copy link

facing this issue when logout from chat screen (after upgrading all libraries)

@intechsol143
Copy link

image
Changer to

Thank you very much

@anwersolangi
Copy link

@horo42 after updating the MessageContainer file, i get the error node_modules\react-native-gifted-chat\lib\messagecontainer.js: cannot find module 'metro-react-native-babel-preset' I tried to update the package.json file and also tried to add metro-react-natiev-babel-preset in the package and comment out the transform in package json, cleared the npm cache, clean android project but nothing helped....

@PointlessSpike
Copy link

I've just tried Gifted Chat and come across this issue. Simplest possible implementation and I've only just installed it.
Any idea when it'll get resolved?

@adhip94
Copy link

adhip94 commented Sep 13, 2021

I've already emailed @xcarpentier, he replied back acknowledging he would do a release. Not sure when though...

@77TecShaeer
Copy link

can any one make fork of Repo ? and make that edit

@Ludolapert
Copy link

Thank you for the follow up @adhip94!

Could we have an estimation of a release date for this fix @xcarpentier ?

@yasimoha
Copy link

hi has there been any progress? becuase im still facing this isssue.

@habovh
Copy link

habovh commented Sep 22, 2021

@yasimoha and anyone needing a quick fix for production apps, you may apply the patch described by @horo42 here: #2090 (comment)

@horo42
Copy link

horo42 commented Sep 22, 2021

image
Changer to

This workaround probably pushes the same callback references to the listener callbacks array, and then instantly removes them, leaving the originals (from attachKeyboardListeners) attached. Which is probably fine, but you don't have to settle, you're already patching into node_modules anyway.

@horo42 after updating the MessageContainer file, i get the error node_modules\react-native-gifted-chat\lib\messagecontainer.js: cannot find module 'metro-react-native-babel-preset' I tried to update the package.json file and also tried to add metro-react-natiev-babel-preset in the package and comment out the transform in package json, cleared the npm cache, clean android project but nothing helped....

Most likely an issue with the optional chaining operator. You can try to fix your config, fall back to if statements, or even this.willShowSub && this.willShowSub.remove();

ymeetme pushed a commit to ymeetme/react-native-gifted-chat that referenced this issue Sep 27, 2021
ymeetme pushed a commit to ymeetme/react-native-gifted-chat that referenced this issue Sep 27, 2021
ymeetme pushed a commit to ymeetme/react-native-gifted-chat that referenced this issue Sep 27, 2021
ymeetme pushed a commit to ymeetme/react-native-gifted-chat that referenced this issue Sep 27, 2021
@emendel
Copy link

emendel commented Nov 7, 2021

in MessageContainer.js constructor

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);
+        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);
+    this.willShowSub?.remove();
+    this.didShowSub?.remove();
+    this.willHideSub?.remove();
+    this.didHideSub?.remove();
};

you can apply this fix with https://github.com/ds300/patch-package until the maintainers fix this

Could you make a PR with this change so they can merge it?

@calcazar
Copy link

Any updates on this?

@Biplovkumar
Copy link

Any update?

@Biplovkumar
Copy link

        this.attachKeyboardListeners = () => {
            const { invertibleScrollViewProps: invertibleProps } = this.props;
            if (invertibleProps) {
                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;
            this.willShowSub?.remove();
            this.didShowSub?.remove();
            this.willHideSub?.remove();
            this.didHideSub?.remove();
        };
        

just need to update these lines in node_modules/react-native-gifted-chat/lib/MessageContainer.jsthis file.
It is temporary solution.

@sheggietyn
Copy link

update

@mehdinourollah
Copy link

I still have this issue ...any update on patch?!
React Native version = 0.66.0

@meirav-s
Copy link

meirav-s commented Feb 8, 2022

also me, Im waiting to the fix to be published.
any update on it?
its urgent...

@stale
Copy link

stale bot commented Apr 17, 2022

Sorry, but this issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. BTW Thank you for your contributions 😀 !!!

@stale stale bot added the wontfix label Apr 17, 2022
@habovh
Copy link

habovh commented Apr 17, 2022

I'm not sure a fix has been issued, so please remove the Stale label unless the event listeners have actually been updated.

@stale stale bot removed the wontfix label Apr 17, 2022
@Johan-dutoit
Copy link
Collaborator

Closing as this is fixed in latest beta.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests