### Install Dependencies and Run on iOS Source: https://github.com/expensify/react-native-share-menu/blob/master/example/README.md Installs project dependencies using yarn, sets up iOS native dependencies with CocoaPods, and runs the application on an iOS simulator or device. Requires Node.js, Yarn, and Xcode. ```shell yarn install ``` ```shell cd ios/ && pod install ``` ```shell yarn react-native run-ios ``` -------------------------------- ### Install react-native-share-menu Source: https://github.com/expensify/react-native-share-menu/blob/master/README.md Installs the react-native-share-menu package using npm. This is the initial step to integrate the library into your React Native project. ```bash npm i --save react-native-share-menu ``` -------------------------------- ### Install Pods Source: https://github.com/expensify/react-native-share-menu/blob/master/IOS_INSTRUCTIONS.md Command to install or update CocoaPods dependencies after modifying the Podfile. ```shell pod install ``` -------------------------------- ### Add Share Extension Files Source: https://github.com/expensify/react-native-share-menu/blob/master/IOS_INSTRUCTIONS.md Instructions for adding the ShareViewController.swift file from the library to your Xcode Share Extension target. Ensures the correct file is linked and not copied. ```shell On the pop-up, select `node_modules/react-native-share-menu/ios/ShareViewController.swift`. Make sure `Copy items if needed` is NOT selected and that the selected target is your newly created Share Extension ``` -------------------------------- ### Register ShareMenuPackage in MainApplication.java Source: https://github.com/expensify/react-native-share-menu/blob/master/ANDROID_INSTRUCTIONS.md This snippet shows how to register the `ShareMenuPackage` within your `MainApplication.java` file. This is crucial for initializing the library with the React Native application context. ```java import com.meedan.ShareMenuPackage; // <--- import public class MainApplication extends Application implements ReactApplication { ...... @Override protected List getPackages() { return Arrays.asList( new MainReactPackage(), new ShareMenuPackage() // <------ add here ); } ...... } ``` -------------------------------- ### Update Podfile for Share Extension Source: https://github.com/expensify/react-native-share-menu/blob/master/IOS_INSTRUCTIONS.md Modifies the Podfile to include the react-native-share-menu pod within the Share Extension target and sets APPLICATION_EXTENSION_API_ONLY to 'NO' for all targets. ```diff target '' do config = use_native_modules! use_react_native!(:path => config["reactNativePath"]) target 'Tests' do inherit! :complete # Pods for testing end # Enables Flipper. # # Note that if you have use_frameworks! enabled, Flipper will not work and # you should disable these next few lines. use_flipper! post_install do |installer| flipper_post_install(installer) + installer.pods_project.targets.each do |target| + target.build_configurations.each do |config| + config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO' + end + end end end +target '' do + use_react_native! + + pod 'RNShareMenu', :path => '../node_modules/react-native-share-menu' + # Manually link packages here to keep your extension bundle size minimal +end ``` -------------------------------- ### App Info.plist Configuration Source: https://github.com/expensify/react-native-share-menu/blob/master/IOS_INSTRUCTIONS.md Adds the necessary URL scheme configuration to the main application's Info.plist file, allowing the app to be opened via custom URL schemes. ```openstep property list CFBundleURLTypes CFBundleTypeRole Editor CFBundleURLSchemes A_URL_SCHEME_UNIQUE_TO_YOUR_APP ``` -------------------------------- ### Run on Android Source: https://github.com/expensify/react-native-share-menu/blob/master/example/README.md Runs the application on an Android emulator or connected device. Ensure an Android development environment is set up. May require starting the Metro bundler separately. ```shell yarn react-native run-android ``` ```shell yarn start ``` -------------------------------- ### Share Extension Info.plist Configuration Source: https://github.com/expensify/react-native-share-menu/blob/master/IOS_INSTRUCTIONS.md Configures the Share Extension's Info.plist with the host app's bundle identifier and URL scheme, and defines activation rules for supported content types. ```openstep property list HostAppBundleIdentifier YOUR_APP_TARGET_BUNDLE_ID HostAppURLScheme YOUR_APP_URL_SCHEME_DEFINED_ABOVE NSExtension NSExtensionAttributes NSExtensionActivationRule NSExtensionActivationSupportsImageWithMaxCount 1 NSExtensionActivationSupportsText NSExtensionActivationSupportsWebURLWithMaxCount 1 NSExtensionMainStoryboard MainInterface NSExtensionPointIdentifier com.apple.share-services ``` -------------------------------- ### Automatic Linking (iOS) Source: https://github.com/expensify/react-native-share-menu/blob/master/README.md Installs native iOS dependencies using CocoaPods. This command should be executed within the 'ios' directory for React Native versions 0.60 and above. ```bash pod install ``` -------------------------------- ### AppDelegate.m Share Menu Integration Source: https://github.com/expensify/react-native-share-menu/blob/master/IOS_INSTRUCTIONS.md Integrates the ShareMenuManager into the AppDelegate.m file to handle incoming URLs from the Share Extension, ensuring proper communication between the extension and the main app. ```objective-c ... #import ... @implementation AppDelegate ... - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { return [ShareMenuManager application:app openURL:url options:options]; } @end ``` -------------------------------- ### Add Share Menu Dependency in app/build.gradle Source: https://github.com/expensify/react-native-share-menu/blob/master/ANDROID_INSTRUCTIONS.md This snippet demonstrates adding the compiled react-native-share-menu library as a project dependency in your `android/app/build.gradle` file. This step links the library to your application module. ```gradle dependencies { ... compile project(':react-native-share-menu') } ``` -------------------------------- ### Include Share Menu in Gradle settings.gradle Source: https://github.com/expensify/react-native-share-menu/blob/master/ANDROID_INSTRUCTIONS.md This snippet shows how to include the react-native-share-menu library project in your Android project's `settings.gradle` file. It ensures the library is recognized by the Gradle build system. ```gradle include ':react-native-share-menu', ':app' project(':react-native-share-menu').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-share-menu/android') ``` -------------------------------- ### Example Usage: Handling Shared Content Source: https://github.com/expensify/react-native-share-menu/blob/master/README.md Demonstrates how to use the ShareMenu API to receive shared data (text, images, files) from other applications. It includes listeners for initial shares and new shares, and logic to display different content types. ```javascript import React, { useState, useEffect, useCallback } from "react"; import { AppRegistry, Text, View, Image, Button } from "react-native"; import ShareMenu, { ShareMenuReactView } from "react-native-share-menu"; type SharedItem = { mimeType: string, data: string, extraData: any, }; const Test = () => { const [sharedData, setSharedData] = useState(null); const [sharedMimeType, setSharedMimeType] = useState(null); const handleShare = useCallback((item: ?SharedItem) => { if (!item) { return; } const { mimeType, data, extraData } = item; setSharedData(data); setSharedMimeType(mimeType); // You can receive extra data from your custom Share View console.log(extraData); }, []); useEffect(() => { ShareMenu.getInitialShare(handleShare); }, []); useEffect(() => { const listener = ShareMenu.addNewShareListener(handleShare); return () => { listener.remove(); }; }, []); if (!sharedMimeType && !sharedData) { // The user hasn't shared anything yet return null; } if (sharedMimeType === "text/plain") { // The user shared text return Shared text: {sharedData}; } if (sharedMimeType.startsWith("image/")) { // The user shared an image return ( Shared image: ); } // The user shared a file in general return ( Shared mime type: {sharedMimeType} Shared file location: {sharedData} ); }; const Share = () => { const [sharedData, setSharedData] = useState(""); const [sharedMimeType, setSharedMimeType] = useState(""); useEffect(() => { ShareMenuReactView.data().then(({ mimeType, data }) => { setSharedData(data); setSharedMimeType(mimeType); }); }, []); return (