react-native-navigation icon indicating copy to clipboard operation
react-native-navigation copied to clipboard

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

Open Darkilen opened this issue 7 years ago • 21 comments

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

  • React Native Navigation version: 2.0.2438
  • React Native version: 0.56.0
  • Platform(s) (iOS, Android, or both?): Android
  • Device info (Simulator/Device? OS version? Debug/Release?): Simulator & Device - Android 8.1.0 - both

Darkilen avatar Jan 04 '19 17:01 Darkilen

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.

stale[bot] avatar Feb 17 '19 14:02 stale[bot]

This issue is still relevant.

Darkilen avatar Feb 17 '19 14:02 Darkilen

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.

stale[bot] avatar Mar 19 '19 15:03 stale[bot]

This issue is still relevant.

Darkilen avatar Mar 19 '19 18:03 Darkilen

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.

stale[bot] avatar Apr 18 '19 19:04 stale[bot]

This issue is still relevant.

Darkilen avatar Apr 19 '19 00:04 Darkilen

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.

draperunner avatar May 10 '19 12:05 draperunner

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.

stale[bot] avatar Jun 09 '19 14:06 stale[bot]

This issue is still relevant.

Darkilen avatar Jun 09 '19 17:06 Darkilen

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

piuholo avatar Jul 09 '19 13:07 piuholo

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

mtzfactory avatar Aug 07 '19 09:08 mtzfactory

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.

stale[bot] avatar Sep 06 '19 09:09 stale[bot]

Still an issue

piuholo avatar Sep 06 '19 10:09 piuholo

Still. Initial launch = not working Background = works

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

oxy88 avatar Sep 18 '19 02:09 oxy88

I have the same problem in version 3.2.0 for iOS.

randomBrainstormer avatar Oct 10 '19 16:10 randomBrainstormer

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.

randomBrainstormer avatar Oct 16 '19 09:10 randomBrainstormer

@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.

zarvedan avatar Nov 26 '19 09:11 zarvedan

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] avatar Mar 08 '20 09:03 stale[bot]

The issue has been closed for inactivity.

stale[bot] avatar Mar 15 '20 11:03 stale[bot]

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

bmbmjmdm avatar Apr 09 '21 16:04 bmbmjmdm