achorein / expo-share-intent

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

[FeatureRequest] Include the type of request in the ShareIntent? #25

Closed MohamedBassem closed 6 months ago

MohamedBassem commented 6 months ago

First of all, thanks for the plugin, it was crucial for an app that I'm building!

I have a feature request. It seems that when the intent either contains a WebURL or a text, both end up in the ShareIntent in the text field. Can we maybe add a type union field in the share intent that contains the original intent type? Thanks!

achorein commented 6 months ago

👋 That's sounds like a good idea !

You mean something like this :

type ShareIntent = {
  files: ...;
  text: string | null;
  type: "text" | "url" | null;
};

what about this :

type ShareIntent = {
  files: ...;
  text: string | null;
  link: string | null;
};

under the hood i only have this information on iOS, it's always a text on android. so for compatibility reason i have to do a manual check with something like that

    const link: string | undefined = first(
      text?.match(/[(http(s)?)://(www.)?-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/gi),
    );
    if (!link || !link?.startsWith('http')) {
      console.log('wrong link:', link, text);
    } else {
      console.log('text contain a link', link)
    }

for example when you share a link from the amazon app it comes with some text before the real url, so we need to isolate the information.

The better way to add this feature is to have text (with raw data) and link return by the hook :

const { shareIntent } = useShareIntent();
console.log(shareIntent.text); // "Hello, click on my link http://example.com"
console.log(shareIntent.link); // "http://example.com"

Alright, it's on my TODO :)

achorein commented 6 months ago

@MohamedBassem available in v1.2.0! see README for more details.

I also add some informations about type and filename.