### Setup Example App
Source: https://github.com/achorein/expo-share-intent/blob/main/CONTRIBUTING.md
Navigate to the example app directory, install its dependencies, and clean previous builds.
```sh
cd example/basic
yarn install
yarn clean
```
--------------------------------
### Run Example App on Android
Source: https://github.com/achorein/expo-share-intent/blob/main/CONTRIBUTING.md
Command to run the example application on an Android device or emulator.
```sh
yarn android
```
--------------------------------
### Run Example App on iOS
Source: https://github.com/achorein/expo-share-intent/blob/main/CONTRIBUTING.md
Command to run the example application on an iOS device or simulator.
```sh
yarn ios
```
--------------------------------
### Install Project Dependencies
Source: https://github.com/achorein/expo-share-intent/blob/main/CONTRIBUTING.md
Run this command in the root directory to install all required dependencies for the project.
```sh
yarn install
```
--------------------------------
### Install expo-share-intent
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/README.md
Install the library using npm. This is the first step before using any of its features.
```bash
npm install expo-share-intent
```
--------------------------------
### Install expo-share-intent
Source: https://github.com/achorein/expo-share-intent/blob/main/README.md
Install the expo-share-intent package using either Yarn or npm.
```bash
yarn add expo-share-intent
# or
npm install expo-share-intent
```
--------------------------------
### Minimal Setup for Text & URLs
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/configuration.md
Configure app.json for basic sharing of text and URLs. This setup requires specifying the deep link scheme and including the plugin.
```json
{
"scheme": "my-app",
"plugins": ["expo-share-intent"]
}
```
--------------------------------
### Install expo-linking
Source: https://github.com/achorein/expo-share-intent/blob/main/README.md
For Expo SDK 52 and later, install the expo-linking package.
```bash
expo install expo-linking
```
--------------------------------
### Complete Usage Example for Expo Share Intent
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/api-reference-utils.md
Demonstrates how to use the useShareIntent hook and utility functions to get the app scheme, share extension key, and parse share data within an Expo component.
```typescript
import {
useShareIntent,
getScheme,
getShareExtensionKey,
parseShareIntent
} from "expo-share-intent";
// In a component
const { shareIntent } = useShareIntent();
// Get the app scheme
const scheme = getScheme();
console.log(scheme); // "my-app"
// Get the share extension key
const extensionKey = getShareExtensionKey();
console.log(extensionKey); // "my-appShareKey"
// Manually parse share data (usually done internally by the hook)
const parsed = parseShareIntent(jsonString, { debug: true });
console.log(parsed.type); // "weburl", "text", "media", or "file", or null
```
--------------------------------
### Example MainActivity Attributes for Share Intents
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/plugin-reference.md
This XML snippet shows an example of attributes applied to the MainActivity element in the AndroidManifest, including the `android:launchMode` attribute for proper share intent handling.
```xml
```
--------------------------------
### iOS Activation Rules Example
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/configuration.md
Configure which content types trigger the share extension on iOS. Use predefined options or a custom predicate format.
```json
"iosActivationRules": "SUBQUERY (predicateFormat)"
```
--------------------------------
### Basic Setup with ShareIntentProvider
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/api-reference-ShareIntentProvider.md
Wrap your app with ShareIntentProvider and use the useShareIntentContext hook to access shared content and reset it. Ensure it's placed above components that need access to the share intent.
```typescript
import { ShareIntentProvider, useShareIntentContext } from "expo-share-intent";
function Home() {
const { hasShareIntent, shareIntent, resetShareIntent } =
useShareIntentContext();
return (
{hasShareIntent && {shareIntent.text}}
);
}
export default function App() {
return (
);
}
```
--------------------------------
### Configure iOS activation rules for content types
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/INDEX.md
Specify which content types the iOS share extension can activate for. This example configures support for a single image.
```json
"iosActivationRules": { "NSExtensionActivationSupportsImageWithMaxCount": 1 }
```
--------------------------------
### Building Native Code for Expo Share Intent
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/00-START-HERE.txt
Commands to prebuild the native project and run it on iOS and Android simulators or devices after installing the expo-share-intent library.
```bash
expo prebuild --no-install --clean
expo run:ios
expo run:android
```
--------------------------------
### Local Development Build Commands
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/plugin-reference.md
Use these commands for local development to generate native files and run your application on simulators or devices. The '--no-install' flag prevents automatic dependency installation.
```bash
# Generate native files
expo prebuild --no-install
# Build and run
expo run:ios
expo run:android
```
--------------------------------
### Complete Usage Example for Expo Share Intent
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/module-exports.md
Demonstrates three ways to use expo-share-intent: direct hook usage with options, context-based approach using ShareIntentProvider, and manual deep link handling by retrieving scheme and extension key.
```typescript
import React, { useEffect } from "react";
import { View, Text, Button } from "react-native";
import {
useShareIntent,
ShareIntentProvider,
useShareIntentContext,
getScheme,
getShareExtensionKey,
type ShareIntent,
type ShareIntentFile,
} from "expo-share-intent";
// Option 1: Direct hook usage
function DirectHookApp() {
const { hasShareIntent, shareIntent, resetShareIntent, error } =
useShareIntent({
debug: true,
resetOnBackground: true,
});
return (
{error && {error}}
{hasShareIntent && (
<>
{shareIntent.text}
>
)}
);
}
// Option 2: Context-based approach
function ContextConsumer() {
const { shareIntent, hasShareIntent } = useShareIntentContext();
return {hasShareIntent ? shareIntent.text : "No content"};
}
function ContextApp() {
return (
);
}
// Option 3: Manual deep link handling
function ManualApp() {
useEffect(() => {
const scheme = getScheme();
const key = getShareExtensionKey();
console.log(`App scheme: ${scheme}, Extension key: ${key}`);
}, []);
return Check console;
}
export default DirectHookApp;
```
--------------------------------
### Android MainActivity Attributes Example
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/configuration.md
Customize Android manifest attributes for MainActivity, such as launch mode. 'singleTask' is recommended for proper share intent handling.
```json
"androidMainActivityAttributes": { "android:launchMode": "singleTask" }
```
--------------------------------
### Android Multi-Intent Filters Example
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/configuration.md
Configure MIME types for handling multiple file sharing intents on Android. Set to an empty array to disable.
```json
"androidMultiIntentFilters": ["image/*", "video/*"]
```
--------------------------------
### ShareIntentProvider with Async Storage Persistence
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/api-reference-ShareIntentProvider.md
This example demonstrates how to persist shared content using AsyncStorage. A ContentProcessor component saves the shared content and then resets the intent, ensuring data is not lost.
```typescript
import AsyncStorage from "@react-native-async-storage/async-storage";
import { useShareIntentContext } from "expo-share-intent";
import { useEffect } from "react";
function ContentProcessor() {
const { hasShareIntent, shareIntent, resetShareIntent } =
useShareIntentContext();
useEffect(() => {
if (hasShareIntent) {
saveContent();
}
}, [hasShareIntent, shareIntent]);
const saveContent = async () => {
try {
await AsyncStorage.setItem(
"lastSharedContent",
JSON.stringify(shareIntent)
);
resetShareIntent();
} catch (error) {
console.error("Failed to save content:", error);
}
};
return null; // Component handles side effects
}
export default function App() {
return (
);
}
```
--------------------------------
### Configure Content Types in app.json
Source: https://github.com/achorein/expo-share-intent/blob/main/README.md
Customize the types of content your app can share or receive by specifying them in the app.json configuration. This example shows how to enable text, image, and video sharing for Android and specific activation rules for iOS.
```json
"plugins": [
[
"expo-share-intent",
{
"iosActivationRules": {
"NSExtensionActivationSupportsWebURLWithMaxCount": 1,
"NSExtensionActivationSupportsWebPageWithMaxCount": 1,
"NSExtensionActivationSupportsImageWithMaxCount": 1,
"NSExtensionActivationSupportsMovieWithMaxCount": 1,
},
"androidIntentFilters": ["text/*", "image/*"]
}
],
],
```
--------------------------------
### Share Intent Meta Example
Source: https://github.com/achorein/expo-share-intent/blob/main/README.md
The 'meta' object contains additional metadata about the share intent, such as the title or other webpage metadata.
```json
{ title: "My cool blog article", "og:image": "https://.../image.png" }
```
--------------------------------
### iOS Share Extension Name Example
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/configuration.md
Set a custom display name for the share extension target. This name appears in the device share menu.
```json
"iosShareExtensionName": "ExpoShareIntent Example Extension"
```
--------------------------------
### getShareExtensionKey Function Export
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/module-exports.md
Exports the `getShareExtensionKey` utility function for generating the share extension storage key. Usage example provided.
```typescript
export { getShareExtensionKey } from "./utils";
// Usage
const key = getShareExtensionKey(options);
```
--------------------------------
### Share Intent Meta Webpage Metadata Example
Source: https://github.com/achorein/expo-share-intent/blob/main/README.md
The 'meta.xxx' property lists all webpage metadata available in meta tags. This is applicable on iOS when 'NSExtensionActivationSupportsWebPageWithMaxCount' is enabled.
```string
```
--------------------------------
### Android Intent Filters Example
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/configuration.md
Define the MIME types that trigger the share intent for single-file sharing on Android. Includes text, images, and video by default.
```json
"androidIntentFilters": ["text/*", "image/*", "video/*"]
```
--------------------------------
### Share Intent Files Example
Source: https://github.com/achorein/expo-share-intent/blob/main/README.md
The 'files' attribute is an array containing details about shared files, including images, videos, audio, or other file types. Each file object includes its path, mime type, filename, size, and optionally dimensions or duration.
```json
[{ path: "file:///local/path/filename", mimeType: "image/jpeg", fileName: "originalFilename.jpg", size: 2567402, width: 800, height: 600 }, { path: "file:///local/path/filename", mimeType: "video/mp4", fileName: "originalFilename.mp4", size: 2567402, width: 800, height: 600, duration: 20000 }]
```
--------------------------------
### Full App Integration with ShareIntentProvider
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/api-reference-ShareIntentProvider.md
This snippet shows a complete React Native application setup using ShareIntentProvider and React Navigation. It demonstrates how to wrap the navigation container with ShareIntentProvider and how to use the useShareIntentContext hook to display shared content.
```typescript
import React from "react";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { ShareIntentProvider, useShareIntentContext } from "expo-share-intent";
import { View, Text, Button } from "react-native";
const Stack = createNativeStackNavigator();
function ShareIntentHandler() {
const { hasShareIntent, shareIntent, resetShareIntent } =
useShareIntentContext();
if (!hasShareIntent) return null;
return (
Shared: {shareIntent.text || shareIntent.webUrl}
);
}
function HomeScreen() {
return (
Home Screen
);
}
function App() {
return (
);
}
export default App;
```
--------------------------------
### Example Android Intent Filters for Sharing
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/plugin-reference.md
This XML snippet illustrates the structure of intent filters added to the AndroidManifest for handling single and multiple file sharing, specifying MIME types.
```xml
```
--------------------------------
### Handle Deep Links with Expo Router
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/api-reference-utils.md
Example of how to use getShareExtensionKey within Expo Router to identify and redirect deep links containing share extension data.
```typescript
// app/+native-intent.ts
import { getShareExtensionKey } from "expo-share-intent";
export function redirectSystemPath({ path, initial }: {
path: string;
initial: string;
}) {
const key = getShareExtensionKey();
if (path.includes(`dataUrl=${key}`)) {
return "/share-handler";
}
return path;
}
```
--------------------------------
### Safe Module Method Calls
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/api-reference-ExpoShareIntentModule.md
Illustrates the importance of null-checking the ExpoShareIntentModule before invoking its methods to prevent runtime errors. Provides examples of both unsafe and safe calling patterns.
```typescript
// ❌ Unsafe
ExpoShareIntentModule.getShareIntent(url);
// ✅ Safe
ExpoShareIntentModule?.getShareIntent(url);
// ✅ Safe with fallback
if (ExpoShareIntentModule) {
ExpoShareIntentModule.getShareIntent(url);
} else {
console.warn("Share intent module not available");
}
```
--------------------------------
### ExpoShareIntentModule Native Methods
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/README.md
Interact with the native module to get share data, clear stored data, check for existing data, or listen for changes. Use the key to reference specific stored data.
```typescript
// Get share data (triggers onChange event)
ExpoShareIntentModule?.getShareIntent(url);
// Clear stored share data
await ExpoShareIntentModule?.clearShareIntent(key);
// Check if data exists
ExpoShareIntentModule?.hasShareIntent(key);
```
```typescript
// Listen for events
ExpoShareIntentModule?.addListener("onChange", (event) => { ... });
ExpoShareIntentModule?.addListener("onError", (event) => { ... });
```
--------------------------------
### Utility Functions for Share Intent
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/README.md
Utilize utility functions to get the app scheme, determine the storage key for share data, or manually parse native share data. These functions accept options for configuration.
```typescript
// Get the app scheme
const scheme = getScheme(options);
// Get the storage key
const key = getShareExtensionKey(options);
// Parse native share data manually
const shareIntent = parseShareIntent(nativeData, options);
```
--------------------------------
### Configure React Navigation Linking for Share Intents
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/api-reference-useShareIntent.md
Configure the linking configuration for React Navigation to handle deep links associated with share intents. This setup uses `ShareIntentProvider` and maps a wildcard path for share data URLs.
```typescript
const linking = {
prefixes: ["my-app://"],
config: {
screens: {
ShareIntent: "dataUrl=*",
```
--------------------------------
### Perform Full Project Build
Source: https://github.com/achorein/expo-share-intent/blob/main/CONTRIBUTING.md
Execute this command to perform a full build of the project. It also copies Swift files for the plugin.
```sh
yarn prepare
```
--------------------------------
### Enable Debug Mode
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/00-START-HERE.txt
Enable debug mode for the useShareIntent hook to get more detailed logs.
```typescript
useShareIntent({ debug: true })
```
--------------------------------
### Share Intent Web URL Example
Source: https://github.com/achorein/expo-share-intent/blob/main/README.md
The 'webUrl' attribute extracts a URL from the raw shared text.
```string
null
```
```string
"http://example.com"
```
```string
"http://example.com/nickname"
```
--------------------------------
### hasShareIntent
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/api-reference-ExpoShareIntentModule.md
Checks if share intent data is available without retrieving it. This allows for conditional logic before attempting to get the data.
```APIDOC
## hasShareIntent
### Description
Check if share intent data is available without retrieving it. This allows for conditional logic before attempting to get the data.
### Signature
```typescript
hasShareIntent(key: string): boolean
```
### Parameters
#### Path Parameters
- **key** (string) - Required - The share extension key to check
### Return Value
- **boolean** - `true` if share data exists, `false` otherwise
### Platform-Specific Behavior
**iOS**:
- Checks if a value exists in shared `UserDefaults` under the key
- Returns synchronously (no async)
- Returns `false` if the key doesn't exist or container is not accessible
**Android**:
- Checks if the launching intent has SEND or SEND_MULTIPLE action
- Returns synchronously
- Checks the intent extras for content URIs, text, or MIME type
### Usage
```typescript
import { ExpoShareIntentModule, getShareExtensionKey } from "expo-share-intent";
const key = getShareExtensionKey();
if (ExpoShareIntentModule?.hasShareIntent(key)) {
console.log("Share data is available");
ExpoShareIntentModule?.getShareIntent("");
}
```
```
--------------------------------
### parseShareIntent Function Export
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/module-exports.md
Exports the `parseShareIntent` utility function for parsing and normalizing platform-specific share data. Usage example provided.
```typescript
export { parseShareIntent } from "./utils";
// Usage
const normalized = parseShareIntent(nativeData, options);
```
--------------------------------
### Recommended App Structure with ShareIntentProvider
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/api-reference-ShareIntentProvider.md
Illustrates the optimal placement of ShareIntentProvider within the component tree, emphasizing its position near the root and before other providers like NavigationContainer and ThemeProvider.
```typescript
export default function App() {
return (
);
}
```
--------------------------------
### Share Intent Text Example
Source: https://github.com/achorein/expo-share-intent/blob/main/README.md
The 'text' attribute contains raw text shared from text/weburl intents on iOS and text/* intents on Android.
```string
"some text"
```
```string
"http://example.com"
```
```string
"Hey, Click on my link : http://example.com/nickname"
```
--------------------------------
### ExpoShareIntentModule Type Definition
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/api-reference-ExpoShareIntentModule.md
Defines the TypeScript interface for the native module, including methods for getting and clearing share intents, and listening for events.
```typescript
declare class ExpoShareIntentModuleType extends NativeModule {
getShareIntent(url: string): string;
clearShareIntent(key: string): Promise;
hasShareIntent(key: string): boolean;
}
type ExpoShareIntentModuleEvents = {
onError: (event: ErrorEventPayload) => void;
onChange: (event: ChangeEventPayload) => void;
onStateChange: (event: StateEventPayload) => void;
};
```
--------------------------------
### Configure iOS Activation Rules
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/plugin-reference.md
Configures the activation rules for the iOS share extension. Use this to specify what types of content the extension can handle, such as text or web URLs.
```json
{
"plugins": [
[
"expo-share-intent",
{
"iosActivationRules": {
"NSExtensionActivationSupportsText": true,
"NSExtensionActivationSupportsWebURLWithMaxCount": 1
}
}
]
]
}
```
--------------------------------
### getScheme Function Export
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/module-exports.md
Exports the `getScheme` utility function for extracting or detecting the application's deep link scheme. Usage example provided.
```typescript
export { getScheme } from "./utils";
// Usage
const scheme = getScheme(options);
```
--------------------------------
### useShareIntent Hook Export
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/module-exports.md
Exports the `useShareIntent` React hook for consuming share intent data within your application components. Usage example provided.
```typescript
export { default as useShareIntent } from "./useShareIntent";
// Usage
const { hasShareIntent, shareIntent, resetShareIntent, error } = useShareIntent(options);
```
--------------------------------
### Configuration with Options in app.json
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/plugin-reference.md
Customize the plugin's behavior by providing an options object alongside the plugin name in app.json. This allows setting iOS activation rules and Android intent filters.
```json
{
"plugins": [
[
"expo-share-intent",
{
"iosActivationRules": { ... },
"androidIntentFilters": ["text/*", "image/*"]
}
]
]
}
```
--------------------------------
### Context for Multi-Screen Apps with ShareIntentProvider
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/README.md
Illustrates how to use `ShareIntentProvider` to make share intent data accessible across multiple screens in an application. This pattern is useful for larger apps where state needs to be shared globally.
```typescript
import { ShareIntentProvider, useShareIntentContext } from "expo-share-intent";
function HomeScreen() {
const { hasShareIntent } = useShareIntentContext();
return {hasShareIntent ? "Content received" : "Waiting..."};
}
export default function App() {
return (
);
}
```
--------------------------------
### Implementation of getShareExtensionKey
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/api-reference-utils.md
The internal implementation of the getShareExtensionKey function, showing how it constructs the key using the app's scheme.
```typescript
export const getShareExtensionKey = (options?: ShareIntentOptions) => {
const scheme = getScheme(options);
return `${scheme}ShareKey`;
};
```
--------------------------------
### Manual Plugin Integration in Code
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/plugin-reference.md
Integrate the plugin directly in your code by importing and calling the withShareMenu function with your configuration. This offers programmatic control over plugin application.
```typescript
import withShareMenu from "expo-share-intent/plugin";
export default withShareMenu(config, {
iosActivationRules: { ... },
androidIntentFilters: ["text/*"],
});
```
--------------------------------
### Native Module Methods
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/INDEX.md
Direct methods for interacting with the native share intent module.
```APIDOC
## `getShareIntent` Method
### Description
Retrieves share intent data from the native module.
### Signature
`getShareIntent(url: string) => string`
### Parameters
- **url** (string) - The URL to process for share intent data.
### Returns
- A string representing the share intent data.
## `clearShareIntent` Method
### Description
Clears share intent data associated with a given key.
### Signature
`clearShareIntent(key: string) => Promise`
### Parameters
- **key** (string) - The key identifying the share intent data to clear.
### Returns
- A promise that resolves when the data is cleared.
## `hasShareIntent` Method
### Description
Checks if share intent data exists for a given key.
### Signature
`hasShareIntent(key: string) => boolean`
### Parameters
- **key** (string) - The key to check for.
### Returns
- `true` if share intent data exists, `false` otherwise.
## `addListener` Method
### Description
Adds an event listener for share intent events.
### Signature
`addListener(event: string, callback) => Subscription`
### Parameters
- **event** (string) - The name of the event to listen for.
- **callback** (function) - The function to call when the event is triggered.
### Returns
- A subscription object that can be used to remove the listener.
```
--------------------------------
### Troubleshoot Config Sync Failure
Source: https://github.com/achorein/expo-share-intent/blob/main/README.md
This command output indicates a configuration synchronization failure during the prebuild process, specifically related to iOS xcode project configuration. It suggests a missing post-install script.
```bash
$ yarn prebuild
⠧ Running prebuild[expo-share-intent] add ios share extension (scheme:exposhareintentexample appIdentifier:expo.modules.exposhareintent.example)
⠇ Running prebuild[expo-share-intent] add android filters text/* image/*
✖ Config sync failed
TypeError: [ios.xcodeproj]: withIosXcodeprojBaseMod: Cannot read properties of null (reading 'path')
```
--------------------------------
### Watch for Development Changes
Source: https://github.com/achorein/expo-share-intent/blob/main/CONTRIBUTING.md
Use these two commands in separate terminals to watch for changes during development. One builds the main project, the other builds the plugin.
```sh
yarn build:dev
```
```sh
yarn build:plugin:dev
```
--------------------------------
### Components
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/INDEX.md
Components for providing and managing share intent context.
```APIDOC
## `ShareIntentProvider` Component
### Description
Wraps your application to provide the share intent context.
### Props
- **options** (object) - Optional - Configuration options for the share intent.
- **children** (ReactNode) - The child components to be rendered within the provider.
```
--------------------------------
### Share Intent Meta Title Example
Source: https://github.com/achorein/expo-share-intent/blob/main/README.md
The 'meta.title' property provides an optional title sent by the originating app. It's available on Android and on iOS when 'NSExtensionActivationSupportsWebPageWithMaxCount' is enabled.
```string
"My cool blog article"
```
--------------------------------
### Expo Share Intent Plugin Entry Point
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/README.md
This is the main entry point for the expo-share-intent plugin. It is configured in the app.json file.
```typescript
// Entry point: plugin/src/index.ts
export default withShareMenu;
```
--------------------------------
### ShareIntentContextConsumer for Class Components
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/api-reference-ShareIntentProvider.md
Provides an example of using the deprecated ShareIntentContextConsumer for integrating with class components. This pattern is less preferred compared to the useShareIntentContext hook for functional components.
```jsx
import { ShareIntentContextConsumer } from "expo-share-intent";
{(context) => }
```
--------------------------------
### iOS App Group Identifier Example
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/configuration.md
Specify a custom application group identifier for shared container access between the main app and the share extension. This is crucial for data sharing.
```json
"iosAppGroupIdentifier": "group.com.example.myapp.shareintent"
```
--------------------------------
### Integrating useShareIntent Hook
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/api-reference-ExpoShareIntentModule.md
Shows how the useShareIntent hook internally utilizes the ExpoShareIntentModule for listening to changes, getting share intents via URL or direct calls, and clearing intents.
```typescript
// Hook initialization
const changeSubscription = ExpoShareIntentModule.addListener("onChange", (event) => {
setSharedIntent(parseShareIntent(event.value, options));
});
// On URL change (iOS deep link)
if (url?.includes(`${getScheme(options)}://dataUrl=`)) {
ExpoShareIntentModule?.getShareIntent(url);
}
// On Android intent
ExpoShareIntentModule?.getShareIntent("");
// On reset
ExpoShareIntentModule?.clearShareIntent(getShareExtensionKey(options));
```
--------------------------------
### Simple Hook Usage with useShareIntent
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/README.md
Demonstrates the basic usage of the `useShareIntent` hook to access shared content, clear it, and handle potential errors. This is suitable for simple applications where direct state management is sufficient.
```typescript
import { useShareIntent } from "expo-share-intent";
export default function App() {
const { hasShareIntent, shareIntent, resetShareIntent, error } =
useShareIntent();
return (
{error && {error}}
{hasShareIntent && {shareIntent.text}}
);
}
```
--------------------------------
### Project Structure Overview
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/INDEX.md
Provides a high-level view of the directory and file organization within the expo-share-intent library, including source code, plugins, and platform-specific configurations.
```tree
src/
├── index.ts ← Main exports
├── useShareIntent.ts ← Main hook (React)
├── ShareIntentProvider.tsx ← Context provider
├── utils.ts ← Helper functions
├── ExpoShareIntentModule.ts ← Native module interface
└── ExpoShareIntentModule.types.ts ← Type definitions
plugin/src/
├── index.ts ← Plugin entry point
├── types.ts ← Plugin parameter types
├── ios/
│ ├── constants.ts ← iOS helper constants
│ ├── withIosAppInfoPlist.ts ← Add app group to plist
│ ├── withIosAppEntitlements.ts ← Add entitlements
│ ├── withIosShareExtensionConfig.ts ← EAS config
│ ├── withIosShareExtensionXcodeTarget.ts ← Create target
│ └── writeIosShareExtensionFiles.ts ← Generate files
├── android/
│ ├── withAndroidIntentFilters.ts ← Add intent filters
│ └── withAndroidMainActivityAttributes.ts ← Set attributes
└── withCompatibilityChecker.ts ← Validation
```
--------------------------------
### ShareIntentModule Export
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/module-exports.md
Exports the default ShareIntentModule, providing a low-level interface to native module functions for getting and clearing share intents. This is useful for direct interaction with the native layer.
```typescript
export { default as ShareIntentModule } from "./ExpoShareIntentModule";
// Usage
ExpoShareIntentModule?.getShareIntent(url);
ExpoShareIntentModule?.clearShareIntent(key);
```
--------------------------------
### Data Flow Diagram
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/INDEX.md
Illustrates the step-by-step process of sharing content from a user action to the final rendering of shared data within the application.
```mermaid
graph TD
User shares content
↓
iOS Extension / Android Intent
↓
Data stored in shared container (iOS) / Captured from intent (Android)
↓
App launches with deep link (iOS) / App launched with intent (Android)
↓
expo-linking detects URL / App detects launch intent
↓
useShareIntent hook calls ExpoShareIntentModule.getShareIntent()
↓
Native module retrieves / extracts data
↓
Native module emits "onChange" event with JSON string
↓
Hook receives event, calls parseShareIntent()
↓
ShareIntent object normalized and state updated
↓
Component renders with shareIntent data available
```
--------------------------------
### ShareIntentProvider with Options
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/api-reference-ShareIntentProvider.md
Configure ShareIntentProvider with options like debug mode, automatic reset on backgrounding, and a custom URL scheme. These options customize the behavior of the share intent handling.
```typescript
```
--------------------------------
### Image and Video Sharing Configuration
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/configuration.md
Configure app.json to enable sharing of images and videos. This involves setting iOS activation rules and Android intent filters for image and video MIME types.
```json
{
"scheme": "my-app",
"plugins": [
[
"expo-share-intent",
{
"iosActivationRules": {
"NSExtensionActivationSupportsImageWithMaxCount": 1,
"NSExtensionActivationSupportsMovieWithMaxCount": 1
},
"androidIntentFilters": ["image/*", "video/*"],
"androidMultiIntentFilters": ["image/*", "video/*"]
}
]
]
}
```
--------------------------------
### Configure patch-package for older versions
Source: https://github.com/achorein/expo-share-intent/blob/main/README.md
For versions up to 5.0, configure post-install scripts and add patch-package for auto-patching if using Expo 55 (v6.0+).
```json
{
"scripts": {
...
"postinstall": "patch-package"
},
}
```
```bash
yarn add patch-package
```
--------------------------------
### ShareIntentProvider with Navigation Stack
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/api-reference-ShareIntentProvider.md
Integrates ShareIntentProvider with React Navigation's stack navigator. This setup allows you to define screens that handle shared content within a navigation flow, with options for debugging.
```typescript
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { ShareIntentProvider } from "expo-share-intent";
const Stack = createNativeStackNavigator();
export default function App() {
return (
);
}
```
--------------------------------
### Loading ExpoShareIntentModule Optionally
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/api-reference-ExpoShareIntentModule.md
Demonstrates how to optionally load the native Expo Share Intent Module. Always check for the module's existence before calling its methods to ensure graceful degradation in environments like Expo Go.
```typescript
const ExpoShareIntentModule =
requireOptionalNativeModule(
"ExpoShareIntentModule"
);
```
--------------------------------
### Get Share Intent Data (iOS and Android)
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/api-reference-ExpoShareIntentModule.md
Retrieve share intent data. For iOS, provide the deep link URL. For Android, use an empty string as data is extracted from the intent.
```typescript
import { ExpoShareIntentModule } from "expo-share-intent";
// iOS: with deep link
ExpoShareIntentModule?.getShareIntent("my-app://dataUrl=my-appShareKey");
// Android: empty string (data comes from intent)
ExpoShareIntentModule?.getShareIntent("");
```
--------------------------------
### Basic Configuration for expo-share-intent
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/configuration.md
Use this basic configuration to enable the expo-share-intent plugin in your app.json.
```json
{
"plugins": [
"expo-share-intent"
]
}
```
--------------------------------
### Handling Share Intent in Deep Link
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/api-reference-ShareIntentProvider.md
This example shows how to use the useShareIntentContext hook within a component to react to shared content, specifically web URLs. It navigates to a WebView if a web URL is shared.
```typescript
import { useEffect } from "react";
import { useNavigation } from "@react-navigation/native";
import { useShareIntentContext } from "expo-share-intent";
function ShareScreen() {
const navigation = useNavigation();
const { hasShareIntent, shareIntent, resetShareIntent } =
useShareIntentContext();
useEffect(() => {
if (hasShareIntent && shareIntent.type === "weburl") {
// Auto-open web content
navigation.navigate("WebView", { url: shareIntent.webUrl });
}
}, [hasShareIntent, shareIntent]);
return (
);
}
```
--------------------------------
### Write iOS Share Extension Files (TypeScript)
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/plugin-reference.md
Generates all necessary files for an iOS share extension, including Info.plist, entitlements, xcprivacy, storyboard, Swift controller, and a JavaScript preprocessor.
```typescript
export async function writeShareExtensionFiles(
platformProjectRoot: string,
scheme: string,
appIdentifier: string,
parameters: Parameters,
appName: string,
) {
// Writes:
// 1. ShareExtension-Info.plist
// 2. ShareExtension.entitlements
// 3. PrivacyInfo.xcprivacy
// 4. MainInterface.storyboard
// 5. ShareViewController.swift
// 6. ShareExtensionPreprocessor.js
}
```
--------------------------------
### Expo Config Plugin Entry Point
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/plugin-reference.md
This TypeScript code defines the main entry point for the expo config plugin. It uses `createRunOncePlugin` to manage plugin execution and `withPlugins` to chain various iOS and Android specific configuration plugins.
```typescript
const withShareMenu: ConfigPlugin = createRunOncePlugin(
(config, params = {}) => {
return withPlugins(config, [
// iOS plugins (if !disableIOS)
() => withIosAppInfoPlist(config, params),
() => withAppEntitlements(config, params),
() => withShareExtensionConfig(config, params),
() => withShareExtensionXcodeTarget(config, params),
// Android plugins (if !disableAndroid)
() => withAndroidIntentFilters(config, params),
() => withAndroidMainActivityAttributes(config, params),
// Shared
() => withCompatibilityChecker(config, params),
]);
},
pkg.name,
pkg.version
);
```
--------------------------------
### Create Share Extension Xcode Target
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/plugin-reference.md
Creates the share extension Xcode target and associated files, including writing Swift files, storyboard, plist, and configuring build phases and settings. It also handles linking frameworks and adding the target to project dependencies.
```typescript
export const withShareExtensionXcodeTarget: ConfigPlugin = (
config,
parameters,
) => {
return withXcodeProject(config, async (config) => {
// 1. Write extension files (Swift, storyboard, plist, etc.)
await writeShareExtensionFiles(
platformProjectRoot,
scheme,
appIdentifier,
parameters,
config.name
);
// 2. Create PBXNativeTarget if not exists
// 3. Create PBXGroup for extension files
// 4. Create PBXSourcesBuildPhase (compile Swift files)
// 5. Create PBXFrameworksBuildPhase
// 6. Create PBXCopyFilesBuildPhase
// 7. Create build configurations
// 8. Link frameworks (Foundation, UIKit)
// 9. Create "Copy Bundle Resources" phase
// 10. Add to project's targetDependencies
return config;
});
};
```
--------------------------------
### All Content Types Sharing Configuration
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/configuration.md
Configure app.json to support sharing of all content types, including text, web URLs, images, videos, and files. This requires extensive configuration of iOS activation rules and Android intent filters.
```json
{
"scheme": "my-app",
"plugins": [
[
"expo-share-intent",
{
"iosActivationRules": {
"NSExtensionActivationSupportsText": true,
"NSExtensionActivationSupportsWebURLWithMaxCount": 1,
"NSExtensionActivationSupportsWebPageWithMaxCount": 1,
"NSExtensionActivationSupportsImageWithMaxCount": 1,
"NSExtensionActivationSupportsMovieWithMaxCount": 1,
"NSExtensionActivationSupportsFileWithMaxCount": 1
},
"androidIntentFilters": ["text/*", "image/*", "video/*", "*/*"],
"androidMultiIntentFilters": ["image/*", "video/*", "audio/*", "*/*"]
}
]
]
}
```
--------------------------------
### EAS Build Commands
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/plugin-reference.md
Commands for configuring and initiating builds using Expo Application Services (EAS). The plugin is automatically configured for EAS builds.
```bash
# Configure EAS
eas build:configure
# Build for iOS
eas build --platform ios
# Build for Android
eas build --platform android
```
--------------------------------
### Handling Share Intent Across Multiple Screens
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/api-reference-ShareIntentProvider.md
Demonstrates how to use ShareIntentProvider to manage shared content across different screens in your application. Components can access the shared data and trigger actions like resetting the intent.
```typescript
function HomeScreen() {
const { hasShareIntent } = useShareIntentContext();
return {hasShareIntent ? "Content received" : "Waiting..."};
}
function DetailsScreen() {
const { shareIntent, resetShareIntent } = useShareIntentContext();
return (
{shareIntent.text}
);
}
export default function App() {
return (
);
}
```
--------------------------------
### ExpoShareIntentModule Interface
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/00-START-HERE.txt
The native module interface for low-level access to share intent functionality, including methods and events for direct native interaction.
```APIDOC
## ExpoShareIntentModule Interface
### Description
This document outlines the native module interface, providing direct access to the underlying native functionality for advanced use cases and debugging.
### Methods
- **`getInitialShareIntent()`**: Retrieves the share intent data that was active when the app was launched.
- **`clearShareIntent()`**: Clears the current share intent data from the native module.
### Events
- **`shareIntentReceived`**: Emitted when a new share intent is received by the application.
- **Payload**: Contains the raw share intent data.
```
--------------------------------
### Implementation of getScheme
Source: https://github.com/achorein/expo-share-intent/blob/main/_autodocs/api-reference-utils.md
The `getScheme` function implements the logic for extracting the app scheme by checking options, app.json, and deep link URLs. Debugging logs provide insights into the detection process.
```typescript
export const getScheme = (options?: ShareIntentOptions) => {
if (options?.scheme !== undefined) {
options?.debug &&
console.debug("expoShareIntent[scheme] from option:", options.scheme);
return options.scheme;
}
if (Constants.expoConfig?.scheme) {
let updatedScheme = Constants.expoConfig?.scheme;
if (Array.isArray(Constants.expoConfig?.scheme)) {
updatedScheme = updatedScheme[0];
options?.debug &&
console.debug(
`expoShareIntent[scheme] from expoConfig: multiple scheme detected (${Constants.expoConfig?.scheme.join(",")}), using:${updatedScheme}`,
);
} else {
options?.debug &&
console.debug(
"expoShareIntent[scheme] from expoConfig:",
updatedScheme,
);
}
return updatedScheme;
}
const deepLinkUrl = createURL("dataUrl=");
const extracted = deepLinkUrl.match(/^([^:]+)/gi)?.[0] || null;
options?.debug &&
console.debug(
"expoShareIntent[scheme] from linking url:",
deepLinkUrl,
extracted,
);
return extracted;
};
```