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

[V2][android] Linking "url" event never fire. #4539

Closed Darkilen closed 4 years ago

Darkilen commented 5 years ago

Issue Description

On Android using RNN v2, the Linking 'url' event listener does not fire.

Re-open of #3581 since it was closed unresolved.

Steps to Reproduce / Code Snippets / Screenshots

const { Navigation } = require('react-native-navigation');
const { registerScreens } = require('./screens');
const { Platform } = require('react-native');

function start() {
  registerScreens();
  Navigation.events().registerAppLaunchedListener(() => {
     Linking.addEventListener("url", event => {
        console.log("url", { event });
     });
     // Other code to launch app
  }) 
}

Environment

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest Detox and report back. Thank you for your contributions.

Darkilen commented 5 years ago

This issue is still relevant.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest Detox and report back. Thank you for your contributions.

Darkilen commented 5 years ago

This issue is still relevant.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest Detox and report back. Thank you for your contributions.

Darkilen commented 5 years ago

This issue is still relevant.

draperunner commented 5 years ago

I am also trying to get the URL from deep linking, but there's never a URL.

componentDidMount() {
  Linking.getInitialURL().then((url) => {
          console.log('Did we come from a URL?')
          if (url) {
              console.log(`Initial url is: ${url}`)
          }
      }).catch(err => console.error('app: An error occurred', err)

I am trying on the iOS simulator. I am opening Safari, entering <myappid>://testpath. It boots the app and takes me to it, but no URL is logged. When the app is already launched in the background, it works.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest Detox and report back. Thank you for your contributions.

Darkilen commented 5 years ago

This issue is still relevant.

piuholo commented 5 years ago

Linking.getInitialURL() works for me but I cannot get the listener Linking.addEventListener('url', handler) to fire with RNN.

mtzfactory commented 5 years ago

Hi, I have the same Issue as @draperunner ...

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest Detox and report back. Thank you for your contributions.

piuholo commented 5 years ago

Still an issue

oxy88 commented 5 years ago

Still. Initial launch = not working Background = works

I decided to move to react-navigation and it works perfectly

randomBrainstormer commented 5 years ago

I have the same problem in version 3.2.0 for iOS.

randomBrainstormer commented 5 years ago

I was able to get the Linking.addEventListener('url', handler) event to fire by adding the check described here like this:

- (BOOL)application:(UIApplication *)application
   openURL:(NSURL *)url
   options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{

  if ([RCTLinkingManager application:application openURL:url sourceApplication:nil annotation:nil]) {
    return YES;
  }

 // default to normal snippet handling
  return [RCTLinkingManager application:application openURL:url options:options];
}

Edit: I've rolled back to V2 so haven't test this fix in V3 yet.

zarvedan commented 4 years ago

@Darkilen I had the same issue (Only Android with RNN V2) when clicking on a Facebook post that redirects to my app. The intent ACTION was "com.facebook.blabla" and was not catched on RN side. By forcing the intent action to ACTION_VIEW, the Linking "url" event is fired correctly.

2 lines to add on MainActivity's onCreate method:

Intent intent = getIntent(); // <- add this line
intent.setAction(Intent.ACTION_VIEW); // <- add this line

1 line to add on NavigationActivity:

@Override
    public void onNewIntent(Intent intent) {
        intent.setAction(Intent.ACTION_VIEW); // <- add this line
        if (!getReactGateway().onNewIntent(intent)) {
            super.onNewIntent(intent);
        }
    }

I hope it can resolves your issue.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest version and report back. Thank you for your contributions.

stale[bot] commented 4 years ago

The issue has been closed for inactivity.

bmbmjmdm commented 3 years ago

This is still an issue. Please stop trying to close this, bot -.-

zarvedan commented 3 years ago

@Darkilen I had the same issue (Only Android with RNN V2) when clicking on a Facebook post that redirects to my app. The intent ACTION was "com.facebook.blabla" and was not catched on RN side. By forcing the intent action to ACTION_VIEW, the Linking "url" event is fired correctly.

2 lines to add on MainActivity's onCreate method:

Intent intent = getIntent(); // <- add this line
intent.setAction(Intent.ACTION_VIEW); // <- add this line

1 line to add on NavigationActivity:

@Override
    public void onNewIntent(Intent intent) {
        intent.setAction(Intent.ACTION_VIEW); // <- add this line
        if (!getReactGateway().onNewIntent(intent)) {
            super.onNewIntent(intent);
        }
    }

I hope it can resolves your issue.

Helping myself 2 years later with same issue on RNN V7 ! :)