wix / react-native-navigation

A complete native navigation solution for React Native
https://wix.github.io/react-native-navigation/
MIT License
13.04k stars 2.67k forks source link

Navigation.events().registerAppLaunchedListener never been triggered #4657

Closed JoseFMP closed 5 years ago

JoseFMP commented 5 years ago

Issue Description

The event

Navigation.events().registerAppLaunchedListener

is never trieggered.

Steps to Reproduce / Code Snippets / Screenshots

console.log('Trying to subscribe to AppLaunched event'); // this line is hit Navigation.registerComponent('LandingScreen', componentGenerator); Navigation.events().registerAppLaunchedListener(() => { console.log('Hello world'); // this line is never hit Navigation.setRoot({ root: { component: { name: 'LandingScreen', id: 'LandingScreen', } } }); }); console.log('Finished subscribing to event'); // this line is hit


The callback for the event `registerAppLaunchedListener` is never called.
Expected behavior: The callback is executed

---
### Environment
* React Native Navigation version: 0.58.1
* React Native version: 2.8.0
* Platform(s) (iOS, Android, or both?): Both
* Device info (Simulator/Device? OS version? Debug/Release?): LG V20
jinshin1013 commented 5 years ago

Is the other console.log being called? Can you share the full index.js or your entry file?

JoseFMP commented 5 years ago

@jinshin1013 I updated it in the original message. So whatever is not related to the event is working fine. But the event is not triggered.

jinshin1013 commented 5 years ago

Do you get any errors? or just blank screen?

JoseFMP commented 5 years ago

@jinshin1013 I get no error, just blank screen and the event no triggered (i.e. debugger does not stop in break points in the callback, the log messages do not appear, I also tried to throw errors in the block to see if they would appear).

jinshin1013 commented 5 years ago

It may sound stupid but you did follow all the instruction to install react-native-navigation, right? If you could prep up a reproducible project on your Github, I could have a look at it. There isn't really anything any of us could do without more info.

jinshin1013 commented 5 years ago

It may be due to react-native-navigation not supporting RN ^0.58. Try downgrading to 0.57.8 and see if it builds.

JoseFMP commented 5 years ago

@jinshin1013 Yes I followed the instructions. I will share it if necessary but it is really just a boiler plate. I will try to downgrade and see what happens.

bobmulder commented 5 years ago

I had the same and saw your issue. The mistake I made was that the listener was registered too early. Try to register the listener (with a console.log) as soon as possible. Hope it works for you!

support[bot] commented 5 years ago

We use the issue tracker exclusively for bug reports and feature requests. This issue appears to be a general usage or support question. Instead, please ask a question on Stack Overflow with the react-native-navigation tag.

dmchoull commented 5 years ago

@bobmulder Can you rephrase or elaborate on what your solution was? I'm not clear on what it means to register the listener too early or how you changed that. Are you doing something different than the example in the documentation (which is not working for me, even after downgrading RN to 0.57.8)

marf commented 5 years ago

Same problem here, in iOS it works, while in Android the event is never triggered.

@bobmulder @dmchoull Have you found a solution to the problem?

dmchoull commented 5 years ago

@marf No, unfortunately not. I've just switched to using react-navigation for now

TheBurgerShot commented 5 years ago

@marf @dmchoull @bobmulder

I was experiencing the same issue. On iOS the event was fired, on Android it wasn't.

In my case, setting the registerAppLaunchedListener before the promised did the trick.

So changing this:

Promise.all([
        Icon.getImageSource(Platform.OS === 'android' ? "md-map" : "ios-map", 30),
        Icon.getImageSource(Platform.OS === 'android' ? "md-list" : "ios-list", 30),
        Icon.getImageSource(Platform.OS === 'android' ? "md-more" : "ios-more", 30)
]).then(sources => {
      console.log('Loaded sources'); // <-- This one does fire on android
      Navigation.events().registerAppLaunchedListener(() => {
          console.log('App launched'); // <-- This one doesn't fire on android
           ...
      });
})

to this:

Navigation.events().registerAppLaunchedListener(() => {
    Promise.all([
        Icon.getImageSource(Platform.OS === 'android' ? "md-map" : "ios-map", 30),
        Icon.getImageSource(Platform.OS === 'android' ? "md-list" : "ios-list", 30),
        Icon.getImageSource(Platform.OS === 'android' ? "md-more" : "ios-more", 30)
    ]).then(sources => {
        console.log('Loaded sources'); // <-- This one does fire on android
    })
})

Your case might be different. But this did the trick for me. Hope it helps.

ShaneMatthias commented 5 years ago

"Register the listener with registerAppLaunchedListener as soon as possible - it should be one of the first lines in your index.js file. If you're observing a "white screen" or a hanging splash screen after relaunching your app, it probably means Navigation.setRoot isn't called once the app has launched. Perhaps the listener was registered too late." - From the docs