Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add meta info (like title) to share intent object on Android #44

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,13 @@ export default const App = () => {
const { shareIntent } = useShareIntent();
```

| attribute | description | example |
| -------------------- | ----------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| `shareIntent.text` | raw text from text/weburl (ios) and text/\* (android) | "`some text`", "`http://example.com`", "`Hey, Click on my link : http://example.com/nickname`" |
| `shareIntent.webUrl` | link extracted from raw text | `null`, "`http://example.com`", "`http://example.com/nickname`" |
| `shareIntent.files` | image / movies / audio / files with name, path, mimetype and size (in octets) | `[{ path: "file:///local/path/filename", mimeType: "image/jpeg", fileName: "originalFilename.jpg", size: 2567402 }]` |
| attribute | description | example |
|--------------------------|-------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------|
| `shareIntent.text` | raw text from text/weburl (ios) and text/\* (android) | "`some text`", "`http://example.com`", "`Hey, Click on my link : http://example.com/nickname`" |
| `shareIntent.webUrl` | link extracted from raw text | `null`, "`http://example.com`", "`http://example.com/nickname`" |
| `shareIntent.files` | image / movies / audio / files with name, path, mimetype and size (in octets) | `[{ path: "file:///local/path/filename", mimeType: "image/jpeg", fileName: "originalFilename.jpg", size: 2567402 }]` |
| `shareIntent.meta` | meta object which contains extra information about the share intent | `{ title: "My cool blog article" }` |
| `shareIntent.meta.title` | optional title property sent by other app. Currently only filled on Android | `My cool blog article` |

#### Customize Content Types in `app.json`

Expand All @@ -164,7 +166,7 @@ Simply choose content types you need :
```

| Option | Values |
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| iosActivationRules | Allow **text** sharing with `"NSExtensionActivationSupportsText": true`<br/>**Url** sharing with `"NSExtensionActivationSupportsWebURLWithMaxCount": 1` and `"NSExtensionActivationSupportsWebPageWithMaxCount": 1`<br/>**Images** sharing with `"NSExtensionActivationSupportsImageWithMaxCount": 1`<br/>**Videos** sharing with `"NSExtensionActivationSupportsMovieWithMaxCount": 1`<br/>**Files and audio** sharing with `"NSExtensionActivationSupportsFileWithMaxCount": 1`<br/>_default value_: `{ "NSExtensionActivationSupportsWebURLWithMaxCount": 1, "NSExtensionActivationSupportsWebPageWithMaxCount": 1 }"`<br/>_More info in apple developper doc [here](https://developer.apple.com/documentation/bundleresources/information_property_list/nsextension/nsextensionattributes/nsextensionactivationrule)_ |
| androidIntentFilters | **one file sharing** array of MIME types :`"text/*"` / `"image/*"` / `"video/*"` / `"*/*"`<br/>_default value_: `["text/*"]` (text and url) |
| androidMultiIntentFilters | **multiple files sharing** array of MIME types : `"image/*"` / `"video/*"` / `"audio/*`/ `"*/*"`<br/>_default value_: `[]` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ class ExpoShareIntentModule : Module() {
if (intent.type!!.startsWith("text")) {
// text / urls
if (intent.action == Intent.ACTION_SEND) {
notifyShareIntent(mapOf( "text" to intent.getStringExtra(Intent.EXTRA_TEXT), "type" to "text"))
notifyShareIntent(mapOf(
"text" to intent.getStringExtra(Intent.EXTRA_TEXT),
"type" to "text",
"meta" to mapOf(
"title" to intent.getCharSequenceExtra(Intent.EXTRA_TITLE),
)
))
} else if (intent.action == Intent.ACTION_VIEW) {
notifyShareIntent(mapOf( "text" to intent.dataString, "type" to "text"))
} else {
Expand Down
3 changes: 3 additions & 0 deletions example/basic/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export default function App() {
{hasShareIntent ? "SHARE INTENT FOUND !" : "NO SHARE INTENT DETECTED"}
</Text>
{!!shareIntent.text && <Text style={styles.gap}>{shareIntent.text}</Text>}
{!!shareIntent.meta?.title && (
<Text>{JSON.stringify(shareIntent.meta)}</Text>
)}
{shareIntent?.files?.map((file) => (
<Image
key={file.path}
Expand Down
17 changes: 13 additions & 4 deletions src/ExpoShareIntentModule.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ export type ShareIntentOptions = {
onResetShareIntent?: () => void;
};

export type ShareIntentMeta = {
title?: string;
};

export type ShareIntent = {
files: ShareIntentFile[] | null;
text: string | null;
webUrl: string | null;
type: "media" | "file" | "text" | "weburl" | null;
meta?: ShareIntentMeta;
};

export interface ShareIntentFile {
Expand All @@ -27,8 +32,14 @@ export interface ShareIntentFile {
size: number | null;
}

export type IosShareIntent = {
export type BaseNativeShareIntent = {
text?: string;
files?: ShareIntentFile[];
type: "file" | "text";
meta?: ShareIntentMeta;
};

export type IosShareIntent = BaseNativeShareIntent & {
files?: IosShareIntentFile[];
type: "media" | "file" | "text" | "weburl";
};
Expand All @@ -41,10 +52,8 @@ export interface IosShareIntentFile {
fileSize?: number;
}

export type AndroidShareIntent = {
text?: string;
export type AndroidShareIntent = BaseNativeShareIntent & {
files?: AndroidShareIntentFile[];
type: "file" | "text";
};

export interface AndroidShareIntentFile {
Expand Down
3 changes: 3 additions & 0 deletions src/useShareIntent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ const parseShareIntent = (value, options): ShareIntent => {
text: shareIntent.text,
webUrl,
type: webUrl ? "weburl" : "text",
meta: {
title: shareIntent.meta?.title ?? undefined,
},
};
} else {
const files =
Expand Down
Loading