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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[V2] Events: No way to listen to screen pop when performed via gesture or hitting back button #3941

Closed
jordanfloyd opened this issue Sep 7, 2018 · 10 comments

Comments

@jordanfloyd
Copy link

Issue Description

When registering a command listener, the only events subscribed to are the ones explicitly called on Navigation class from my code. The implicit commands (gesture swipe back, system back button) don't get picked up by this listener so there is effectively no way to detect that they happened.

The componentDidAppear/didDisappear listeners could be used if there was context with the event (command that resulted in the screen being mounted/unmounted).

Ultimately what I'm trying to do is trigger some side effect on screen pop. I can override the back button with my own button and manually call the pop command, but that doesn't solve the gesture back case and it seems like this is a departure from the way that v1 handled this, which was to provide a handler for all events and then let the implementer filter out as needed.

Steps to Reproduce / Code Snippets / Screenshots

Navigation.events().registerCommandListener((name, params) => {
  // do something here
}

Environment

  • React Native Navigation version: 2.0.2514
  • React Native version: 0.55.1
  • Platform(s) (iOS, Android, or both?): Both
  • Device info (Simulator/Device? OS version? Debug/Release?): Simulator/Emulator, iOS 11.4, Android 8.0, Debug
@ShaMan123
Copy link

+1

@vladkosinov
Copy link

Very important for me too

@TuTejsy
Copy link

TuTejsy commented Nov 14, 2019

I have the same problem. @guyca Did you work on this?

@guyca
Copy link
Collaborator

guyca commented Dec 9, 2019

Hey guys, we'll add the following event to support this use case:

Navigation.events().registerScreenPoppedListener({ componentId } = {
});

The event will be emitted each time a screen is popped, regardless of whether it was popped by Navigation.pop() command or gesture.

@guyca guyca closed this as completed in 71af559 Dec 18, 2019
@msqar
Copy link

msqar commented Jan 29, 2020

@guyca hey guy, is telling me that registerScreenPoppedListener is not a function. In what version of RNN was this added? I'm using 3.7.0. Thanks!

EDIT: I installed the latest possible version of RNN, which is 4.6.0, at least is not throwing any error but the callback is not being executed.

Within my component constructor I have:

this.screenPoppedListener = Navigation.events().registerScreenPoppedListener(({ componentId }) => {
            console.log('screenPopped > ', componentId);
        });

Then i do screenPoppedListener.remove() during WillUnmount.

But is never showing the console log.

Any idea?

@guyca
Copy link
Collaborator

guyca commented Jan 30, 2020

Hey @msqar On which platform are you not getting the event?

@msqar
Copy link

msqar commented Jan 31, 2020

@guyca on iOS 13, didn't test on Android though. I ended up using a different library that would handle event listeners to solve it :( since i couldn't make this one work, don't know why, even by updating to latest.

vshkl pushed a commit to vshkl/react-native-navigation that referenced this issue Feb 5, 2020
Called each time a screen is popped, either due to `Navigation.pop` or pop gesture.
closes wix#3941 

Navigation.events().registerScreenPoppedListener(({ componentId }) => {

});
@habovh
Copy link
Contributor

habovh commented Apr 23, 2020

@guyca can confirm the registerScreenPoppedListener event is never fired on iOS 13.

Checked on iOS 13.4.1 with RNN version 6.4.0

@eightyfive
Copy link

I'm using react-native-navigation@^4 and I can confirm the event is not fired both in iOS 12 & 13 (Simulators).

@guyca
Copy link
Collaborator

guyca commented Oct 13, 2020

@eightyfive screenPopped event works as expected on latest RNN, please upgrade and open a new issue with a reproduction if you think there's still an issue 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants