diff --git a/README.md b/README.md index 0bddc5d..1628aa3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # React Native WebView Javascript Bridge -This project is inspired by [WebViewJavascriptBridge](https://github.com/marcuswestin/WebViewJavascriptBridge). +I have been testing and reading a lot of way to safely create a bridge between react-native and webview. I'm happy to announced that the wait is over and from **React-Native 0.16 and above**, the bridge is fully functional. + -> In order for me to extend React-Native's WebView, I had to use `Category` feature objective-c, that would be the simplest and most elegant way by far. ## Installation @@ -9,115 +9,116 @@ In order to use this extension, you have to do the following steps: 1. in your react-native project, run `npm install react-native-webview-bridge` 2. go to xcode's `Project Navigator` tab +

+ +

3. right click on `Libraries` 4. select `Add Files to ...` option -5. navigate to `node_modules/react-native-webview-bridge` and add `WebViewBridge` folder -6. clean compile to make sure your project can compile and build. +

+ +

+5. navigate to `node_modules/react-native-webview-bridge/ios` and add `React-Native-Webview-Bridge.xcodeproj` folder +

+ +

+6. on project `Project Navigator` tab, click on your project's name and select Target's name and from there click on `Build Phases` +

+ +

+7. expand `Link Binary With Libraries` and click `+` sign to add a new one. +8. select `libReact-Native-Webviwe-Bridge.a` and click `Add` button. +

+ +

+9. clean compile to make sure your project can compile and build. ## Usage -There is a script which will be injected by this extension to the first page that you load. In order for your webpage to get access to the injected script, you have to use the following function. +just import the module with one of your choices way: + +** CommonJS style ** ```js -function WebViewBridgeReady(cb) { - //checks whether WebViewBirdge exists in global scope. - if (window.WebViewBridge) { - cb(window.WebViewBridge); - return; - } - - function handler() { - //remove the handler from listener since we don't need it anymore - document.removeEventListener('WebViewBridge', handler, false); - //pass the WebViewBridge object to the callback - cb(window.WebViewBridge); - } - - //if WebViewBridge doesn't exist in global scope attach itself to document - //event system. Once the code is being injected by extension, the handler will - //be called. - document.addEventListener('WebViewBridge', handler, false); -} -``` - -so now, anywhere in your script in webpage, you can call - -```js -WebViewBridgeReady(function (WebViewBridge) { - //at this time, you should be able to use the injected code here. -}); -``` - -`WebViewBridge` exposes 2 methods, `send` and `onMessage`; - -if you want to send a message to `React-Native` component, call the `send` method. - -if you want to receive message from `React-Native`, attach a function to `onMessage`. - -For Example: - -```js -WebViewBridgeReady(function (WebViewBridge) { - WebViewBridge.onMessage = function(message) { - console.log('got a message from react-native', message); - }; - - //sending a message to react-native - WebViewBridge.send("Hello this is me calling from web page"); -}); -``` - - -On React-Native side, you just have to load the `WebViewBridge` component. - -```js -var React = require('react-native'); var WebViewBridge = require('react-native-webview-bridge'); ``` -Since `WebViewBridge` is extending `WebView` component, it behaves exactly as WebView. -What it means that `WebViewBridge` has all the methods and props of `WebView` component. - -So here's an example of using `WebViewBridge`, +** ES6/ES2015 style ** ```js -var React = require('react-native'); -var WebViewBridge = require('react-native-webview-bridge'); +import WebViewBridge from 'react-native-webview-bridge'; +``` -var { - Component -} = React; +`WebViewBridge` is an extension of `WebView`. It injects special script into any pages once it loads. Also it extends the functionality of `WebView` by adding 1 new method and 1 new props. -var WEBVIEW_REF = 'my_webview'; +#### sendToBridge(message) +the message must be in string. because this is the only way to send data back and forth between native and webview. -class MyAwesomeView extends Component { - constructor(props) { - super(props); - } +#### onBridgeMessage +this is a prop that needs to be a function. it will be called once a message is received from webview. The type of received message is also in string. + + +## Bridge Script + +bridge script is a special script which injects into all the webview. It automatically register a global variable called `WebViewBridge`. It has 2 optional methods to implement and one method to send message to native side. + +#### send(message) + +this method sends a message to native side. the message must be in string type or `onError` method will be called. + +#### onMessage + +this method needs to be implemented. it will be called once a message arrives from native side. The type of message is in string. + +#### onError + +this is an error reporting method. It will be called if there is an error happens during sending a message. It receives a error message in string type. + +## Notes + +> a special bridge script will be injected once the page is going to different URL. So you don't have to manage when it needs to be injected. + +> You can still pass your own javascript to be injected into webview. However, Bridge script will be injected first and then your custom script. + + +## Simple Example +This example can be found in `examples` folder. + +```js +const injectScript = ` + (function () { + if (WebViewBridge) { + + WebViewBridge.onMessage = function (message) { + alert('got a message from Native: ' + message); + + WebViewBridge.send("message from webview"); + }; + + } + }()); +`; + +var Sample2 = React.createClass({ componentDidMount() { - var webviewRef = this.refs[WEBVIEW_REF]; - - webviewRef.onMessage(function (message) { - console.log("This message coming from web view", message); - webviewRef.send("Hello from react-native"); - }); - - webviewRef.injectBridgeScript(); - } - - render() { + setTimeout(() => { + this.refs.webviewbridge.sendToBridge("hahaha"); + }, 5000); + }, + onBridgeMessage: function (message) { + console.log(message); + }, + render: function() { return ( + ref="webviewbridge" + onBridgeMessage={this.onBridgeMessage} + injectedJavaScript={injectScript} + onBridgeMessage={(message) => { + console.log(message); + }} + url={"http://google.com"}/> ); } -} - -Added feature - -- 0.3.4 - - added `print` feature [exampl ecode](https://github.com/alinz/react-native-webview-bridge/blob/v0.3.4/example/Sample1/index.ios.js#L53) +}); +``` diff --git a/doc/assets/01.png b/doc/assets/01.png new file mode 100644 index 0000000..465b57c Binary files /dev/null and b/doc/assets/01.png differ diff --git a/doc/assets/02.png b/doc/assets/02.png new file mode 100644 index 0000000..7b599c5 Binary files /dev/null and b/doc/assets/02.png differ diff --git a/doc/assets/03.png b/doc/assets/03.png new file mode 100644 index 0000000..cf9aa8f Binary files /dev/null and b/doc/assets/03.png differ diff --git a/doc/assets/04.png b/doc/assets/04.png new file mode 100644 index 0000000..9c89656 Binary files /dev/null and b/doc/assets/04.png differ diff --git a/doc/assets/05.png b/doc/assets/05.png new file mode 100644 index 0000000..05bf20d Binary files /dev/null and b/doc/assets/05.png differ diff --git a/example/Sample1/android/app/build.gradle b/example/Sample1/android/app/build.gradle deleted file mode 100644 index 3626665..0000000 --- a/example/Sample1/android/app/build.gradle +++ /dev/null @@ -1,29 +0,0 @@ -apply plugin: 'com.android.application' - -android { - compileSdkVersion 23 - buildToolsVersion "23.0.1" - - defaultConfig { - applicationId "com.sample1" - minSdkVersion 16 - targetSdkVersion 22 - versionCode 1 - versionName "1.0" - ndk { - abiFilters "armeabi-v7a", "x86" - } - } - buildTypes { - release { - minifyEnabled false // Set this to true to enable Proguard - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } -} - -dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:23.0.1' - compile 'com.facebook.react:react-native:0.13.+' -} diff --git a/example/Sample1/android/app/src/main/res/values/strings.xml b/example/Sample1/android/app/src/main/res/values/strings.xml deleted file mode 100644 index 0ce7021..0000000 --- a/example/Sample1/android/app/src/main/res/values/strings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - Sample1 - diff --git a/example/Sample1/android/settings.gradle b/example/Sample1/android/settings.gradle deleted file mode 100644 index 8200536..0000000 --- a/example/Sample1/android/settings.gradle +++ /dev/null @@ -1,3 +0,0 @@ -rootProject.name = 'Sample1' - -include ':app' diff --git a/example/Sample1/iOS/main.jsbundle b/example/Sample1/iOS/main.jsbundle deleted file mode 100644 index b702b30..0000000 --- a/example/Sample1/iOS/main.jsbundle +++ /dev/null @@ -1,8 +0,0 @@ -// Offline JS -// To re-generate the offline bundle, run this from the root of your project: -// -// $ react-native bundle --minify -// -// See http://facebook.github.io/react-native/docs/runningondevice.html for more details. - -throw new Error('Offline JS file is empty. See iOS/main.jsbundle for instructions'); diff --git a/example/Sample1/index.ios.js b/example/Sample1/index.ios.js deleted file mode 100644 index d94ddbc..0000000 --- a/example/Sample1/index.ios.js +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Sample React Native App - * https://github.com/facebook/react-native - */ -'use strict'; - -var React = require('react-native'); -var WebViewBridgeNative = require('react-native-webview-bridge'); - -var myPageScripts = function() { - function WebViewBridgeReady(cb) { - if (window.WebViewBridge) { - cb(window.WebViewBridge); - return; - } - function handler() { - document.removeEventListener('WebViewBridge', handler, false); - cb(window.WebViewBridge); - } - document.addEventListener('WebViewBridge', handler, false); - } - WebViewBridgeReady(function (WebViewBridge) { - WebViewBridge.send("Hello this is me calling from web page"); - }); -}; - -//convert function definition into string -myPageScripts = `(${myPageScripts.toString()}());`; - -var { - AppRegistry, - Component -} = React; - -class Sample1 extends Component { - constructor(props) { - super(props); - this.once = true; - } - - componentDidMount() { - var myWebViewBridgeRef = this.refs.myWebViewBridge; - - var onMessage = function(message) { - console.log("Received message", message); - }; - myWebViewBridgeRef.onMessage(onMessage); - - myWebViewBridgeRef.injectBridgeScript(); - - //this opens up the printer window dialoge - setTimeout(() => { - myWebViewBridgeRef.print(); - }, 5000); - } - - onNavigationStateChange(navState) { - var myWebViewBridgeRef = this.refs.myWebViewBridge; - if (this.once) { - this.once = false; - setTimeout(() => { - myWebViewBridgeRef.evalScript(myPageScripts); - }, 1000); - } - - console.log(navState.url); - } - - render() { - var url = 'http://google.com'; - - return ( - - ); - } -} - - -AppRegistry.registerComponent('Sample1', () => Sample1); diff --git a/example/Sample1/.flowconfig b/examples/Sample2/.flowconfig similarity index 52% rename from example/Sample1/.flowconfig rename to examples/Sample2/.flowconfig index 05cad20..8eadd33 100644 --- a/example/Sample1/.flowconfig +++ b/examples/Sample2/.flowconfig @@ -7,12 +7,24 @@ # Some modules have their own node_modules with overlap .*/node_modules/node-haste/.* -# Ignore react-tools where there are overlaps, but don't ignore anything that -# react-native relies on -.*/node_modules/react-tools/src/React.js -.*/node_modules/react-tools/src/renderers/shared/event/EventPropagators.js -.*/node_modules/react-tools/src/renderers/shared/event/eventPlugins/ResponderEventPlugin.js -.*/node_modules/react-tools/src/shared/vendor/core/ExecutionEnvironment.js +# Ugh +.*/node_modules/babel.* +.*/node_modules/babylon.* +.*/node_modules/invariant.* + +# Ignore react and fbjs where there are overlaps, but don't ignore +# anything that react-native relies on +.*/node_modules/fbjs-haste/.*/__tests__/.* +.*/node_modules/fbjs-haste/__forks__/Map.js +.*/node_modules/fbjs-haste/__forks__/Promise.js +.*/node_modules/fbjs-haste/__forks__/fetch.js +.*/node_modules/fbjs-haste/core/ExecutionEnvironment.js +.*/node_modules/fbjs-haste/core/isEmpty.js +.*/node_modules/fbjs-haste/crypto/crc32.js +.*/node_modules/fbjs-haste/stubs/ErrorUtils.js +.*/node_modules/react-haste/React.js +.*/node_modules/react-haste/renderers/dom/ReactDOM.js +.*/node_modules/react-haste/renderers/shared/event/eventPlugins/ResponderEventPlugin.js # Ignore commoner tests .*/node_modules/commoner/test/.* @@ -43,9 +55,9 @@ suppress_type=$FlowIssue suppress_type=$FlowFixMe suppress_type=$FixMe -suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(1[0-7]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) -suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(1[0-7]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)? #[0-9]+ +suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(1[0-8]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) +suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(1[0-8]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)? #[0-9]+ suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy [version] -0.17.0 +0.18.1 diff --git a/example/Sample1/.gitignore b/examples/Sample2/.gitignore similarity index 100% rename from example/Sample1/.gitignore rename to examples/Sample2/.gitignore diff --git a/example/Sample1/.watchmanconfig b/examples/Sample2/.watchmanconfig similarity index 100% rename from example/Sample1/.watchmanconfig rename to examples/Sample2/.watchmanconfig diff --git a/examples/Sample2/android/app/build.gradle b/examples/Sample2/android/app/build.gradle new file mode 100644 index 0000000..fd9c3be --- /dev/null +++ b/examples/Sample2/android/app/build.gradle @@ -0,0 +1,78 @@ +apply plugin: "com.android.application" + +/** + * The react.gradle file registers two tasks: bundleDebugJsAndAssets and bundleReleaseJsAndAssets. + * These basically call `react-native bundle` with the correct arguments during the Android build + * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the + * bundle directly from the development server. Below you can see all the possible configurations + * and their defaults. If you decide to add a configuration block, make sure to add it before the + * `apply from: "react.gradle"` line. + * + * project.ext.react = [ + * // the name of the generated asset file containing your JS bundle + * bundleAssetName: "index.android.bundle", + * + * // the entry file for bundle generation + * entryFile: "index.android.js", + * + * // whether to bundle JS and assets in debug mode + * bundleInDebug: false, + * + * // whether to bundle JS and assets in release mode + * bundleInRelease: true, + * + * // the root of your project, i.e. where "package.json" lives + * root: "../../", + * + * // where to put the JS bundle asset in debug mode + * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", + * + * // where to put the JS bundle asset in release mode + * jsBundleDirRelease: "$buildDir/intermediates/assets/release", + * + * // where to put drawable resources / React Native assets, e.g. the ones you use via + * // require('./image.png')), in debug mode + * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", + * + * // where to put drawable resources / React Native assets, e.g. the ones you use via + * // require('./image.png')), in release mode + * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", + * + * // by default the gradle tasks are skipped if none of the JS files or assets change; this means + * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to + * // date; if you have any other folders that you want to ignore for performance reasons (gradle + * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ + * // for example, you might want to remove it from here. + * inputExcludes: ["android/**", "ios/**"] + * ] + */ + +apply from: "react.gradle" + +android { + compileSdkVersion 23 + buildToolsVersion "23.0.1" + + defaultConfig { + applicationId "com.sample2" + minSdkVersion 16 + targetSdkVersion 22 + versionCode 1 + versionName "1.0" + ndk { + abiFilters "armeabi-v7a", "x86" + } + } + buildTypes { + release { + minifyEnabled false // Set this to true to enable Proguard + proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" + } + } +} + +dependencies { + compile fileTree(dir: "libs", include: ["*.jar"]) + compile "com.android.support:appcompat-v7:23.0.1" + compile "com.facebook.react:react-native:0.16.+" +} diff --git a/example/Sample1/android/app/proguard-rules.pro b/examples/Sample2/android/app/proguard-rules.pro similarity index 100% rename from example/Sample1/android/app/proguard-rules.pro rename to examples/Sample2/android/app/proguard-rules.pro diff --git a/examples/Sample2/android/app/react.gradle b/examples/Sample2/android/app/react.gradle new file mode 100644 index 0000000..1e08b00 --- /dev/null +++ b/examples/Sample2/android/app/react.gradle @@ -0,0 +1,87 @@ +import org.apache.tools.ant.taskdefs.condition.Os + +def config = project.hasProperty("react") ? project.react : []; + +def bundleAssetName = config.bundleAssetName ?: "index.android.bundle" +def entryFile = config.entryFile ?: "index.android.js" + +// because elvis operator +def elvisFile(thing) { + return thing ? file(thing) : null; +} + +def reactRoot = elvisFile(config.root) ?: file("../../") +def jsBundleDirDebug = elvisFile(config.jsBundleDirDebug) ?: + file("$buildDir/intermediates/assets/debug") +def jsBundleDirRelease = elvisFile(config.jsBundleDirRelease) ?: + file("$buildDir/intermediates/assets/release") +def resourcesDirDebug = elvisFile(config.resourcesDirDebug) ?: + file("$buildDir/intermediates/res/merged/debug") +def resourcesDirRelease = elvisFile(config.resourcesDirRelease) ?: + file("$buildDir/intermediates/res/merged/release") +def inputExcludes = config.inputExcludes ?: ["android/**", "ios/**"] + +def jsBundleFileDebug = file("$jsBundleDirDebug/$bundleAssetName") +def jsBundleFileRelease = file("$jsBundleDirRelease/$bundleAssetName") + +task bundleDebugJsAndAssets(type: Exec) { + // create dirs if they are not there (e.g. the "clean" task just ran) + doFirst { + jsBundleDirDebug.mkdirs() + resourcesDirDebug.mkdirs() + } + + // set up inputs and outputs so gradle can cache the result + inputs.files fileTree(dir: reactRoot, excludes: inputExcludes) + outputs.dir jsBundleDirDebug + outputs.dir resourcesDirDebug + + // set up the call to the react-native cli + workingDir reactRoot + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine "cmd", "/c", "react-native", "bundle", "--platform", "android", "--dev", "true", "--entry-file", + entryFile, "--bundle-output", jsBundleFileDebug, "--assets-dest", resourcesDirDebug + } else { + commandLine "react-native", "bundle", "--platform", "android", "--dev", "true", "--entry-file", + entryFile, "--bundle-output", jsBundleFileDebug, "--assets-dest", resourcesDirDebug + } + + enabled config.bundleInDebug ?: false +} + +task bundleReleaseJsAndAssets(type: Exec) { + // create dirs if they are not there (e.g. the "clean" task just ran) + doFirst { + jsBundleDirRelease.mkdirs() + resourcesDirRelease.mkdirs() + } + + // set up inputs and outputs so gradle can cache the result + inputs.files fileTree(dir: reactRoot, excludes: inputExcludes) + outputs.dir jsBundleDirRelease + outputs.dir resourcesDirRelease + + // set up the call to the react-native cli + workingDir reactRoot + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine "cmd","/c", "react-native", "bundle", "--platform", "android", "--dev", "false", "--entry-file", + entryFile, "--bundle-output", jsBundleFileRelease, "--assets-dest", resourcesDirRelease + } else { + commandLine "react-native", "bundle", "--platform", "android", "--dev", "false", "--entry-file", + entryFile, "--bundle-output", jsBundleFileRelease, "--assets-dest", resourcesDirRelease + } + + enabled config.bundleInRelease ?: true +} + +gradle.projectsEvaluated { + // hook bundleDebugJsAndAssets into the android build process + bundleDebugJsAndAssets.dependsOn mergeDebugResources + bundleDebugJsAndAssets.dependsOn mergeDebugAssets + processDebugResources.dependsOn bundleDebugJsAndAssets + + // hook bundleReleaseJsAndAssets into the android build process + bundleReleaseJsAndAssets.dependsOn mergeReleaseResources + bundleReleaseJsAndAssets.dependsOn mergeReleaseAssets + processReleaseResources.dependsOn bundleReleaseJsAndAssets +} diff --git a/example/Sample1/android/app/src/main/AndroidManifest.xml b/examples/Sample2/android/app/src/main/AndroidManifest.xml similarity index 82% rename from example/Sample1/android/app/src/main/AndroidManifest.xml rename to examples/Sample2/android/app/src/main/AndroidManifest.xml index 463011c..6c2b911 100644 --- a/example/Sample1/android/app/src/main/AndroidManifest.xml +++ b/examples/Sample2/android/app/src/main/AndroidManifest.xml @@ -1,5 +1,5 @@ + package="com.sample2"> @@ -10,7 +10,8 @@ android:theme="@style/AppTheme"> + android:label="@string/app_name" + android:configChanges="keyboard|keyboardHidden|orientation|screenSize"> diff --git a/example/Sample1/android/app/src/main/java/com/sample1/MainActivity.java b/examples/Sample2/android/app/src/main/java/com/sample2/MainActivity.java similarity index 95% rename from example/Sample1/android/app/src/main/java/com/sample1/MainActivity.java rename to examples/Sample2/android/app/src/main/java/com/sample2/MainActivity.java index f9027f6..37ac3e2 100644 --- a/example/Sample1/android/app/src/main/java/com/sample1/MainActivity.java +++ b/examples/Sample2/android/app/src/main/java/com/sample2/MainActivity.java @@ -1,4 +1,4 @@ -package com.sample1; +package com.sample2; import android.app.Activity; import android.os.Bundle; @@ -30,7 +30,7 @@ public class MainActivity extends Activity implements DefaultHardwareBackBtnHand .setInitialLifecycleState(LifecycleState.RESUMED) .build(); - mReactRootView.startReactApplication(mReactInstanceManager, "Sample1", null); + mReactRootView.startReactApplication(mReactInstanceManager, "Sample2", null); setContentView(mReactRootView); } @@ -72,7 +72,7 @@ public class MainActivity extends Activity implements DefaultHardwareBackBtnHand super.onResume(); if (mReactInstanceManager != null) { - mReactInstanceManager.onResume(this); + mReactInstanceManager.onResume(this, this); } } } diff --git a/example/Sample1/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/examples/Sample2/android/app/src/main/res/mipmap-hdpi/ic_launcher.png similarity index 100% rename from example/Sample1/android/app/src/main/res/mipmap-hdpi/ic_launcher.png rename to examples/Sample2/android/app/src/main/res/mipmap-hdpi/ic_launcher.png diff --git a/example/Sample1/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/examples/Sample2/android/app/src/main/res/mipmap-mdpi/ic_launcher.png similarity index 100% rename from example/Sample1/android/app/src/main/res/mipmap-mdpi/ic_launcher.png rename to examples/Sample2/android/app/src/main/res/mipmap-mdpi/ic_launcher.png diff --git a/example/Sample1/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/examples/Sample2/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png similarity index 100% rename from example/Sample1/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png rename to examples/Sample2/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png diff --git a/example/Sample1/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/examples/Sample2/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png similarity index 100% rename from example/Sample1/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png rename to examples/Sample2/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png diff --git a/examples/Sample2/android/app/src/main/res/values/strings.xml b/examples/Sample2/android/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..dc23cf5 --- /dev/null +++ b/examples/Sample2/android/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + Sample2 + diff --git a/example/Sample1/android/app/src/main/res/values/styles.xml b/examples/Sample2/android/app/src/main/res/values/styles.xml similarity index 100% rename from example/Sample1/android/app/src/main/res/values/styles.xml rename to examples/Sample2/android/app/src/main/res/values/styles.xml diff --git a/example/Sample1/android/build.gradle b/examples/Sample2/android/build.gradle similarity index 84% rename from example/Sample1/android/build.gradle rename to examples/Sample2/android/build.gradle index ccdfc4e..bdb0fcc 100644 --- a/example/Sample1/android/build.gradle +++ b/examples/Sample2/android/build.gradle @@ -16,5 +16,8 @@ allprojects { repositories { mavenLocal() jcenter() + jcenter { + url "http://dl.bintray.com/mkonicek/maven" + } } } diff --git a/example/Sample1/android/gradle.properties b/examples/Sample2/android/gradle.properties similarity index 100% rename from example/Sample1/android/gradle.properties rename to examples/Sample2/android/gradle.properties diff --git a/example/Sample1/android/gradle/wrapper/gradle-wrapper.jar b/examples/Sample2/android/gradle/wrapper/gradle-wrapper.jar similarity index 100% rename from example/Sample1/android/gradle/wrapper/gradle-wrapper.jar rename to examples/Sample2/android/gradle/wrapper/gradle-wrapper.jar diff --git a/example/Sample1/android/gradle/wrapper/gradle-wrapper.properties b/examples/Sample2/android/gradle/wrapper/gradle-wrapper.properties similarity index 100% rename from example/Sample1/android/gradle/wrapper/gradle-wrapper.properties rename to examples/Sample2/android/gradle/wrapper/gradle-wrapper.properties diff --git a/example/Sample1/android/gradlew b/examples/Sample2/android/gradlew similarity index 100% rename from example/Sample1/android/gradlew rename to examples/Sample2/android/gradlew diff --git a/example/Sample1/android/gradlew.bat b/examples/Sample2/android/gradlew.bat similarity index 100% rename from example/Sample1/android/gradlew.bat rename to examples/Sample2/android/gradlew.bat diff --git a/examples/Sample2/android/settings.gradle b/examples/Sample2/android/settings.gradle new file mode 100644 index 0000000..078872f --- /dev/null +++ b/examples/Sample2/android/settings.gradle @@ -0,0 +1,3 @@ +rootProject.name = 'Sample2' + +include ':app' diff --git a/example/Sample1/index.android.js b/examples/Sample2/index.android.js similarity index 91% rename from example/Sample1/index.android.js rename to examples/Sample2/index.android.js index cd21ea3..dd170e3 100644 --- a/example/Sample1/index.android.js +++ b/examples/Sample2/index.android.js @@ -12,7 +12,7 @@ var { View, } = React; -var Sample1 = React.createClass({ +var Sample2 = React.createClass({ render: function() { return ( @@ -49,4 +49,4 @@ var styles = StyleSheet.create({ }, }); -AppRegistry.registerComponent('Sample1', () => Sample1); +AppRegistry.registerComponent('Sample2', () => Sample2); diff --git a/examples/Sample2/index.ios.js b/examples/Sample2/index.ios.js new file mode 100644 index 0000000..860d2b7 --- /dev/null +++ b/examples/Sample2/index.ios.js @@ -0,0 +1,54 @@ +/** + * Sample React Native App + * https://github.com/facebook/react-native + */ +'use strict'; + +var React = require('react-native'); +var { + AppRegistry, + StyleSheet, + Text, + View, +} = React; + +var WebViewBridge = require('react-native-webview-bridge'); + +const injectScript = ` + (function () { + if (WebViewBridge) { + + WebViewBridge.onMessage = function (message) { + alert('got a message from Native: ' + message); + + WebViewBridge.send("message from webview"); + }; + + } + }()); +`; + +var Sample2 = React.createClass({ + componentDidMount() { + setTimeout(() => { + this.refs.webviewbridge.sendToBridge("hahaha"); + }, 5000); + }, + onBridgeMessage: function (message) { + console.log(message); + }, + render: function() { + return ( + { + console.log(message); + }} + url={"http://google.com"}/> + ); + } +}); + +AppRegistry.registerComponent('Sample2', () => Sample2); diff --git a/example/Sample1/iOS/Sample1.xcodeproj/project.pbxproj b/examples/Sample2/ios/Sample2.xcodeproj/project.pbxproj similarity index 87% rename from example/Sample1/iOS/Sample1.xcodeproj/project.pbxproj rename to examples/Sample2/ios/Sample2.xcodeproj/project.pbxproj index 131a880..051c047 100644 --- a/example/Sample1/iOS/Sample1.xcodeproj/project.pbxproj +++ b/examples/Sample2/ios/Sample2.xcodeproj/project.pbxproj @@ -7,13 +7,12 @@ objects = { /* Begin PBXBuildFile section */ - 008F07F31AC5B25A0029DE68 /* main.jsbundle in Resources */ = {isa = PBXBuildFile; fileRef = 008F07F21AC5B25A0029DE68 /* main.jsbundle */; }; 00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302AC1ABCB8CE00DB3ED1 /* libRCTActionSheet.a */; }; 00C302E71ABCBA2D00DB3ED1 /* libRCTGeolocation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302BA1ABCB90400DB3ED1 /* libRCTGeolocation.a */; }; 00C302E81ABCBA2D00DB3ED1 /* libRCTImage.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302C01ABCB91800DB3ED1 /* libRCTImage.a */; }; 00C302E91ABCBA2D00DB3ED1 /* libRCTNetwork.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302DC1ABCB9D200DB3ED1 /* libRCTNetwork.a */; }; 00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302E41ABCB9EE00DB3ED1 /* libRCTVibration.a */; }; - 00E356F31AD99517003FC87E /* Sample1Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* Sample1Tests.m */; }; + 00E356F31AD99517003FC87E /* Sample2Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* Sample2Tests.m */; }; 133E29F31AD74F7200F7D852 /* libRCTLinking.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 78C398B91ACF4ADC00677621 /* libRCTLinking.a */; }; 139105C61AF99C1200B5F7CC /* libRCTSettings.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 139105C11AF99BAD00B5F7CC /* libRCTSettings.a */; }; 139FDEF61B0652A700C62182 /* libRCTWebSocket.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 139FDEF41B06529B00C62182 /* libRCTWebSocket.a */; }; @@ -22,7 +21,7 @@ 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; 146834051AC3E58100842450 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; }; - 415EA5581BEB154F000C8125 /* libReact-Native-WebView-Bridge.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 415EA5561BEB1546000C8125 /* libReact-Native-WebView-Bridge.a */; }; + 4115A2051C189D3C0020D542 /* libReact-Native-Webview-Bridge.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4115A2041C189C290020D542 /* libReact-Native-Webview-Bridge.a */; }; 832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; }; /* End PBXBuildFile section */ @@ -67,7 +66,7 @@ containerPortal = 83CBB9F71A601CBA00E9B192 /* Project object */; proxyType = 1; remoteGlobalIDString = 13B07F861A680F5B00A75B9A; - remoteInfo = Sample1; + remoteInfo = Sample2; }; 139105C01AF99BAD00B5F7CC /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; @@ -90,12 +89,12 @@ remoteGlobalIDString = 83CBBA2E1A601D0E00E9B192; remoteInfo = React; }; - 415EA5551BEB1546000C8125 /* PBXContainerItemProxy */ = { + 4115A2031C189C290020D542 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; - containerPortal = 415EA5481BEB1546000C8125 /* React-Native-WebView-Bridge.xcodeproj */; + containerPortal = 4115A1FF1C189C290020D542 /* React-Native-Webview-Bridge.xcodeproj */; proxyType = 2; - remoteGlobalIDString = 415125421BEB04C40042928F; - remoteInfo = "React-Native-WebView-Bridge"; + remoteGlobalIDString = 4114DC4C1C187C3A003CD988; + remoteInfo = "React-Native-Webview-Bridge"; }; 78C398B81ACF4ADC00677621 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; @@ -120,20 +119,20 @@ 00C302BB1ABCB91800DB3ED1 /* RCTImage.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTImage.xcodeproj; path = "../node_modules/react-native/Libraries/Image/RCTImage.xcodeproj"; sourceTree = ""; }; 00C302D31ABCB9D200DB3ED1 /* RCTNetwork.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTNetwork.xcodeproj; path = "../node_modules/react-native/Libraries/Network/RCTNetwork.xcodeproj"; sourceTree = ""; }; 00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTVibration.xcodeproj; path = "../node_modules/react-native/Libraries/Vibration/RCTVibration.xcodeproj"; sourceTree = ""; }; - 00E356EE1AD99517003FC87E /* Sample1Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Sample1Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 00E356EE1AD99517003FC87E /* Sample2Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Sample2Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 00E356F11AD99517003FC87E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 00E356F21AD99517003FC87E /* Sample1Tests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Sample1Tests.m; sourceTree = ""; }; + 00E356F21AD99517003FC87E /* Sample2Tests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Sample2Tests.m; sourceTree = ""; }; 139105B61AF99BAD00B5F7CC /* RCTSettings.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTSettings.xcodeproj; path = "../node_modules/react-native/Libraries/Settings/RCTSettings.xcodeproj"; sourceTree = ""; }; 139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTWebSocket.xcodeproj; path = "../node_modules/react-native/Libraries/WebSocket/RCTWebSocket.xcodeproj"; sourceTree = ""; }; - 13B07F961A680F5B00A75B9A /* Sample1.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Sample1.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = Sample1/AppDelegate.h; sourceTree = ""; }; - 13B07FB01A68108700A75B9A /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AppDelegate.m; path = Sample1/AppDelegate.m; sourceTree = ""; }; + 13B07F961A680F5B00A75B9A /* Sample2.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Sample2.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = Sample2/AppDelegate.h; sourceTree = ""; }; + 13B07FB01A68108700A75B9A /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AppDelegate.m; path = Sample2/AppDelegate.m; sourceTree = ""; }; 13B07FB21A68108700A75B9A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; - 13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = Sample1/Images.xcassets; sourceTree = ""; }; - 13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = Sample1/Info.plist; sourceTree = ""; }; - 13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = Sample1/main.m; sourceTree = ""; }; + 13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = Sample2/Images.xcassets; sourceTree = ""; }; + 13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = Sample2/Info.plist; sourceTree = ""; }; + 13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = Sample2/main.m; sourceTree = ""; }; 146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "../node_modules/react-native/React/React.xcodeproj"; sourceTree = ""; }; - 415EA5481BEB1546000C8125 /* React-Native-WebView-Bridge.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = "React-Native-WebView-Bridge.xcodeproj"; path = "../node_modules/react-native-webview-bridge/lib/ios/React-Native-WebView-Bridge.xcodeproj"; sourceTree = ""; }; + 4115A1FF1C189C290020D542 /* React-Native-Webview-Bridge.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = "React-Native-Webview-Bridge.xcodeproj"; path = "../node_modules/react-native-webview-bridge/ios/React-Native-Webview-Bridge.xcodeproj"; sourceTree = ""; }; 78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = ""; }; 832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -150,7 +149,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 415EA5581BEB154F000C8125 /* libReact-Native-WebView-Bridge.a in Frameworks */, + 4115A2051C189D3C0020D542 /* libReact-Native-Webview-Bridge.a in Frameworks */, 146834051AC3E58100842450 /* libReact.a in Frameworks */, 00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */, 00C302E71ABCBA2D00DB3ED1 /* libRCTGeolocation.a in Frameworks */, @@ -207,13 +206,13 @@ name = Products; sourceTree = ""; }; - 00E356EF1AD99517003FC87E /* Sample1Tests */ = { + 00E356EF1AD99517003FC87E /* Sample2Tests */ = { isa = PBXGroup; children = ( - 00E356F21AD99517003FC87E /* Sample1Tests.m */, + 00E356F21AD99517003FC87E /* Sample2Tests.m */, 00E356F01AD99517003FC87E /* Supporting Files */, ); - path = Sample1Tests; + path = Sample2Tests; sourceTree = ""; }; 00E356F01AD99517003FC87E /* Supporting Files */ = { @@ -240,7 +239,7 @@ name = Products; sourceTree = ""; }; - 13B07FAE1A68108700A75B9A /* Sample1 */ = { + 13B07FAE1A68108700A75B9A /* Sample2 */ = { isa = PBXGroup; children = ( 008F07F21AC5B25A0029DE68 /* main.jsbundle */, @@ -251,7 +250,7 @@ 13B07FB11A68108700A75B9A /* LaunchScreen.xib */, 13B07FB71A68108700A75B9A /* main.m */, ); - name = Sample1; + name = Sample2; sourceTree = ""; }; 146834001AC3E56700842450 /* Products */ = { @@ -262,10 +261,10 @@ name = Products; sourceTree = ""; }; - 415EA5491BEB1546000C8125 /* Products */ = { + 4115A2001C189C290020D542 /* Products */ = { isa = PBXGroup; children = ( - 415EA5561BEB1546000C8125 /* libReact-Native-WebView-Bridge.a */, + 4115A2041C189C290020D542 /* libReact-Native-Webview-Bridge.a */, ); name = Products; sourceTree = ""; @@ -281,7 +280,7 @@ 832341AE1AAA6A7D00B99B32 /* Libraries */ = { isa = PBXGroup; children = ( - 415EA5481BEB1546000C8125 /* React-Native-WebView-Bridge.xcodeproj */, + 4115A1FF1C189C290020D542 /* React-Native-Webview-Bridge.xcodeproj */, 146833FF1AC3E56700842450 /* React.xcodeproj */, 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */, 00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */, @@ -307,9 +306,9 @@ 83CBB9F61A601CBA00E9B192 = { isa = PBXGroup; children = ( - 13B07FAE1A68108700A75B9A /* Sample1 */, + 13B07FAE1A68108700A75B9A /* Sample2 */, 832341AE1AAA6A7D00B99B32 /* Libraries */, - 00E356EF1AD99517003FC87E /* Sample1Tests */, + 00E356EF1AD99517003FC87E /* Sample2Tests */, 83CBBA001A601CBA00E9B192 /* Products */, ); indentWidth = 2; @@ -319,8 +318,8 @@ 83CBBA001A601CBA00E9B192 /* Products */ = { isa = PBXGroup; children = ( - 13B07F961A680F5B00A75B9A /* Sample1.app */, - 00E356EE1AD99517003FC87E /* Sample1Tests.xctest */, + 13B07F961A680F5B00A75B9A /* Sample2.app */, + 00E356EE1AD99517003FC87E /* Sample2Tests.xctest */, ); name = Products; sourceTree = ""; @@ -328,9 +327,9 @@ /* End PBXGroup section */ /* Begin PBXNativeTarget section */ - 00E356ED1AD99517003FC87E /* Sample1Tests */ = { + 00E356ED1AD99517003FC87E /* Sample2Tests */ = { isa = PBXNativeTarget; - buildConfigurationList = 00E357021AD99517003FC87E /* Build configuration list for PBXNativeTarget "Sample1Tests" */; + buildConfigurationList = 00E357021AD99517003FC87E /* Build configuration list for PBXNativeTarget "Sample2Tests" */; buildPhases = ( 00E356EA1AD99517003FC87E /* Sources */, 00E356EB1AD99517003FC87E /* Frameworks */, @@ -341,26 +340,27 @@ dependencies = ( 00E356F51AD99517003FC87E /* PBXTargetDependency */, ); - name = Sample1Tests; - productName = Sample1Tests; - productReference = 00E356EE1AD99517003FC87E /* Sample1Tests.xctest */; + name = Sample2Tests; + productName = Sample2Tests; + productReference = 00E356EE1AD99517003FC87E /* Sample2Tests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; - 13B07F861A680F5B00A75B9A /* Sample1 */ = { + 13B07F861A680F5B00A75B9A /* Sample2 */ = { isa = PBXNativeTarget; - buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "Sample1" */; + buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "Sample2" */; buildPhases = ( 13B07F871A680F5B00A75B9A /* Sources */, 13B07F8C1A680F5B00A75B9A /* Frameworks */, 13B07F8E1A680F5B00A75B9A /* Resources */, + 00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */, ); buildRules = ( ); dependencies = ( ); - name = Sample1; + name = Sample2; productName = "Hello World"; - productReference = 13B07F961A680F5B00A75B9A /* Sample1.app */; + productReference = 13B07F961A680F5B00A75B9A /* Sample2.app */; productType = "com.apple.product-type.application"; }; /* End PBXNativeTarget section */ @@ -378,7 +378,7 @@ }; }; }; - buildConfigurationList = 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "Sample1" */; + buildConfigurationList = 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "Sample2" */; compatibilityVersion = "Xcode 3.2"; developmentRegion = English; hasScannedForEncodings = 0; @@ -427,8 +427,8 @@ ProjectRef = 139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */; }, { - ProductGroup = 415EA5491BEB1546000C8125 /* Products */; - ProjectRef = 415EA5481BEB1546000C8125 /* React-Native-WebView-Bridge.xcodeproj */; + ProductGroup = 4115A2001C189C290020D542 /* Products */; + ProjectRef = 4115A1FF1C189C290020D542 /* React-Native-Webview-Bridge.xcodeproj */; }, { ProductGroup = 146834001AC3E56700842450 /* Products */; @@ -437,8 +437,8 @@ ); projectRoot = ""; targets = ( - 13B07F861A680F5B00A75B9A /* Sample1 */, - 00E356ED1AD99517003FC87E /* Sample1Tests */, + 13B07F861A680F5B00A75B9A /* Sample2 */, + 00E356ED1AD99517003FC87E /* Sample2Tests */, ); }; /* End PBXProject section */ @@ -500,11 +500,11 @@ remoteRef = 146834031AC3E56700842450 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - 415EA5561BEB1546000C8125 /* libReact-Native-WebView-Bridge.a */ = { + 4115A2041C189C290020D542 /* libReact-Native-Webview-Bridge.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; - path = "libReact-Native-WebView-Bridge.a"; - remoteRef = 415EA5551BEB1546000C8125 /* PBXContainerItemProxy */; + path = "libReact-Native-Webview-Bridge.a"; + remoteRef = 4115A2031C189C290020D542 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; 78C398B91ACF4ADC00677621 /* libRCTLinking.a */ = { @@ -535,7 +535,6 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 008F07F31AC5B25A0029DE68 /* main.jsbundle in Resources */, 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */, 13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */, ); @@ -543,12 +542,29 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Bundle React Native code and images"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "../node_modules/react-native/packager/react-native-xcode.sh"; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 00E356EA1AD99517003FC87E /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 00E356F31AD99517003FC87E /* Sample1Tests.m in Sources */, + 00E356F31AD99517003FC87E /* Sample2Tests.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -566,7 +582,7 @@ /* Begin PBXTargetDependency section */ 00E356F51AD99517003FC87E /* PBXTargetDependency */ = { isa = PBXTargetDependency; - target = 13B07F861A680F5B00A75B9A /* Sample1 */; + target = 13B07F861A680F5B00A75B9A /* Sample2 */; targetProxy = 00E356F41AD99517003FC87E /* PBXContainerItemProxy */; }; /* End PBXTargetDependency section */ @@ -578,7 +594,7 @@ 13B07FB21A68108700A75B9A /* Base */, ); name = LaunchScreen.xib; - path = Sample1; + path = Sample2; sourceTree = ""; }; /* End PBXVariantGroup section */ @@ -596,11 +612,11 @@ "DEBUG=1", "$(inherited)", ); - INFOPLIST_FILE = Sample1Tests/Info.plist; + INFOPLIST_FILE = Sample2Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.2; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; - TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Sample1.app/Sample1"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Sample2.app/Sample2"; }; name = Debug; }; @@ -613,11 +629,11 @@ "$(SDKROOT)/Developer/Library/Frameworks", "$(inherited)", ); - INFOPLIST_FILE = Sample1Tests/Info.plist; + INFOPLIST_FILE = Sample2Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.2; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; - TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Sample1.app/Sample1"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Sample2.app/Sample2"; }; name = Release; }; @@ -631,10 +647,10 @@ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, "$(SRCROOT)/../node_modules/react-native/React/**", ); - INFOPLIST_FILE = Sample1/Info.plist; + INFOPLIST_FILE = Sample2/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; OTHER_LDFLAGS = "-ObjC"; - PRODUCT_NAME = Sample1; + PRODUCT_NAME = Sample2; }; name = Debug; }; @@ -647,10 +663,10 @@ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, "$(SRCROOT)/../node_modules/react-native/React/**", ); - INFOPLIST_FILE = Sample1/Info.plist; + INFOPLIST_FILE = Sample2/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; OTHER_LDFLAGS = "-ObjC"; - PRODUCT_NAME = Sample1; + PRODUCT_NAME = Sample2; }; name = Release; }; @@ -743,7 +759,7 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ - 00E357021AD99517003FC87E /* Build configuration list for PBXNativeTarget "Sample1Tests" */ = { + 00E357021AD99517003FC87E /* Build configuration list for PBXNativeTarget "Sample2Tests" */ = { isa = XCConfigurationList; buildConfigurations = ( 00E356F61AD99517003FC87E /* Debug */, @@ -752,7 +768,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "Sample1" */ = { + 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "Sample2" */ = { isa = XCConfigurationList; buildConfigurations = ( 13B07F941A680F5B00A75B9A /* Debug */, @@ -761,7 +777,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "Sample1" */ = { + 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "Sample2" */ = { isa = XCConfigurationList; buildConfigurations = ( 83CBBA201A601CBA00E9B192 /* Debug */, diff --git a/example/Sample1/iOS/Sample1.xcodeproj/xcshareddata/xcschemes/Sample1.xcscheme b/examples/Sample2/ios/Sample2.xcodeproj/xcshareddata/xcschemes/Sample2.xcscheme similarity index 78% rename from example/Sample1/iOS/Sample1.xcodeproj/xcshareddata/xcschemes/Sample1.xcscheme rename to examples/Sample2/ios/Sample2.xcodeproj/xcshareddata/xcschemes/Sample2.xcscheme index 345f20c..2b0bc44 100644 --- a/example/Sample1/iOS/Sample1.xcodeproj/xcshareddata/xcschemes/Sample1.xcscheme +++ b/examples/Sample2/ios/Sample2.xcodeproj/xcshareddata/xcschemes/Sample2.xcscheme @@ -15,9 +15,9 @@ + BuildableName = "Sample2.app" + BlueprintName = "Sample2" + ReferencedContainer = "container:Sample2.xcodeproj"> + BuildableName = "Sample2Tests.xctest" + BlueprintName = "Sample2Tests" + ReferencedContainer = "container:Sample2.xcodeproj"> @@ -47,9 +47,9 @@ + BuildableName = "Sample2Tests.xctest" + BlueprintName = "Sample2Tests" + ReferencedContainer = "container:Sample2.xcodeproj"> @@ -57,9 +57,9 @@ + BuildableName = "Sample2.app" + BlueprintName = "Sample2" + ReferencedContainer = "container:Sample2.xcodeproj"> @@ -77,9 +77,9 @@ + BuildableName = "Sample2.app" + BlueprintName = "Sample2" + ReferencedContainer = "container:Sample2.xcodeproj"> @@ -96,9 +96,9 @@ + BuildableName = "Sample2.app" + BlueprintName = "Sample2" + ReferencedContainer = "container:Sample2.xcodeproj"> diff --git a/example/Sample1/iOS/Sample1/AppDelegate.h b/examples/Sample2/ios/Sample2/AppDelegate.h similarity index 100% rename from example/Sample1/iOS/Sample1/AppDelegate.h rename to examples/Sample2/ios/Sample2/AppDelegate.h diff --git a/example/Sample1/iOS/Sample1/AppDelegate.m b/examples/Sample2/ios/Sample2/AppDelegate.m similarity index 84% rename from example/Sample1/iOS/Sample1/AppDelegate.m rename to examples/Sample2/ios/Sample2/AppDelegate.m index 298c9db..a14d2bc 100644 --- a/example/Sample1/iOS/Sample1/AppDelegate.m +++ b/examples/Sample2/ios/Sample2/AppDelegate.m @@ -35,23 +35,19 @@ /** * OPTION 2 - * Load from pre-bundled file on disk. To re-generate the static bundle - * from the root of your project directory, run - * - * $ react-native bundle --minify - * - * see http://facebook.github.io/react-native/docs/runningondevice.html + * Load from pre-bundled file on disk. The static bundle is automatically + * generated by "Bundle React Native code and images" build step. */ // jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation - moduleName:@"Sample1" + moduleName:@"Sample2" initialProperties:nil launchOptions:launchOptions]; self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; - UIViewController *rootViewController = [[UIViewController alloc] init]; + UIViewController *rootViewController = [UIViewController new]; rootViewController.view = rootView; self.window.rootViewController = rootViewController; [self.window makeKeyAndVisible]; diff --git a/example/Sample1/iOS/Sample1/Base.lproj/LaunchScreen.xib b/examples/Sample2/ios/Sample2/Base.lproj/LaunchScreen.xib similarity index 98% rename from example/Sample1/iOS/Sample1/Base.lproj/LaunchScreen.xib rename to examples/Sample2/ios/Sample2/Base.lproj/LaunchScreen.xib index 1da109d..30d7e10 100644 --- a/example/Sample1/iOS/Sample1/Base.lproj/LaunchScreen.xib +++ b/examples/Sample2/ios/Sample2/Base.lproj/LaunchScreen.xib @@ -18,7 +18,7 @@ -