From b930e25a8ff4fc12e38102f22286605d1744a66d Mon Sep 17 00:00:00 2001
From: Tero Paananen <54746036+tero-paananen@users.noreply.github.com>
Date: Mon, 26 Oct 2020 15:01:40 +0200
Subject: [PATCH] feat(windows): JS-WebView messaging bridge & multiple
WebViews fixes (#1617)
* Manage to build webview using Visual Studio
* WebView in content of UserControl
* Destructor not needed
* Example app tested
* Add messagingEnabled prop
* WebViewBridge
* Message posting
* Store bridge as instance variable
* Use bridge if messagingEnabled
* Free event delegate
* PostMessage api uses string message
* script.notify() usage removed
* Debug log removed
* Bridge reference added
* Base for web allowed object implemented c++/winrt
* Bribge works
* "Microsoft.Windows.CppWinRT" version="2.0.200729.8"
* Update bridge implementation
* version changes
* Reference fix
* WebView prj builds
* yarn lock update
* Platfrom version update
* NuGet package reference updated
* Messaging test added into example app
* Typo fix
* try_as() to as() calls
* WebView.PostMessage() not supported anymore, use injectJavaScript
* Fix WebView.postMessage to work using injectJavascript
* Eval postMessage fix
* postMessage via injectJavascript
* Example fixed to handle postMessage call
---
example/App.tsx | 42 +-
example/examples/Messaging.tsx | 63 +
example/windows/WebViewWindows.sln | 39 +
.../WebViewWindows/WebViewWindows.vcxproj | 8 +-
.../windows/WebViewWindows/packages.config | 2 +-
package.json | 2 +-
src/WebView.windows.tsx | 15 +-
windows/ReactNativeWebView.sln | 21 +
.../ReactNativeWebView.vcxproj | 11 +-
windows/ReactNativeWebView/ReactWebView.cpp | 107 +-
windows/ReactNativeWebView/ReactWebView.h | 17 +-
windows/ReactNativeWebView/ReactWebView.idl | 3 +-
.../ReactWebViewManager.cpp | 117 +-
.../ReactNativeWebView/ReactWebViewManager.h | 1 -
windows/ReactNativeWebView/packages.config | 2 +-
.../PropertySheet.props | 16 +
windows/WebViewBridgeComponent/WebBridge.cpp | 19 +
windows/WebViewBridgeComponent/WebBridge.h | 24 +
windows/WebViewBridgeComponent/WebBridge.idl | 11 +
.../WebViewBridgeComponent.def | 3 +
.../WebViewBridgeComponent.vcxproj | 158 +
.../WebViewBridgeComponent.vcxproj.filters | 33 +
.../WebViewBridgeComponent/packages.config | 4 +
windows/WebViewBridgeComponent/pch.cpp | 1 +
windows/WebViewBridgeComponent/pch.h | 4 +
windows/WebViewBridgeComponent/readme.txt | 23 +
yarn.lock | 2634 +++++++++--------
27 files changed, 1942 insertions(+), 1438 deletions(-)
create mode 100644 example/examples/Messaging.tsx
create mode 100644 windows/WebViewBridgeComponent/PropertySheet.props
create mode 100644 windows/WebViewBridgeComponent/WebBridge.cpp
create mode 100644 windows/WebViewBridgeComponent/WebBridge.h
create mode 100644 windows/WebViewBridgeComponent/WebBridge.idl
create mode 100644 windows/WebViewBridgeComponent/WebViewBridgeComponent.def
create mode 100644 windows/WebViewBridgeComponent/WebViewBridgeComponent.vcxproj
create mode 100644 windows/WebViewBridgeComponent/WebViewBridgeComponent.vcxproj.filters
create mode 100644 windows/WebViewBridgeComponent/packages.config
create mode 100644 windows/WebViewBridgeComponent/pch.cpp
create mode 100644 windows/WebViewBridgeComponent/pch.h
create mode 100644 windows/WebViewBridgeComponent/readme.txt
diff --git a/example/App.tsx b/example/App.tsx
index 6322382..d269439 100644
--- a/example/App.tsx
+++ b/example/App.tsx
@@ -17,8 +17,17 @@ import Downloads from './examples/Downloads';
import Uploads from './examples/Uploads';
import Injection from './examples/Injection';
import LocalPageLoad from './examples/LocalPageLoad';
+import Messaging from './examples/Messaging';
const TESTS = {
+ Messaging: {
+ title: 'Messaging',
+ testId: 'messaging',
+ description: 'js-webview postMessage messaging test',
+ render() {
+ return ;
+ },
+ },
Alerts: {
title: 'Alerts',
testId: 'alerts',
@@ -78,7 +87,7 @@ const TESTS = {
};
type Props = {};
-type State = {restarting: boolean, currentTest: Object};
+type State = {restarting: boolean; currentTest: Object};
export default class App extends Component {
state = {
@@ -90,7 +99,7 @@ export default class App extends Component {
this.setState({restarting: true}, () => this.setState({restarting: false}));
};
- _changeTest = testName => {
+ _changeTest = (testName) => {
this.setState({currentTest: TESTS[testName]});
};
@@ -138,16 +147,25 @@ export default class App extends Component {
title="LocalPageLoad"
onPress={() => this._changeTest('PageLoad')}
/>
- {Platform.OS == "ios" &&