Skip to content

Replace deprecated Linking.removeEventListener(), to remove() , throwing error undefined is not a function #3844

@manarfalah

Description

@manarfalah

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.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-router-flux/src/Router.js b/node_modules/react-native-router-flux/src/Router.js
index 6f595e4..c9baf20 100644
--- a/node_modules/react-native-router-flux/src/Router.js
+++ b/node_modules/react-native-router-flux/src/Router.js
@@ -6,6 +6,8 @@ import defaultStore from './defaultStore';
 import pathParser from './pathParser';
 
 class App extends React.Component {
+  hardwareBackPressSubscriber ;
+  urlSubscriber;
   static propTypes = {
     navigator: PropTypes.func,
     backAndroidHandler: PropTypes.func,
@@ -22,17 +24,17 @@ class App extends React.Component {
   };
 
   componentDidMount() {
-    BackHandler.addEventListener('hardwareBackPress', this.props.backAndroidHandler || this.onBackPress);
+    this.hardwareBackPressSubscriber = BackHandler.addEventListener('hardwareBackPress', this.props.backAndroidHandler || this.onBackPress);
 
     // If the app was "woken up" by an external route.
     Linking.getInitialURL().then(url => this.parseDeepURL(url));
     // Add an event listener for further deep linking.
-    Linking.addEventListener('url', this.handleDeepURL);
+   this.urlSubscriber = Linking.addEventListener('url', this.handleDeepURL);
   }
 
   componentWillUnmount() {
-    BackHandler.removeEventListener('hardwareBackPress', this.props.backAndroidHandler || this.onBackPress);
-    Linking.removeEventListener('url', this.handleDeepURL);
+    this.hardwareBackPressSubscriber.remove();
+    this.urlSubscriber.remove();
   }
 
   onBackPress = () => this.props.navigationStore.pop();

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions