achorein / expo-share-intent-demo

React Native Expo Share Intent Demonstration
90 stars 9 forks source link

fix: pending callbacks #17

Closed Randall71 closed 9 months ago

Randall71 commented 1 year ago

When using actual patch, on Android i get a lot of warning due to promise not handle correctly inside react-native-action-receive-sharing-intent.

Please report: Excessive number of pending callbacks: 501. Some pending callbacks that might have leaked by never being called from native code: {"208":{"module":"ReceiveSharingIntent","method":"getFileNames"},"3428":{"module":"ReceiveSharingIntent","method":"getFileNames"},"21703":{},"21707":{},"21711":{},"21715":{},"21719":{},"21723":{},"21727":{},"21731":{},"21735":{},"21739":{},"21743":{},"21747":{},"21751":{},"21755":{},"21759":{},"21763":{},"21767":{},"21771":{},"21775":{},"21779":{},"21783":{},"21787":{},"21791":{},"21795":{},"21799":{},"21803":{},"21807":{},"21811":{},"21815":{},"21819":{},"21823":{},"21827":{},"21831":{},"21835":{},"21839":{},"21843":{},"21847":{},"21851":{},"21855":{},"21859":{},"21863":{},"21867":{},"21871":{},"21875":{},"21879":{},"21883":{},"21887":{},"21891":{},"...(truncated keys)...":451}

I updated it to handle promise correctly and structure a little.

achorein commented 1 year ago

good idea, but during my test i got a compilation error on yarn android

/Users/anselme/project/expo-share-intent-demo/node_modules/react-native-receive-sharing-intent/android/src/main/java/com/reactnativereceivesharingintent/ReceiveSharingIntentHelper.java:109: error: no suitable method found for reject(no arguments)
      promise.reject();
Randall71 commented 1 year ago

@achorein fixed, all is good now 🎉

achorein commented 1 year ago

I'm wondering how to handle the state "no share intent detected",

When you simply run the app without sharing anything, the hook call ReceiveSharingIntent?.getReceivedFiles() which doesn't have any data. with this new code we got an error to handle :

useShareIntent[mount] error [Error: Type is null]

IMHO, empty data doesn't mean an error, in that case we should resolve the promise with an empty data ([]) and update the useShareIntent hook, something like that :

    ReceiveSharingIntent?.getReceivedFiles(
      (data) => {
        if (!data || data.length === 0) {
           console.log("useShareIntent[mount] no share intent detected");
           return;
        }
      }
  )
achorein commented 1 year ago

@Randall71 just updated the patch here https://github.com/achorein/expo-share-intent-demo/commit/3b684159575e3a8c115053089839f3f8a52933d6, but cannot update your branch.

Working find on android, i'm looking to update the ios side now

achorein commented 9 months ago

continued in #34