React-native-navigation: [v2] How to unsubscribe from Navigation.events() listeners?

Created on 26 Dec 2018  ·  1Comment  ·  Source: wix/react-native-navigation

Issue Description

We lave listeners like
Navigation.events().registerComponentDidDisappearListener(({ componentId, componentName }) => {});
How can we unsubscribe from it? Do we even need to do it?

Steps to Reproduce / Code Snippets / Screenshots

Navigation.events().registerComponentDidDisappearListener(({ componentId, componentName }) => {});


Environment

  • React Native Navigation version: 2.4.0
  • React Native version: 0.57.8
  • Platform(s) (iOS, Android, or both?): both
  • Device info (Simulator/Device? OS version? Debug/Release?): all

Most helpful comment

@rendomnet All methods of Navigation.events() return the instance of event subscription.
You can use remove method of it.

eventSubscription1 = Navigation.events().bindComponent(this);
eventSubscription2 = Navigation.events().registerComponentDidDisappearListener(({ componentId, componentName }) => {});
...
eventSubscription1.remove();
eventSubscription2.remove();

Hope this helps you!

>All comments

@rendomnet All methods of Navigation.events() return the instance of event subscription.
You can use remove method of it.

eventSubscription1 = Navigation.events().bindComponent(this);
eventSubscription2 = Navigation.events().registerComponentDidDisappearListener(({ componentId, componentName }) => {});
...
eventSubscription1.remove();
eventSubscription2.remove();

Hope this helps you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

edcs picture edcs  ·  3Comments

henrikra picture henrikra  ·  3Comments

yayanartha picture yayanartha  ·  3Comments

charlesluo2014 picture charlesluo2014  ·  3Comments

yedidyak picture yedidyak  ·  3Comments