doomsower / react-native-modal-popover

React-Native pure JS popover that uses Modal
MIT License
322 stars 45 forks source link

Update remove deprecated function removeEventListener #76

Open napro8509 opened 2 years ago

napro8509 commented 2 years ago

Hi! ๐Ÿ‘‹

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

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

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-modal-popover/lib/PopoverController.js b/node_modules/react-native-modal-popover/lib/PopoverController.js
index 005c07f..9a0eb11 100644
--- a/node_modules/react-native-modal-popover/lib/PopoverController.js
+++ b/node_modules/react-native-modal-popover/lib/PopoverController.js
@@ -62,10 +62,10 @@ class PopoverController extends React.PureComponent {
         this.closePopover = () => this.setState({ showPopover: false });
     }
     componentDidMount() {
-        react_native_1.Dimensions.addEventListener('change', this.onOrientationChange);
+        this.listener = react_native_1.Dimensions.addEventListener('change', this.onOrientationChange);
     }
     componentWillUnmount() {
-        react_native_1.Dimensions.removeEventListener('change', this.onOrientationChange);
+       this.listener?.remove?.();
     }
     render() {
         return this.props.children({
diff --git a/node_modules/react-native-modal-popover/lib/usePopover.js b/node_modules/react-native-modal-popover/lib/usePopover.js
index 75cc72a..820f98d 100644
--- a/node_modules/react-native-modal-popover/lib/usePopover.js
+++ b/node_modules/react-native-modal-popover/lib/usePopover.js
@@ -45,9 +45,9 @@ function usePopover(calculateStatusBar = false) {
                 requestAnimationFrame(openPopover);
             }
         };
-        react_native_1.Dimensions.addEventListener('change', onOrientationChange);
+        const listener = react_native_1.Dimensions.addEventListener('change', onOrientationChange);
         return () => {
-            react_native_1.Dimensions.removeEventListener('change', onOrientationChange);
+           listener?.remove?.();
         };
     }, [showPopover, openPopover]);
     return result;

This issue body was partially generated by patch-package.