-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Library not Compatible with React Native 0.65.1 - Keyboard.removeListener is not a function #2109
Comments
That looks like it'll cause memory leaks. As the events are being added in the function above. So effectively the initial ones are never removed. Here's the patch I went with diff --git a/node_modules/react-native-gifted-chat/lib/MessageContainer.js b/node_modules/react-native-gifted-chat/lib/MessageContainer.js
index 193772a..c639b01 100644
--- a/node_modules/react-native-gifted-chat/lib/MessageContainer.js
+++ b/node_modules/react-native-gifted-chat/lib/MessageContainer.js
@@ -47,6 +47,10 @@ const styles = StyleSheet.create({
},
});
export default class MessageContainer extends React.PureComponent {
+ keyboardWillShowSubscription = null;
+ keyboardDidShowSubscription = null;
+ keyboardWillHideSubscription = null;
+ keyboardDidHideSubscription = null;
constructor() {
super(...arguments);
this.state = {
@@ -55,18 +59,18 @@ 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);
+ this.keyboardWillShowSubscription = Keyboard.addListener('keyboardWillShow', invertibleProps.onKeyboardWillShow);
+ this.keyboardDidShowSubscription = Keyboard.addListener('keyboardDidShow', invertibleProps.onKeyboardDidShow);
+ this.keyboardWillHideSubscription = Keyboard.addListener('keyboardWillHide', invertibleProps.onKeyboardWillHide);
+ this.keyboardDidHideSubscription = 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.keyboardWillShowSubscription?.remove()
+ this.keyboardDidShowSubscription?.remove()
+ this.keyboardWillHideSubscription?.remove()
+ this.keyboardDidHideSubscription?.remove()
};
this.renderTypingIndicator = () => {
if (Platform.OS === 'web') {
|
Can you make a PR with this change so they can update the package? |
@emendel I don't mind, but I think this package is abandoned. With the last change being made 8 months ago. |
I think we need a fork... |
You're probably right. Do you know any other packages that could be an alternative to this? |
I used npm patch-package to fix it on my local machine. It was an easy setup |
https://github.com/facebook/react-native/releases/tag/v0.66.3 re-implements the method (although it is still deprecated). |
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 😀 !!! |
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch
[email protected]
for the project I'm working on.Solving this issue: #2090 and #2094
Here is the diff that solved my problem:
This issue body was partially generated by patch-package.
The text was updated successfully, but these errors were encountered: