mmazzarolo / react-native-modal-datetime-picker

A React-Native datetime-picker for Android and iOS
MIT License
2.98k stars 399 forks source link

`DeviceEventEmitter.removeListener` is not supported on React Native 0.70+ #681

Closed fansilva1991 closed 1 year ago

fansilva1991 commented 1 year ago

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

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

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-modal-datetime-picker/src/Modal.js b/node_modules/react-native-modal-datetime-picker/src/Modal.js
index 6e5f95d..1466d08 100644
--- a/node_modules/react-native-modal-datetime-picker/src/Modal.js
+++ b/node_modules/react-native-modal-datetime-picker/src/Modal.js
@@ -48,10 +48,12 @@ export class Modal extends Component {
   }

   componentWillUnmount() {
-    DeviceEventEmitter.removeListener(
-      "didUpdateDimensions",
-      this.handleDimensionsUpdate
-    );
+    try {
+      DeviceEventEmitter.removeListener(
+        "didUpdateDimensions",
+        this.handleDimensionsUpdate
+      );
+    } catch (e) {} 
     this._isMounted = false;
   }

This issue body was partially generated by patch-package.

fansilva1991 commented 1 year ago

Looks like this is happening because DeviceEventEmitter.removeListener has been removed after being deprecated for a while.

mmazzarolo commented 1 year ago

πŸ‘‹ I think a good starting point would be to use https://github.com/mmazzarolo/react-native-modal-datetime-picker/pull/669 and support the new device dimension update API instead

joe-brabben commented 1 year ago

@mmazzarolo Hi any updates on this being landed as it is currently crashing devices. Thanks

mmazzarolo commented 1 year ago

Hey I'm currently on parental leave and can't work directly on the codebase. If you're willing to update #669 adding support for the updated Dimensions API I can give it a review and try it out.

joe-brabben commented 1 year ago

@mmazzarolo Hey sorry for the delay was busy on new native version for a bit. I've submitted the pull request now so should all be good. Thanks

khzouroussama commented 1 year ago

@fansilva1991 this will be fixed if you update the library, there is no need for this patch, the deprecated API DeviceEventEmitter.removeListener has been already replaced with listener.remove()

@mmazzarolo I don't think we need to do any changes here

image
mmazzarolo commented 1 year ago

@khzouroussama not sure I'm following, who replaced DeviceEventEmitter.removeListener with listener.remove()? πŸ‘€ It's still here in this lib.

khzouroussama commented 1 year ago

I believe it was changed here https://github.com/mmazzarolo/react-native-modal-datetime-picker/pull/591 I was facing the same issue before because my app was on an older version, so it is not reproducible on the recent versions

mmazzarolo commented 1 year ago

Ah, right, I thought this issue was about something different. Good call, thanks!

joe-brabben commented 1 year ago

@mmazzarolo sounds fixed. Want me to close the pull request???