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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

The application crashes when the component is unmounted, caused by the fact that DeviceEventEmitter does not recognize that it has the removeListener method. #747

Open
Sacre-MBIKU-WAKANE opened this issue Aug 25, 2023 · 3 comments

Comments

@Sacre-MBIKU-WAKANE
Copy link

Hi! 馃憢

Firstly, thanks for your work on this project! 馃檪

Today I used patch-package to patch react-native-modal@9.0.0 for the project I'm working on.

DeviceEventEmitter.removeListener(

  • "didUpdateDimensions",
  • this.handleDimensionsUpdate
  • ) => returns an error removeListener is not a function.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-modal/src/index.js b/node_modules/react-native-modal/src/index.js
index e4ca746..c8e154a 100644
--- a/node_modules/react-native-modal/src/index.js
+++ b/node_modules/react-native-modal/src/index.js
@@ -105,7 +105,8 @@ class ReactNativeModal extends Component {
     deviceWidth: Dimensions.get("window").width,
     deviceHeight: Dimensions.get("window").height,
     isSwipeable: this.props.swipeDirection ? true : false,
-    pan: null
+    pan: null,
+    eventEmitter: null
   };
 
   isTransitioning = false;
@@ -163,17 +164,18 @@ class ReactNativeModal extends Component {
     if (this.state.isVisible) {
       this.open();
     }
-    DeviceEventEmitter.addListener(
+    const eventEmitter = DeviceEventEmitter.addListener(
       "didUpdateDimensions",
       this.handleDimensionsUpdate
     );
+    this.setState({eventEmitter})
   }
 
   componentWillUnmount() {
-    DeviceEventEmitter.removeListener(
-      "didUpdateDimensions",
-      this.handleDimensionsUpdate
-    );
+    if(this.state.eventEmitter) {
+      this.state.eventEmitter.remove()
+    }
+   
   }
 
   componentDidUpdate(prevProps, prevState) {

This issue body was partially generated by patch-package.

@luca-tomasetti
Copy link

I had the same problem but updating to the latest version fix it for me.

@Hady207
Copy link

Hady207 commented Sep 23, 2023

Im on the latest version and i'm facing the same problem

@zlanich
Copy link

zlanich commented Oct 21, 2023

I am also having this issue on the latest version, and it's crashing the app :(

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

4 participants