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

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

Open
manarfalah opened this issue Feb 2, 2023 · 0 comments

Comments

@manarfalah
Copy link

Hi! 馃憢

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

Today I used patch-package to patch react-native-router-flux@4.3.1 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.

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

1 participant