achorein / expo-share-intent

🚀 Simple share intent in an Expo Native Module
MIT License
177 stars 15 forks source link

On Android first launch, files must contain a video for it to work properly #122

Open Audeos opened 2 days ago

Audeos commented 2 days ago

I have applied the linking you provided in react-navigation-example. I also provided below stuff in app.json:

"androidIntentFilters": ["image/*", "video/*"], "androidMultiIntentFilters": ["image/*", "video/*"]

Everything works as intended. However on android release build, if you share files that only contain image, the getInitialUrl function claims needRedirect to be false, and it does not navigate to the screen I asked for it to. It does work if at least one of your shared files is a video. However, even in that case, it's still false. What's different between the video sharing or image sharing is this pending value:

const shareIntentEventSubscription = addStateListener((event) => {
      // REQUIRED FOR ANDROID WHEN APP IS IN BACKGROUND
      console.debug(
        "react-navigation[subscribe] shareIntentStateListener",
        event.value,
      );
      if (event.value === "pending") { // this was the thing that videos fire and images don't
        listener(`${Constants.expoConfig?.scheme}://shareintent`);
      }
    });

and getInitialUrl looks like to be false all the time.

In development build, neither the ios or android works as intended, probably because expo is in the way. So I had to test these on release build, logging with alerts.

achorein commented 2 days ago

for the app, there is no difference between image and video.

on android we are not using deep link (using scheme only on ios), so it's normal that getInitialURL is always false.

you should use hasShareIntent(getShareExtensionKey()); as mention in the example. it calls share-intent native module to check if we got pending request to handle.

Audeos commented 2 days ago

What I meant is, const needRedirect = hasShareIntent(getShareExtensionKey()); above expression is false. It's inside getInitialUrl in the link you provide.

 async getInitialURL() {
    // REQUIRED FOR ANDROID FIRST LAUNCH
    const needRedirect = hasShareIntent(getShareExtensionKey());
    console.debug(
      "react-navigation[getInitialURL] redirect to ShareIntent screen:",
      needRedirect,
    );
    if (needRedirect) {
      return `${Constants.expoConfig?.scheme}://shareintent`;
    }
    // As a fallback, do the default deep link handling
    const url = await Linking.getInitialURL();
    return url;
  },
};