From f5805e92082fd79f251cefbe86759201589f6e9a Mon Sep 17 00:00:00 2001 From: Gustavo Parreira Date: Sat, 1 Aug 2020 18:42:40 +0100 Subject: [PATCH] Separate JS bundle for Share Extension React View (#66) * Added instructions for running Share Extension custom view outside simulator * Separating share extension js bundle from maain app * Remove Share component registration from inddex.js --- SHARE_EXTENSION_VIEW.md | 5 ++++- example/index.js | 2 -- example/index.share.js | 8 ++++++++ example/ios/Podfile.lock | 4 ++-- example/ios/Test.xcodeproj/project.pbxproj | 2 +- ios/ReactShareViewController.swift | 2 +- 6 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 example/index.share.js diff --git a/SHARE_EXTENSION_VIEW.md b/SHARE_EXTENSION_VIEW.md index 8d2e04b..e6906fa 100644 --- a/SHARE_EXTENSION_VIEW.md +++ b/SHARE_EXTENSION_VIEW.md @@ -88,6 +88,7 @@ If you're planning to run builds outside the simulator, or to make Release build ```shell export NODE_BINARY=node +export ENTRY_FILE=index.share.js ../node_modules/react-native/scripts/react-native-xcode.sh ``` @@ -99,9 +100,11 @@ You should end up with something like this: ## Register Component -Finally, in your `index.js` file, register the component you want to render in your Share Extension view: +Finally, create an `index.share.js` file, register the component you want to render in your Share Extension view: ```javascript +import { AppRegistry } from "react-native"; + AppRegistry.registerComponent( "ShareMenuModuleComponent", () => MyShareComponent diff --git a/example/index.js b/example/index.js index 7b45860..a850d03 100644 --- a/example/index.js +++ b/example/index.js @@ -4,8 +4,6 @@ import {AppRegistry} from 'react-native'; import App from './App'; -import Share from './Share'; import {name as appName} from './app.json'; AppRegistry.registerComponent(appName, () => App); -AppRegistry.registerComponent('ShareMenuModuleComponent', () => Share); diff --git a/example/index.share.js b/example/index.share.js new file mode 100644 index 0000000..b1efcfc --- /dev/null +++ b/example/index.share.js @@ -0,0 +1,8 @@ +/** + * @format + */ + +import {AppRegistry} from 'react-native'; +import Share from './Share'; + +AppRegistry.registerComponent('ShareMenuModuleComponent', () => Share); diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 83f4fac..48c1091 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -296,7 +296,7 @@ PODS: - React-Core (= 0.63.2) - React-cxxreact (= 0.63.2) - React-jsi (= 0.63.2) - - RNShareMenu (4.1.3): + - RNShareMenu (4.1.4): - React - Yoga (1.14.0) - YogaKit (1.18.1): @@ -460,7 +460,7 @@ SPEC CHECKSUMS: React-RCTText: 1b6773e776e4b33f90468c20fe3b16ca3e224bb8 React-RCTVibration: 4d2e726957f4087449739b595f107c0d4b6c2d2d ReactCommon: a0a1edbebcac5e91338371b72ffc66aa822792ce - RNShareMenu: 916e2500637b7b6f02ac50b5cb4f3fb027efe98d + RNShareMenu: 43c83aa52d50a689b1f16b02f7815ea0406b1cc0 Yoga: 7740b94929bbacbddda59bf115b5317e9a161598 YogaKit: f782866e155069a2cca2517aafea43200b01fd5a diff --git a/example/ios/Test.xcodeproj/project.pbxproj b/example/ios/Test.xcodeproj/project.pbxproj index a266dd4..4af6534 100644 --- a/example/ios/Test.xcodeproj/project.pbxproj +++ b/example/ios/Test.xcodeproj/project.pbxproj @@ -763,7 +763,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "export NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh\n"; + shellScript = "export NODE_BINARY=node\nexport ENTRY_FILE=index.share.js\n../node_modules/react-native/scripts/react-native-xcode.sh\n"; }; DE1711632D695F6EF19AF198 /* [CP] Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; diff --git a/ios/ReactShareViewController.swift b/ios/ReactShareViewController.swift index a52f2c1..5dc846d 100644 --- a/ios/ReactShareViewController.swift +++ b/ios/ReactShareViewController.swift @@ -13,7 +13,7 @@ class ReactShareViewController: ShareViewController, RCTBridgeDelegate, ReactSha func sourceURL(for bridge: RCTBridge!) -> URL! { #if DEBUG return RCTBundleURLProvider.sharedSettings()? - .jsBundleURL(forBundleRoot: "index", fallbackResource: nil) + .jsBundleURL(forBundleRoot: "index.share", fallbackResource: nil) #else return Bundle.main.url(forResource: "main", withExtension: "jsbundle") #endif