Tero Paananen 4 lat temu
rodzic
commit
ab0f3a7c10
No account linked to committer's email address

+ 30
- 12
example/App.tsx Wyświetl plik

@@ -17,8 +17,17 @@ import Downloads from './examples/Downloads';
17 17
 import Uploads from './examples/Uploads';
18 18
 import Injection from './examples/Injection';
19 19
 import LocalPageLoad from './examples/LocalPageLoad';
20
+import Messaging from './examples/Messaging';
20 21
 
21 22
 const TESTS = {
23
+  Messaging: {
24
+    title: 'Messaging',
25
+    testId: 'messaging',
26
+    description: 'js-webview postMessage messaging test',
27
+    render() {
28
+      return <Messaging />;
29
+    },
30
+  },
22 31
   Alerts: {
23 32
     title: 'Alerts',
24 33
     testId: 'alerts',
@@ -78,7 +87,7 @@ const TESTS = {
78 87
 };
79 88
 
80 89
 type Props = {};
81
-type State = {restarting: boolean, currentTest: Object};
90
+type State = {restarting: boolean; currentTest: Object};
82 91
 
83 92
 export default class App extends Component<Props, State> {
84 93
   state = {
@@ -90,7 +99,7 @@ export default class App extends Component<Props, State> {
90 99
     this.setState({restarting: true}, () => this.setState({restarting: false}));
91 100
   };
92 101
 
93
-  _changeTest = testName => {
102
+  _changeTest = (testName) => {
94 103
     this.setState({currentTest: TESTS[testName]});
95 104
   };
96 105
 
@@ -138,16 +147,25 @@ export default class App extends Component<Props, State> {
138 147
             title="LocalPageLoad"
139 148
             onPress={() => this._changeTest('PageLoad')}
140 149
           />
141
-          {Platform.OS == "ios" && <Button
142
-            testID="testType_downloads"
143
-            title="Downloads"
144
-            onPress={() => this._changeTest('Downloads')}
145
-          />}
146
-          {Platform.OS === 'android' && <Button
147
-            testID="testType_uploads"
148
-            title="Uploads"
149
-            onPress={() => this._changeTest('Uploads')}
150
-          />}
150
+          {Platform.OS == 'ios' && (
151
+            <Button
152
+              testID="testType_downloads"
153
+              title="Downloads"
154
+              onPress={() => this._changeTest('Downloads')}
155
+            />
156
+          )}
157
+          {Platform.OS === 'android' && (
158
+            <Button
159
+              testID="testType_uploads"
160
+              title="Uploads"
161
+              onPress={() => this._changeTest('Uploads')}
162
+            />
163
+          )}
164
+          <Button
165
+            testID="testType_messaging"
166
+            title="Messaging"
167
+            onPress={() => this._changeTest('Messaging')}
168
+          />
151 169
         </View>
152 170
 
153 171
         {restarting ? null : (

+ 54
- 0
example/examples/Messaging.tsx Wyświetl plik

@@ -0,0 +1,54 @@
1
+import React, {Component} from 'react';
2
+import {Text, View, Alert} from 'react-native';
3
+
4
+import WebView from 'react-native-webview';
5
+
6
+const HTML = `
7
+<!DOCTYPE html>\n
8
+<html>
9
+  <head>
10
+    <title>Messaging</title>
11
+    <meta http-equiv="content-type" content="text/html; charset=utf-8">
12
+    <meta name="viewport" content="width=320, user-scalable=no">
13
+    <style type="text/css">
14
+      body {
15
+        margin: 0;
16
+        padding: 0;
17
+        font: 62.5% arial, sans-serif;
18
+        background: #ccc;
19
+      }
20
+    </style>
21
+  </head>
22
+  <body>
23
+    <button onclick="sendPostMessage()">Send post message from JS to WebView</button>
24
+    <p id="demo"></p>    
25
+    <script>
26
+      function sendPostMessage() {
27
+        window.ReactNativeWebView.postMessage('Message from javascript');
28
+      }
29
+    </script>
30
+  </body>
31
+</html>
32
+`;
33
+
34
+type Props = {};
35
+type State = {};
36
+
37
+export default class Alerts extends Component<Props, State> {
38
+  state = {};
39
+
40
+  render() {
41
+    return (
42
+      <View style={{height: 120}}>
43
+        <WebView
44
+          source={{html: HTML}}
45
+          automaticallyAdjustContentInsets={false}
46
+          onMessage={(e: {nativeEvent: {data?: string}}) => {
47
+            console.log('onMessage', e.nativeEvent.data);
48
+            Alert.alert('Message received', e.nativeEvent.data);
49
+          }}
50
+        />
51
+      </View>
52
+    );
53
+  }
54
+}

+ 39
- 0
example/windows/WebViewWindows.sln Wyświetl plik

@@ -42,9 +42,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Mso", "..\..\node_modules\r
42 42
 EndProject
43 43
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ReactNativeWebView", "..\..\windows\ReactNativeWebView\ReactNativeWebView.vcxproj", "{729D9AF8-CD9E-4427-9F6C-FB757E287729}"
44 44
 EndProject
45
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WebViewBridgeComponent", "..\..\windows\WebViewBridgeComponent\WebViewBridgeComponent.vcxproj", "{FCB612AD-FACC-410C-828C-24B5940B2762}"
46
+EndProject
45 47
 Global
46 48
 	GlobalSection(SharedMSBuildProjectFiles) = preSolution
47 49
 		..\..\node_modules\react-native-windows\JSI\Shared\JSI.Shared.vcxitems*{0cc28589-39e4-4288-b162-97b959f8b843}*SharedItemsImports = 9
50
+		..\..\node_modules\react-native-windows\ReactWindowsCore\ReactWindowsCore.vcxitems*{11c084a3-a57c-4296-a679-cac17b603144}*SharedItemsImports = 4
48 51
 		..\..\node_modules\react-native-windows\Shared\Shared.vcxitems*{2049dbe9-8d13-42c9-ae4b-413ae38fffd0}*SharedItemsImports = 9
49 52
 		..\..\node_modules\react-native-windows\Microsoft.ReactNative.SharedManaged\Microsoft.ReactNative.SharedManaged.projitems*{67a1076f-7790-4203-86ea-4402ccb5e782}*SharedItemsImports = 13
50 53
 		..\..\node_modules\react-native-windows\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.vcxitems*{729d9af8-cd9e-4427-9f6c-fb757e287729}*SharedItemsImports = 4
@@ -60,16 +63,19 @@ Global
60 63
 		..\..\node_modules\react-native-windows\Shared\Shared.vcxitems*{f7d32bd0-2749-483e-9a0d-1635ef7e3136}*SharedItemsImports = 4
61 64
 	EndGlobalSection
62 65
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
66
+		Debug|Any CPU = Debug|Any CPU
63 67
 		Debug|ARM = Debug|ARM
64 68
 		Debug|ARM64 = Debug|ARM64
65 69
 		Debug|x64 = Debug|x64
66 70
 		Debug|x86 = Debug|x86
71
+		Release|Any CPU = Release|Any CPU
67 72
 		Release|ARM = Release|ARM
68 73
 		Release|ARM64 = Release|ARM64
69 74
 		Release|x64 = Release|x64
70 75
 		Release|x86 = Release|x86
71 76
 	EndGlobalSection
72 77
 	GlobalSection(ProjectConfigurationPlatforms) = postSolution
78
+		{AC6C354F-8C80-47EA-9E40-996ABE271843}.Debug|Any CPU.ActiveCfg = Debug|Win32
73 79
 		{AC6C354F-8C80-47EA-9E40-996ABE271843}.Debug|ARM.ActiveCfg = Debug|ARM
74 80
 		{AC6C354F-8C80-47EA-9E40-996ABE271843}.Debug|ARM.Build.0 = Debug|ARM
75 81
 		{AC6C354F-8C80-47EA-9E40-996ABE271843}.Debug|ARM.Deploy.0 = Debug|ARM
@@ -82,6 +88,7 @@ Global
82 88
 		{AC6C354F-8C80-47EA-9E40-996ABE271843}.Debug|x86.ActiveCfg = Debug|Win32
83 89
 		{AC6C354F-8C80-47EA-9E40-996ABE271843}.Debug|x86.Build.0 = Debug|Win32
84 90
 		{AC6C354F-8C80-47EA-9E40-996ABE271843}.Debug|x86.Deploy.0 = Debug|Win32
91
+		{AC6C354F-8C80-47EA-9E40-996ABE271843}.Release|Any CPU.ActiveCfg = Release|Win32
85 92
 		{AC6C354F-8C80-47EA-9E40-996ABE271843}.Release|ARM.ActiveCfg = Release|ARM
86 93
 		{AC6C354F-8C80-47EA-9E40-996ABE271843}.Release|ARM.Build.0 = Release|ARM
87 94
 		{AC6C354F-8C80-47EA-9E40-996ABE271843}.Release|ARM.Deploy.0 = Release|ARM
@@ -94,6 +101,7 @@ Global
94 101
 		{AC6C354F-8C80-47EA-9E40-996ABE271843}.Release|x86.ActiveCfg = Release|Win32
95 102
 		{AC6C354F-8C80-47EA-9E40-996ABE271843}.Release|x86.Build.0 = Release|Win32
96 103
 		{AC6C354F-8C80-47EA-9E40-996ABE271843}.Release|x86.Deploy.0 = Release|Win32
104
+		{A990658C-CE31-4BCC-976F-0FC6B1AF693D}.Debug|Any CPU.ActiveCfg = Debug|Win32
97 105
 		{A990658C-CE31-4BCC-976F-0FC6B1AF693D}.Debug|ARM.ActiveCfg = Debug|ARM
98 106
 		{A990658C-CE31-4BCC-976F-0FC6B1AF693D}.Debug|ARM.Build.0 = Debug|ARM
99 107
 		{A990658C-CE31-4BCC-976F-0FC6B1AF693D}.Debug|ARM64.ActiveCfg = Debug|ARM64
@@ -102,6 +110,7 @@ Global
102 110
 		{A990658C-CE31-4BCC-976F-0FC6B1AF693D}.Debug|x64.Build.0 = Debug|x64
103 111
 		{A990658C-CE31-4BCC-976F-0FC6B1AF693D}.Debug|x86.ActiveCfg = Debug|Win32
104 112
 		{A990658C-CE31-4BCC-976F-0FC6B1AF693D}.Debug|x86.Build.0 = Debug|Win32
113
+		{A990658C-CE31-4BCC-976F-0FC6B1AF693D}.Release|Any CPU.ActiveCfg = Release|Win32
105 114
 		{A990658C-CE31-4BCC-976F-0FC6B1AF693D}.Release|ARM.ActiveCfg = Release|ARM
106 115
 		{A990658C-CE31-4BCC-976F-0FC6B1AF693D}.Release|ARM.Build.0 = Release|ARM
107 116
 		{A990658C-CE31-4BCC-976F-0FC6B1AF693D}.Release|ARM64.ActiveCfg = Release|ARM64
@@ -110,6 +119,7 @@ Global
110 119
 		{A990658C-CE31-4BCC-976F-0FC6B1AF693D}.Release|x64.Build.0 = Release|x64
111 120
 		{A990658C-CE31-4BCC-976F-0FC6B1AF693D}.Release|x86.ActiveCfg = Release|Win32
112 121
 		{A990658C-CE31-4BCC-976F-0FC6B1AF693D}.Release|x86.Build.0 = Release|Win32
122
+		{A9D95A91-4DB7-4F72-BEB6-FE8A5C89BFBD}.Debug|Any CPU.ActiveCfg = Debug|Win32
113 123
 		{A9D95A91-4DB7-4F72-BEB6-FE8A5C89BFBD}.Debug|ARM.ActiveCfg = Debug|ARM
114 124
 		{A9D95A91-4DB7-4F72-BEB6-FE8A5C89BFBD}.Debug|ARM.Build.0 = Debug|ARM
115 125
 		{A9D95A91-4DB7-4F72-BEB6-FE8A5C89BFBD}.Debug|ARM64.ActiveCfg = Debug|ARM64
@@ -118,6 +128,7 @@ Global
118 128
 		{A9D95A91-4DB7-4F72-BEB6-FE8A5C89BFBD}.Debug|x64.Build.0 = Debug|x64
119 129
 		{A9D95A91-4DB7-4F72-BEB6-FE8A5C89BFBD}.Debug|x86.ActiveCfg = Debug|Win32
120 130
 		{A9D95A91-4DB7-4F72-BEB6-FE8A5C89BFBD}.Debug|x86.Build.0 = Debug|Win32
131
+		{A9D95A91-4DB7-4F72-BEB6-FE8A5C89BFBD}.Release|Any CPU.ActiveCfg = Release|Win32
121 132
 		{A9D95A91-4DB7-4F72-BEB6-FE8A5C89BFBD}.Release|ARM.ActiveCfg = Release|ARM
122 133
 		{A9D95A91-4DB7-4F72-BEB6-FE8A5C89BFBD}.Release|ARM.Build.0 = Release|ARM
123 134
 		{A9D95A91-4DB7-4F72-BEB6-FE8A5C89BFBD}.Release|ARM64.ActiveCfg = Release|ARM64
@@ -126,6 +137,7 @@ Global
126 137
 		{A9D95A91-4DB7-4F72-BEB6-FE8A5C89BFBD}.Release|x64.Build.0 = Release|x64
127 138
 		{A9D95A91-4DB7-4F72-BEB6-FE8A5C89BFBD}.Release|x86.ActiveCfg = Release|Win32
128 139
 		{A9D95A91-4DB7-4F72-BEB6-FE8A5C89BFBD}.Release|x86.Build.0 = Release|Win32
140
+		{11C084A3-A57C-4296-A679-CAC17B603144}.Debug|Any CPU.ActiveCfg = Debug|Win32
129 141
 		{11C084A3-A57C-4296-A679-CAC17B603144}.Debug|ARM.ActiveCfg = Debug|ARM
130 142
 		{11C084A3-A57C-4296-A679-CAC17B603144}.Debug|ARM.Build.0 = Debug|ARM
131 143
 		{11C084A3-A57C-4296-A679-CAC17B603144}.Debug|ARM64.ActiveCfg = Debug|ARM64
@@ -134,6 +146,7 @@ Global
134 146
 		{11C084A3-A57C-4296-A679-CAC17B603144}.Debug|x64.Build.0 = Debug|x64
135 147
 		{11C084A3-A57C-4296-A679-CAC17B603144}.Debug|x86.ActiveCfg = Debug|Win32
136 148
 		{11C084A3-A57C-4296-A679-CAC17B603144}.Debug|x86.Build.0 = Debug|Win32
149
+		{11C084A3-A57C-4296-A679-CAC17B603144}.Release|Any CPU.ActiveCfg = Release|Win32
137 150
 		{11C084A3-A57C-4296-A679-CAC17B603144}.Release|ARM.ActiveCfg = Release|ARM
138 151
 		{11C084A3-A57C-4296-A679-CAC17B603144}.Release|ARM.Build.0 = Release|ARM
139 152
 		{11C084A3-A57C-4296-A679-CAC17B603144}.Release|ARM64.ActiveCfg = Release|ARM64
@@ -142,6 +155,7 @@ Global
142 155
 		{11C084A3-A57C-4296-A679-CAC17B603144}.Release|x64.Build.0 = Release|x64
143 156
 		{11C084A3-A57C-4296-A679-CAC17B603144}.Release|x86.ActiveCfg = Release|Win32
144 157
 		{11C084A3-A57C-4296-A679-CAC17B603144}.Release|x86.Build.0 = Release|Win32
158
+		{F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Debug|Any CPU.ActiveCfg = Debug|Win32
145 159
 		{F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Debug|ARM.ActiveCfg = Debug|ARM
146 160
 		{F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Debug|ARM.Build.0 = Debug|ARM
147 161
 		{F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Debug|ARM64.ActiveCfg = Debug|ARM64
@@ -150,6 +164,7 @@ Global
150 164
 		{F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Debug|x64.Build.0 = Debug|x64
151 165
 		{F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Debug|x86.ActiveCfg = Debug|Win32
152 166
 		{F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Debug|x86.Build.0 = Debug|Win32
167
+		{F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Release|Any CPU.ActiveCfg = Release|Win32
153 168
 		{F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Release|ARM.ActiveCfg = Release|ARM
154 169
 		{F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Release|ARM.Build.0 = Release|ARM
155 170
 		{F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Release|ARM64.ActiveCfg = Release|ARM64
@@ -158,6 +173,7 @@ Global
158 173
 		{F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Release|x64.Build.0 = Release|x64
159 174
 		{F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Release|x86.ActiveCfg = Release|Win32
160 175
 		{F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Release|x86.Build.0 = Release|Win32
176
+		{A62D504A-16B8-41D2-9F19-E2E86019E5E4}.Debug|Any CPU.ActiveCfg = Debug|Win32
161 177
 		{A62D504A-16B8-41D2-9F19-E2E86019E5E4}.Debug|ARM.ActiveCfg = Debug|ARM
162 178
 		{A62D504A-16B8-41D2-9F19-E2E86019E5E4}.Debug|ARM.Build.0 = Debug|ARM
163 179
 		{A62D504A-16B8-41D2-9F19-E2E86019E5E4}.Debug|ARM64.ActiveCfg = Debug|ARM64
@@ -166,6 +182,7 @@ Global
166 182
 		{A62D504A-16B8-41D2-9F19-E2E86019E5E4}.Debug|x64.Build.0 = Debug|x64
167 183
 		{A62D504A-16B8-41D2-9F19-E2E86019E5E4}.Debug|x86.ActiveCfg = Debug|Win32
168 184
 		{A62D504A-16B8-41D2-9F19-E2E86019E5E4}.Debug|x86.Build.0 = Debug|Win32
185
+		{A62D504A-16B8-41D2-9F19-E2E86019E5E4}.Release|Any CPU.ActiveCfg = Release|Win32
169 186
 		{A62D504A-16B8-41D2-9F19-E2E86019E5E4}.Release|ARM.ActiveCfg = Release|ARM
170 187
 		{A62D504A-16B8-41D2-9F19-E2E86019E5E4}.Release|ARM.Build.0 = Release|ARM
171 188
 		{A62D504A-16B8-41D2-9F19-E2E86019E5E4}.Release|ARM64.ActiveCfg = Release|ARM64
@@ -174,6 +191,7 @@ Global
174 191
 		{A62D504A-16B8-41D2-9F19-E2E86019E5E4}.Release|x64.Build.0 = Release|x64
175 192
 		{A62D504A-16B8-41D2-9F19-E2E86019E5E4}.Release|x86.ActiveCfg = Release|Win32
176 193
 		{A62D504A-16B8-41D2-9F19-E2E86019E5E4}.Release|x86.Build.0 = Release|Win32
194
+		{FCA38F3C-7C73-4C47-BE4E-32F77FA8538D}.Debug|Any CPU.ActiveCfg = Debug|Win32
177 195
 		{FCA38F3C-7C73-4C47-BE4E-32F77FA8538D}.Debug|ARM.ActiveCfg = Debug|ARM
178 196
 		{FCA38F3C-7C73-4C47-BE4E-32F77FA8538D}.Debug|ARM.Build.0 = Debug|ARM
179 197
 		{FCA38F3C-7C73-4C47-BE4E-32F77FA8538D}.Debug|ARM64.ActiveCfg = Debug|ARM64
@@ -182,6 +200,7 @@ Global
182 200
 		{FCA38F3C-7C73-4C47-BE4E-32F77FA8538D}.Debug|x64.Build.0 = Debug|x64
183 201
 		{FCA38F3C-7C73-4C47-BE4E-32F77FA8538D}.Debug|x86.ActiveCfg = Debug|Win32
184 202
 		{FCA38F3C-7C73-4C47-BE4E-32F77FA8538D}.Debug|x86.Build.0 = Debug|Win32
203
+		{FCA38F3C-7C73-4C47-BE4E-32F77FA8538D}.Release|Any CPU.ActiveCfg = Release|Win32
185 204
 		{FCA38F3C-7C73-4C47-BE4E-32F77FA8538D}.Release|ARM.ActiveCfg = Release|ARM
186 205
 		{FCA38F3C-7C73-4C47-BE4E-32F77FA8538D}.Release|ARM.Build.0 = Release|ARM
187 206
 		{FCA38F3C-7C73-4C47-BE4E-32F77FA8538D}.Release|ARM64.ActiveCfg = Release|ARM64
@@ -190,6 +209,7 @@ Global
190 209
 		{FCA38F3C-7C73-4C47-BE4E-32F77FA8538D}.Release|x64.Build.0 = Release|x64
191 210
 		{FCA38F3C-7C73-4C47-BE4E-32F77FA8538D}.Release|x86.ActiveCfg = Release|Win32
192 211
 		{FCA38F3C-7C73-4C47-BE4E-32F77FA8538D}.Release|x86.Build.0 = Release|Win32
212
+		{729D9AF8-CD9E-4427-9F6C-FB757E287729}.Debug|Any CPU.ActiveCfg = Debug|Win32
193 213
 		{729D9AF8-CD9E-4427-9F6C-FB757E287729}.Debug|ARM.ActiveCfg = Debug|ARM
194 214
 		{729D9AF8-CD9E-4427-9F6C-FB757E287729}.Debug|ARM.Build.0 = Debug|ARM
195 215
 		{729D9AF8-CD9E-4427-9F6C-FB757E287729}.Debug|ARM64.ActiveCfg = Debug|Win32
@@ -197,6 +217,7 @@ Global
197 217
 		{729D9AF8-CD9E-4427-9F6C-FB757E287729}.Debug|x64.Build.0 = Debug|x64
198 218
 		{729D9AF8-CD9E-4427-9F6C-FB757E287729}.Debug|x86.ActiveCfg = Debug|Win32
199 219
 		{729D9AF8-CD9E-4427-9F6C-FB757E287729}.Debug|x86.Build.0 = Debug|Win32
220
+		{729D9AF8-CD9E-4427-9F6C-FB757E287729}.Release|Any CPU.ActiveCfg = Release|Win32
200 221
 		{729D9AF8-CD9E-4427-9F6C-FB757E287729}.Release|ARM.ActiveCfg = Release|ARM
201 222
 		{729D9AF8-CD9E-4427-9F6C-FB757E287729}.Release|ARM.Build.0 = Release|ARM
202 223
 		{729D9AF8-CD9E-4427-9F6C-FB757E287729}.Release|ARM64.ActiveCfg = Release|Win32
@@ -204,6 +225,24 @@ Global
204 225
 		{729D9AF8-CD9E-4427-9F6C-FB757E287729}.Release|x64.Build.0 = Release|x64
205 226
 		{729D9AF8-CD9E-4427-9F6C-FB757E287729}.Release|x86.ActiveCfg = Release|Win32
206 227
 		{729D9AF8-CD9E-4427-9F6C-FB757E287729}.Release|x86.Build.0 = Release|Win32
228
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Debug|Any CPU.ActiveCfg = Debug|Win32
229
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Debug|ARM.ActiveCfg = Debug|ARM
230
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Debug|ARM.Build.0 = Debug|ARM
231
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Debug|ARM64.ActiveCfg = Debug|ARM64
232
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Debug|ARM64.Build.0 = Debug|ARM64
233
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Debug|x64.ActiveCfg = Debug|x64
234
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Debug|x64.Build.0 = Debug|x64
235
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Debug|x86.ActiveCfg = Debug|Win32
236
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Debug|x86.Build.0 = Debug|Win32
237
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Release|Any CPU.ActiveCfg = Release|Win32
238
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Release|ARM.ActiveCfg = Release|ARM
239
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Release|ARM.Build.0 = Release|ARM
240
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Release|ARM64.ActiveCfg = Release|ARM64
241
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Release|ARM64.Build.0 = Release|ARM64
242
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Release|x64.ActiveCfg = Release|x64
243
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Release|x64.Build.0 = Release|x64
244
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Release|x86.ActiveCfg = Release|Win32
245
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Release|x86.Build.0 = Release|Win32
207 246
 	EndGlobalSection
208 247
 	GlobalSection(SolutionProperties) = preSolution
209 248
 		HideSolutionNode = FALSE

+ 4
- 4
example/windows/WebViewWindows/WebViewWindows.vcxproj Wyświetl plik

@@ -1,6 +1,6 @@
1 1
 <?xml version="1.0" encoding="utf-8"?>
2 2
 <Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
-  <Import Project="$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.props')" />
3
+  <Import Project="$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.props')" />
4 4
   <PropertyGroup Label="Globals">
5 5
     <CppWinRTOptimized>true</CppWinRTOptimized>
6 6
     <CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge>
@@ -167,15 +167,15 @@
167 167
   <Import Project="..\..\..\node_modules\react-native-windows\PropertySheets\Bundle.Cpp.targets" />
168 168
   <Import Project="..\..\..\node_modules\react-native-windows\PropertySheets\Bundle.props" />
169 169
   <ImportGroup Label="ExtensionTargets">
170
-    <Import Project="$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.targets')" />
170
+    <Import Project="$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.targets')" />
171 171
     <Import Project="$(SolutionDir)packages\Microsoft.UI.Xaml.2.3.191129002\build\native\Microsoft.UI.Xaml.targets" Condition="Exists('$(SolutionDir)packages\Microsoft.UI.Xaml.2.3.191129002\build\native\Microsoft.UI.Xaml.targets')" />
172 172
   </ImportGroup>
173 173
   <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
174 174
     <PropertyGroup>
175 175
       <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
176 176
     </PropertyGroup>
177
-    <Error Condition="!Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.props'))" />
178
-    <Error Condition="!Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.targets'))" />
177
+    <Error Condition="!Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.props'))" />
178
+    <Error Condition="!Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.targets'))" />
179 179
     <Error Condition="!Exists('$(SolutionDir)packages\Microsoft.UI.Xaml.2.3.191129002\build\native\Microsoft.UI.Xaml.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)packages\Microsoft.UI.Xaml.2.3.191129002\build\native\Microsoft.UI.Xaml.targets'))" />
180 180
   </Target>
181 181
 </Project>

+ 1
- 1
example/windows/WebViewWindows/packages.config Wyświetl plik

@@ -1,5 +1,5 @@
1 1
 <?xml version="1.0" encoding="utf-8"?>
2 2
 <packages>
3
-  <package id="Microsoft.Windows.CppWinRT" version="2.0.190730.2" targetFramework="native" />
3
+  <package id="Microsoft.Windows.CppWinRT" version="2.0.200729.8" targetFramework="native" />
4 4
   <package id="Microsoft.UI.Xaml" version="2.3.191129002" targetFramework="native" />
5 5
 </packages>

+ 1
- 1
package.json Wyświetl plik

@@ -65,7 +65,7 @@
65 65
     "react": "16.11.0",
66 66
     "react-native": "0.62.2",
67 67
     "react-native-macos": "0.60.0-microsoft.73",
68
-    "react-native-windows": "^0.62.0-0",
68
+    "react-native-windows": "^0.62.5",
69 69
     "semantic-release": "15.13.24",
70 70
     "typescript": "3.8.3",
71 71
     "appium": "1.17.0",

+ 21
- 0
windows/ReactNativeWebView.sln Wyświetl plik

@@ -29,10 +29,14 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ReactUWP", "..\node_modules
29 29
 EndProject
30 30
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ReactWindowsCore", "..\node_modules\react-native-windows\ReactWindowsCore\ReactWindowsCore.vcxproj", "{11C084A3-A57C-4296-A679-CAC17B603144}"
31 31
 EndProject
32
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WebViewBridgeComponent", "WebViewBridgeComponent\WebViewBridgeComponent.vcxproj", "{FCB612AD-FACC-410C-828C-24B5940B2762}"
33
+EndProject
32 34
 Global
33 35
 	GlobalSection(SharedMSBuildProjectFiles) = preSolution
34 36
 		..\node_modules\react-native-windows\JSI\Shared\JSI.Shared.vcxitems*{0cc28589-39e4-4288-b162-97b959f8b843}*SharedItemsImports = 9
37
+		..\node_modules\react-native-windows\ReactWindowsCore\ReactWindowsCore.vcxitems*{11c084a3-a57c-4296-a679-cac17b603144}*SharedItemsImports = 4
35 38
 		..\node_modules\react-native-windows\Chakra\Chakra.vcxitems*{2d5d43d9-cffc-4c40-b4cd-02efb4e2742b}*SharedItemsImports = 4
39
+		..\node_modules\react-native-windows\Mso\Mso.vcxitems*{2d5d43d9-cffc-4c40-b4cd-02efb4e2742b}*SharedItemsImports = 4
36 40
 		..\node_modules\react-native-windows\Shared\Shared.vcxitems*{2d5d43d9-cffc-4c40-b4cd-02efb4e2742b}*SharedItemsImports = 4
37 41
 		..\node_modules\react-native-windows\Microsoft.ReactNative.SharedManaged\Microsoft.ReactNative.SharedManaged.projitems*{67a1076f-7790-4203-86ea-4402ccb5e782}*SharedItemsImports = 13
38 42
 		..\node_modules\react-native-windows\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.vcxitems*{729d9af8-cd9e-4427-9f6c-fb757e287729}*SharedItemsImports = 4
@@ -41,6 +45,7 @@ Global
41 45
 		..\node_modules\react-native-windows\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.vcxitems*{da8b35b3-da00-4b02-bde6-6a397b3fd46b}*SharedItemsImports = 9
42 46
 		..\node_modules\react-native-windows\Chakra\Chakra.vcxitems*{f7d32bd0-2749-483e-9a0d-1635ef7e3136}*SharedItemsImports = 4
43 47
 		..\node_modules\react-native-windows\JSI\Shared\JSI.Shared.vcxitems*{f7d32bd0-2749-483e-9a0d-1635ef7e3136}*SharedItemsImports = 4
48
+		..\node_modules\react-native-windows\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.vcxitems*{f7d32bd0-2749-483e-9a0d-1635ef7e3136}*SharedItemsImports = 4
44 49
 		..\node_modules\react-native-windows\Mso\Mso.vcxitems*{f7d32bd0-2749-483e-9a0d-1635ef7e3136}*SharedItemsImports = 4
45 50
 		..\node_modules\react-native-windows\Shared\Shared.vcxitems*{f7d32bd0-2749-483e-9a0d-1635ef7e3136}*SharedItemsImports = 4
46 51
 	EndGlobalSection
@@ -181,6 +186,22 @@ Global
181 186
 		{11C084A3-A57C-4296-A679-CAC17B603144}.Release|x64.Build.0 = Release|x64
182 187
 		{11C084A3-A57C-4296-A679-CAC17B603144}.Release|x86.ActiveCfg = Release|Win32
183 188
 		{11C084A3-A57C-4296-A679-CAC17B603144}.Release|x86.Build.0 = Release|Win32
189
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Debug|ARM.ActiveCfg = Debug|ARM
190
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Debug|ARM.Build.0 = Debug|ARM
191
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Debug|ARM64.ActiveCfg = Debug|ARM64
192
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Debug|ARM64.Build.0 = Debug|ARM64
193
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Debug|x64.ActiveCfg = Debug|x64
194
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Debug|x64.Build.0 = Debug|x64
195
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Debug|x86.ActiveCfg = Debug|Win32
196
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Debug|x86.Build.0 = Debug|Win32
197
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Release|ARM.ActiveCfg = Release|ARM
198
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Release|ARM.Build.0 = Release|ARM
199
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Release|ARM64.ActiveCfg = Release|ARM64
200
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Release|ARM64.Build.0 = Release|ARM64
201
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Release|x64.ActiveCfg = Release|x64
202
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Release|x64.Build.0 = Release|x64
203
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Release|x86.ActiveCfg = Release|Win32
204
+		{FCB612AD-FACC-410C-828C-24B5940B2762}.Release|x86.Build.0 = Release|Win32
184 205
 	EndGlobalSection
185 206
 	GlobalSection(SolutionProperties) = preSolution
186 207
 		HideSolutionNode = FALSE

+ 7
- 4
windows/ReactNativeWebView/ReactNativeWebView.vcxproj Wyświetl plik

@@ -1,6 +1,6 @@
1 1
 <?xml version="1.0" encoding="utf-8"?>
2 2
 <Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
-  <Import Project="$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.props')" />
3
+  <Import Project="$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.props')" /> 
4 4
   <PropertyGroup Label="Globals">
5 5
     <CppWinRTOptimized>true</CppWinRTOptimized>
6 6
     <CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge>
@@ -145,16 +145,19 @@
145 145
       <Project>{f7d32bd0-2749-483e-9a0d-1635ef7e3136}</Project>
146 146
       <Private>false</Private>
147 147
     </ProjectReference>
148
+    <ProjectReference Include="..\WebViewBridgeComponent\WebViewBridgeComponent.vcxproj">
149
+      <Project>{176323cd-97ce-4b0f-9d11-a2b77bda829b}</Project>
150
+    </ProjectReference>
148 151
   </ItemGroup>
149 152
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
150 153
   <ImportGroup Label="ExtensionTargets">
151
-    <Import Project="$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.targets')" />
154
+    <Import Project="$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.targets')" />
152 155
   </ImportGroup>
153 156
   <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
154 157
     <PropertyGroup>
155 158
       <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
156 159
     </PropertyGroup>
157
-    <Error Condition="!Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.props'))" />
158
-    <Error Condition="!Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.targets'))" />
160
+    <Error Condition="!Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.props'))" />
161
+    <Error Condition="!Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.targets'))" />
159 162
   </Target>
160 163
 </Project>

+ 64
- 49
windows/ReactNativeWebView/ReactWebView.cpp Wyświetl plik

@@ -6,6 +6,8 @@
6 6
 #include "ReactWebView.h"
7 7
 #include "ReactWebView.g.cpp"
8 8
 
9
+
10
+
9 11
 namespace winrt {
10 12
     using namespace Microsoft::ReactNative;
11 13
     using namespace Windows::Data::Json;
@@ -26,11 +28,15 @@ namespace winrt::ReactNativeWebView::implementation {
26 28
 #else
27 29
         m_webView = winrt::WebView();
28 30
 #endif
31
+        this->Content(m_webView);
29 32
         RegisterEvents();
30 33
     }
31 34
 
32
-    winrt::WebView ReactWebView::GetView() {
33
-        return m_webView;
35
+    ReactWebView::~ReactWebView()
36
+    {
37
+      if (m_messagingEnabled) {
38
+        m_webBridge.MessagePostEvent(m_message_token);
39
+      }
34 40
     }
35 41
 
36 42
     void ReactWebView::RegisterEvents() {
@@ -55,94 +61,103 @@ namespace winrt::ReactNativeWebView::implementation {
55 61
                     self->OnNavigationFailed(sender, args);
56 62
                 }
57 63
             });
58
-
59
-        m_scriptNotifyRevoker = m_webView.ScriptNotify(
60
-            winrt::auto_revoke, [ref = get_weak()](auto const& sender, auto const& args) {
61
-                if (auto self = ref.get()) {
62
-                    self->OnScriptNotify(sender, args);
63
-                }
64
-            });
65 64
     }
66 65
 
67
-    void ReactWebView::WriteWebViewNavigationEventArg(winrt::IJSValueWriter const& eventDataWriter) {
68
-        auto tag = m_webView.GetValue(winrt::FrameworkElement::TagProperty()).as<winrt::IPropertyValue>().GetInt64();
69
-        WriteProperty(eventDataWriter, L"canGoBack", m_webView.CanGoBack());
70
-        WriteProperty(eventDataWriter, L"canGoForward", m_webView.CanGoForward());
71
-        WriteProperty(eventDataWriter, L"loading", !m_webView.IsLoaded());
66
+    void ReactWebView::WriteWebViewNavigationEventArg(winrt::WebView const& sender, winrt::IJSValueWriter const& eventDataWriter) {
67
+        auto tag = this->GetValue(winrt::FrameworkElement::TagProperty()).as<winrt::IPropertyValue>().GetInt64();
68
+        WriteProperty(eventDataWriter, L"canGoBack", sender.CanGoBack());
69
+        WriteProperty(eventDataWriter, L"canGoForward", sender.CanGoForward());
70
+        WriteProperty(eventDataWriter, L"loading", !sender.IsLoaded());
72 71
         WriteProperty(eventDataWriter, L"target", tag);
73
-        WriteProperty(eventDataWriter, L"title", m_webView.DocumentTitle());
74
-        if (auto uri = m_webView.Source()) {
75
-            WriteProperty(eventDataWriter, L"url", uri.AbsoluteCanonicalUri());
72
+        WriteProperty(eventDataWriter, L"title", sender.DocumentTitle());
73
+        if (auto uri = sender.Source()) {
74
+          WriteProperty(eventDataWriter, L"url", uri.AbsoluteCanonicalUri());
76 75
         }
77 76
     }
78 77
 
79 78
     void ReactWebView::OnNavigationStarting(winrt::WebView const& webView, winrt::WebViewNavigationStartingEventArgs const& /*args*/) {
80 79
         m_reactContext.DispatchEvent(
81
-            webView,
80
+            *this,
82 81
             L"topLoadingStart",
83 82
             [&](winrt::IJSValueWriter const& eventDataWriter) noexcept {
84 83
                 eventDataWriter.WriteObjectBegin();
85
-                WriteWebViewNavigationEventArg(eventDataWriter);
84
+                WriteWebViewNavigationEventArg(webView, eventDataWriter);
86 85
                 eventDataWriter.WriteObjectEnd();
87 86
             });
87
+
88
+        if (m_messagingEnabled) {
89
+          m_webBridge = WebBridge();
90
+          m_message_token = m_webBridge.MessagePostEvent([this](const auto&, hstring const& message)
91
+            {
92
+              this->OnMessagePosted(message);
93
+            });
94
+          webView.AddWebAllowedObject(L"__REACT_WEB_VIEW_BRIDGE", m_webBridge);
95
+        }
96
+    }
97
+
98
+    void ReactWebView::OnMessagePosted(hstring const& message)
99
+    {
100
+      PostMessage(message);
88 101
     }
89 102
 
90 103
     void ReactWebView::OnNavigationCompleted(winrt::WebView const& webView, winrt::WebViewNavigationCompletedEventArgs const& /*args*/) {
91 104
         m_reactContext.DispatchEvent(
92
-            webView,
105
+            *this,
93 106
             L"topLoadingFinish",
94 107
             [&](winrt::IJSValueWriter const& eventDataWriter) noexcept {
95 108
                 eventDataWriter.WriteObjectBegin();
96
-                WriteWebViewNavigationEventArg(eventDataWriter);
109
+                WriteWebViewNavigationEventArg(webView, eventDataWriter);
97 110
                 eventDataWriter.WriteObjectEnd();
98 111
             });
99 112
 
100
-        winrt::hstring windowAlert = L"window.alert = function (msg) {window.external.notify(`{\"type\":\"__alert\",\"message\":\"${msg}\"}`)};";
101
-        winrt::hstring postMessage = L"window.ReactNativeWebView = {postMessage: function (data) {window.external.notify(String(data))}};";
102
-        m_webView.InvokeScriptAsync(L"eval", { windowAlert + postMessage });
113
+        if (m_messagingEnabled) {
114
+          winrt::hstring windowAlert = L"window.alert = function (msg) {__REACT_WEB_VIEW_BRIDGE.postMessage(`{\"type\":\"__alert\",\"message\":\"${msg}\"}`)};";
115
+          winrt::hstring postMessage = L"window.ReactNativeWebView = {postMessage: function (data) {__REACT_WEB_VIEW_BRIDGE.postMessage(String(data))}};";
116
+          webView.InvokeScriptAsync(L"eval", { windowAlert + postMessage });
117
+        }
103 118
     }
104 119
 
105 120
     void ReactWebView::OnNavigationFailed(winrt::IInspectable const& /*sender*/, winrt::WebViewNavigationFailedEventArgs const& args) {
106 121
         m_reactContext.DispatchEvent(
107
-            m_webView,
122
+            *this,
108 123
             L"topLoadingError",
109 124
             [&](winrt::IJSValueWriter const& eventDataWriter) noexcept {
110 125
                 auto httpCode = static_cast<int32_t>(args.WebErrorStatus());
111 126
                 eventDataWriter.WriteObjectBegin();
112 127
                 {
113 128
                     WriteProperty(eventDataWriter, L"code", httpCode);
114
-                    WriteWebViewNavigationEventArg(eventDataWriter);
129
+                    WriteWebViewNavigationEventArg(m_webView, eventDataWriter);
115 130
                 }
116 131
                 eventDataWriter.WriteObjectEnd();
117 132
             });
118 133
     }
119 134
 
120
-    void ReactWebView::OnScriptNotify(winrt::IInspectable const& /*sender*/, winrt::Windows::UI::Xaml::Controls::NotifyEventArgs const& args) {
121
-        winrt::JsonObject jsonObject;
122
-        if (winrt::JsonObject::TryParse(args.Value(), jsonObject) && jsonObject.HasKey(L"type")) {
123
-            auto type = jsonObject.GetNamedString(L"type");
124
-            if (type == L"__alert") {
125
-                auto dialog = winrt::MessageDialog(jsonObject.GetNamedString(L"message"));
126
-                dialog.Commands().Append(winrt::UICommand(L"OK"));
127
-                dialog.ShowAsync();
128
-                return;
129
-            }
135
+    void ReactWebView::PostMessage(winrt::hstring const& message) {
136
+      winrt::JsonObject jsonObject;
137
+      if (winrt::JsonObject::TryParse(message, jsonObject) && jsonObject.HasKey(L"type")) {
138
+          auto type = jsonObject.GetNamedString(L"type");
139
+          if (type == L"__alert") {
140
+            auto dialog = winrt::MessageDialog(jsonObject.GetNamedString(L"message"));
141
+            dialog.Commands().Append(winrt::UICommand(L"OK"));
142
+            dialog.ShowAsync();
143
+            return;
144
+          }
130 145
         }
131
-        
132
-        PostMessage(winrt::hstring(args.Value()));
146
+      
147
+        m_reactContext.DispatchEvent(
148
+              *this,
149
+              L"topMessage",
150
+              [&](winrt::Microsoft::ReactNative::IJSValueWriter const& eventDataWriter) noexcept {
151
+                  eventDataWriter.WriteObjectBegin();
152
+                  {
153
+                      WriteProperty(eventDataWriter, L"data", message);
154
+                  }
155
+                  eventDataWriter.WriteObjectEnd();
156
+              });
133 157
     }
134 158
 
135
-    void ReactWebView::PostMessage(winrt::hstring const& message) {
136
-        m_reactContext.DispatchEvent(
137
-            m_webView,
138
-            L"topMessage",
139
-            [&](winrt::Microsoft::ReactNative::IJSValueWriter const& eventDataWriter) noexcept {
140
-                eventDataWriter.WriteObjectBegin();
141
-                {
142
-                    WriteProperty(eventDataWriter, L"data", message);
143
-                }
144
-                eventDataWriter.WriteObjectEnd();
145
-            });
159
+    void ReactWebView::SetMessagingEnabled(bool enabled) {
160
+      m_messagingEnabled = enabled;
146 161
     }
147 162
 
148 163
 } // namespace winrt::ReactNativeWebView::implementation

+ 11
- 4
windows/ReactNativeWebView/ReactWebView.h Wyświetl plik

@@ -7,28 +7,35 @@
7 7
 #include "NativeModules.h"
8 8
 #include "ReactWebView.g.h"
9 9
 
10
+#include "winrt/WebViewBridgeComponent.h"
11
+
12
+using namespace winrt::WebViewBridgeComponent;
13
+
10 14
 namespace winrt::ReactNativeWebView::implementation {
11 15
 
12 16
     class ReactWebView : public ReactWebViewT<ReactWebView> {
13 17
     public:
14 18
         ReactWebView(Microsoft::ReactNative::IReactContext const& reactContext);
15
-        winrt::Windows::UI::Xaml::Controls::WebView GetView();
16 19
         void PostMessage(winrt::hstring const& message);
20
+        void SetMessagingEnabled(bool enabled);
21
+        ~ReactWebView();
17 22
 
18 23
     private:
24
+        bool m_messagingEnabled{ true };
19 25
         winrt::Windows::UI::Xaml::Controls::WebView m_webView{ nullptr };
20 26
         Microsoft::ReactNative::IReactContext m_reactContext{ nullptr };
27
+        WebBridge m_webBridge{ nullptr };
28
+        winrt::event_token m_message_token;
21 29
         winrt::Windows::UI::Xaml::Controls::WebView::NavigationStarting_revoker m_navigationStartingRevoker{};
22 30
         winrt::Windows::UI::Xaml::Controls::WebView::NavigationCompleted_revoker m_navigationCompletedRevoker{};
23 31
         winrt::Windows::UI::Xaml::Controls::WebView::NavigationFailed_revoker m_navigationFailedRevoker{};
24
-        winrt::Windows::UI::Xaml::Controls::WebView::ScriptNotify_revoker m_scriptNotifyRevoker{};
25 32
 
26 33
         void RegisterEvents();
27
-        void WriteWebViewNavigationEventArg(winrt::Microsoft::ReactNative::IJSValueWriter const& eventDataWriter);
34
+        void WriteWebViewNavigationEventArg(winrt::Windows::UI::Xaml::Controls::WebView const& sender, winrt::Microsoft::ReactNative::IJSValueWriter const& eventDataWriter);
28 35
         void OnNavigationStarting(winrt::Windows::UI::Xaml::Controls::WebView const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationStartingEventArgs const& args);
29 36
         void OnNavigationCompleted(winrt::Windows::UI::Xaml::Controls::WebView const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationCompletedEventArgs const& args);
30 37
         void OnNavigationFailed(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationFailedEventArgs const& args);
31
-        void OnScriptNotify(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::NotifyEventArgs const& args);
38
+        void OnMessagePosted(hstring const& message);
32 39
     };
33 40
 } // namespace winrt::ReactNativeWebView::implementation
34 41
 

+ 1
- 1
windows/ReactNativeWebView/ReactWebView.idl Wyświetl plik

@@ -2,7 +2,7 @@ namespace ReactNativeWebView{
2 2
     [default_interface]
3 3
     runtimeclass ReactWebView : Windows.UI.Xaml.Controls.UserControl{
4 4
         ReactWebView(Microsoft.ReactNative.IReactContext context);
5
-        Windows.UI.Xaml.Controls.WebView GetView();
6 5
         void PostMessage(String message);
6
+        void SetMessagingEnabled(Boolean enabled);
7 7
     };
8 8
 } // namespace ReactNativeWebView

+ 19
- 5
windows/ReactNativeWebView/ReactWebViewManager.cpp Wyświetl plik

@@ -23,8 +23,8 @@ namespace winrt::ReactNativeWebView::implementation {
23 23
     }
24 24
 
25 25
     winrt::FrameworkElement ReactWebViewManager::CreateView() noexcept {
26
-        m_reactWebView = *winrt::make_self<ReactWebView>(m_reactContext);
27
-        return m_reactWebView.GetView();
26
+      auto view = winrt::ReactNativeWebView::ReactWebView(m_reactContext);
27
+      return view;
28 28
     }
29 29
 
30 30
     // IViewManagerWithReactContext
@@ -40,13 +40,17 @@ namespace winrt::ReactNativeWebView::implementation {
40 40
     IMapView<hstring, ViewManagerPropertyType> ReactWebViewManager::NativeProps() noexcept {
41 41
         auto nativeProps = winrt::single_threaded_map<hstring, ViewManagerPropertyType>();
42 42
         nativeProps.Insert(L"source", ViewManagerPropertyType::Map);
43
+        nativeProps.Insert(L"backgroundColor", ViewManagerPropertyType::Color);
44
+        nativeProps.Insert(L"messagingEnabled", ViewManagerPropertyType::Boolean);
43 45
         return nativeProps.GetView();
44 46
     }
45 47
 
46 48
     void ReactWebViewManager::UpdateProperties(
47 49
         FrameworkElement const& view,
48 50
         IJSValueReader const& propertyMapReader) noexcept {
49
-        if (auto webView = view.try_as<winrt::WebView>()) {
51
+        auto control = view.try_as<winrt::UserControl>();
52
+        auto content = control.Content();
53
+        if (auto webView = content.try_as<winrt::WebView>()) {
50 54
             const JSValueObject& propertyMap = JSValueObject::ReadFrom(propertyMapReader);
51 55
 
52 56
             for (auto const& pair : propertyMap) {
@@ -82,6 +86,12 @@ namespace winrt::ReactNativeWebView::implementation {
82 86
                     auto color = propertyValue.To<winrt::Color>();
83 87
                     webView.DefaultBackgroundColor(color.A==0 ? winrt::Colors::Transparent() : color);
84 88
                 }
89
+                else if (propertyName == "messagingEnabled") {
90
+                  auto messagingEnabled = propertyValue.To<bool>();
91
+                  if (auto reactWebView = view.try_as<ReactNativeWebView::ReactWebView>()) {
92
+                    reactWebView.SetMessagingEnabled(messagingEnabled);
93
+                  }
94
+                }
85 95
             }
86 96
         }
87 97
     }
@@ -116,8 +126,10 @@ namespace winrt::ReactNativeWebView::implementation {
116 126
         FrameworkElement const& view,
117 127
         winrt::hstring const& commandId,
118 128
         winrt::IJSValueReader const& commandArgsReader) noexcept {
129
+        auto control = view.try_as<winrt::UserControl>();
130
+        auto content = control.Content();
119 131
         auto commandArgs = JSValue::ReadArrayFrom(commandArgsReader);
120
-        if (auto webView = view.try_as<winrt::WebView>()) {
132
+        if (auto webView = content.try_as<winrt::WebView>()) {
121 133
             if (commandId == L"goForward") {
122 134
                 if (webView.CanGoForward()) {
123 135
                     webView.GoForward();
@@ -137,7 +149,9 @@ namespace winrt::ReactNativeWebView::implementation {
137 149
             else if (commandId == L"injectJavaScript") {
138 150
                 webView.InvokeScriptAsync(L"eval", { winrt::to_hstring(commandArgs[0].AsString()) });
139 151
             } else if(commandId == L"postMessage") {
140
-                m_reactWebView.PostMessage(winrt::to_hstring(commandArgs[0].AsString()));
152
+                if (auto reactWebView = view.try_as<ReactNativeWebView::ReactWebView>()) {
153
+                    reactWebView.PostMessage(winrt::to_hstring(commandArgs[0].AsString()));
154
+                }
141 155
             }
142 156
         }
143 157
     }

+ 0
- 1
windows/ReactNativeWebView/ReactWebViewManager.h Wyświetl plik

@@ -47,7 +47,6 @@ namespace winrt::ReactNativeWebView::implementation {
47 47
             winrt::Microsoft::ReactNative::IJSValueReader const& commandArgsReader) noexcept;
48 48
 
49 49
     private:
50
-        winrt::ReactNativeWebView::ReactWebView m_reactWebView{ nullptr };
51 50
         winrt::Microsoft::ReactNative::IReactContext m_reactContext{ nullptr };
52 51
 
53 52
     };

+ 1
- 1
windows/ReactNativeWebView/packages.config Wyświetl plik

@@ -1,4 +1,4 @@
1 1
 <?xml version="1.0" encoding="utf-8"?>
2 2
 <packages>
3
-  <package id="Microsoft.Windows.CppWinRT" version="2.0.190730.2" targetFramework="native" />
3
+  <package id="Microsoft.Windows.CppWinRT" version="2.0.200316.3" targetFramework="native" />
4 4
 </packages>

+ 16
- 0
windows/WebViewBridgeComponent/PropertySheet.props Wyświetl plik

@@ -0,0 +1,16 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
+  <ImportGroup Label="PropertySheets" />
4
+  <PropertyGroup Label="UserMacros" />
5
+  <!--
6
+    To customize common C++/WinRT project properties: 
7
+    * right-click the project node
8
+    * expand the Common Properties item
9
+    * select the C++/WinRT property page
10
+
11
+    For more advanced scenarios, and complete documentation, please see:
12
+    https://github.com/Microsoft/cppwinrt/tree/master/nuget 
13
+    -->
14
+  <PropertyGroup />
15
+  <ItemDefinitionGroup />
16
+</Project>

+ 19
- 0
windows/WebViewBridgeComponent/WebBridge.cpp Wyświetl plik

@@ -0,0 +1,19 @@
1
+#include "pch.h"
2
+#include "WebBridge.h"
3
+#include "WebBridge.g.cpp"
4
+
5
+namespace winrt::WebViewBridgeComponent::implementation
6
+{
7
+    void WebBridge::PostMessage(hstring const& message)
8
+    {
9
+        m_messageEvent(*this, message);
10
+    }
11
+    winrt::event_token WebBridge::MessagePostEvent(Windows::Foundation::EventHandler<hstring> const& handler)
12
+    {
13
+        return m_messageEvent.add(handler);
14
+    }
15
+    void WebBridge::MessagePostEvent(winrt::event_token const& token) noexcept
16
+    {
17
+        m_messageEvent.remove(token);
18
+    }
19
+}

+ 24
- 0
windows/WebViewBridgeComponent/WebBridge.h Wyświetl plik

@@ -0,0 +1,24 @@
1
+#pragma once
2
+#include "WebBridge.g.h"
3
+
4
+
5
+namespace winrt::WebViewBridgeComponent::implementation
6
+{
7
+    struct WebBridge : WebBridgeT<WebBridge>
8
+    {
9
+        WebBridge() = default;
10
+
11
+        void PostMessage(hstring const& message);
12
+        winrt::event_token MessagePostEvent(Windows::Foundation::EventHandler<hstring> const& handler);
13
+        void MessagePostEvent(winrt::event_token const& token) noexcept;
14
+
15
+    private:
16
+      winrt::event<Windows::Foundation::EventHandler<winrt::hstring>> m_messageEvent;
17
+    };
18
+}
19
+namespace winrt::WebViewBridgeComponent::factory_implementation
20
+{
21
+    struct WebBridge : WebBridgeT<WebBridge, implementation::WebBridge>
22
+    {
23
+    };
24
+}

+ 11
- 0
windows/WebViewBridgeComponent/WebBridge.idl Wyświetl plik

@@ -0,0 +1,11 @@
1
+namespace WebViewBridgeComponent
2
+{
3
+    [default_interface]
4
+    [allowforweb]
5
+    runtimeclass WebBridge
6
+    {
7
+        WebBridge();
8
+        void PostMessage(String message);
9
+        event Windows.Foundation.EventHandler<String> MessagePostEvent;
10
+    }
11
+}

+ 3
- 0
windows/WebViewBridgeComponent/WebViewBridgeComponent.def Wyświetl plik

@@ -0,0 +1,3 @@
1
+EXPORTS
2
+DllCanUnloadNow = WINRT_CanUnloadNow                    PRIVATE
3
+DllGetActivationFactory = WINRT_GetActivationFactory    PRIVATE

+ 158
- 0
windows/WebViewBridgeComponent/WebViewBridgeComponent.vcxproj Wyświetl plik

@@ -0,0 +1,158 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
+  <Import Project="$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.props')" />
4
+  <PropertyGroup Label="Globals">
5
+    <CppWinRTOptimized>true</CppWinRTOptimized>
6
+    <CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge>
7
+    <CppWinRTGenerateWindowsMetadata>true</CppWinRTGenerateWindowsMetadata>
8
+    <MinimalCoreWin>true</MinimalCoreWin>
9
+    <ProjectGuid>{fcb612ad-facc-410c-828c-24b5940b2762}</ProjectGuid>
10
+    <ProjectName>WebViewBridgeComponent</ProjectName>
11
+    <RootNamespace>WebViewBridgeComponent</RootNamespace>
12
+    <DefaultLanguage>en-US</DefaultLanguage>
13
+    <MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
14
+    <AppContainerApplication>true</AppContainerApplication>
15
+    <ApplicationType>Windows Store</ApplicationType>
16
+    <ApplicationTypeRevision>10.0</ApplicationTypeRevision>
17
+    <WindowsTargetPlatformVersion Condition=" '$(WindowsTargetPlatformVersion)' == '' ">10.0.18362.0</WindowsTargetPlatformVersion>
18
+    <WindowsTargetPlatformMinVersion>10.0.17134.0</WindowsTargetPlatformMinVersion>
19
+  </PropertyGroup>
20
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
21
+  <ItemGroup Label="ProjectConfigurations">
22
+    <ProjectConfiguration Include="Debug|ARM">
23
+      <Configuration>Debug</Configuration>
24
+      <Platform>ARM</Platform>
25
+    </ProjectConfiguration>
26
+    <ProjectConfiguration Include="Debug|ARM64">
27
+      <Configuration>Debug</Configuration>
28
+      <Platform>ARM64</Platform>
29
+    </ProjectConfiguration>
30
+    <ProjectConfiguration Include="Debug|Win32">
31
+      <Configuration>Debug</Configuration>
32
+      <Platform>Win32</Platform>
33
+    </ProjectConfiguration>
34
+    <ProjectConfiguration Include="Debug|x64">
35
+      <Configuration>Debug</Configuration>
36
+      <Platform>x64</Platform>
37
+    </ProjectConfiguration>
38
+    <ProjectConfiguration Include="Release|ARM">
39
+      <Configuration>Release</Configuration>
40
+      <Platform>ARM</Platform>
41
+    </ProjectConfiguration>
42
+    <ProjectConfiguration Include="Release|ARM64">
43
+      <Configuration>Release</Configuration>
44
+      <Platform>ARM64</Platform>
45
+    </ProjectConfiguration>
46
+    <ProjectConfiguration Include="Release|Win32">
47
+      <Configuration>Release</Configuration>
48
+      <Platform>Win32</Platform>
49
+    </ProjectConfiguration>
50
+    <ProjectConfiguration Include="Release|x64">
51
+      <Configuration>Release</Configuration>
52
+      <Platform>x64</Platform>
53
+    </ProjectConfiguration>
54
+  </ItemGroup>
55
+  <PropertyGroup Label="Configuration">
56
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
57
+    <PlatformToolset>v140</PlatformToolset>
58
+    <PlatformToolset Condition="'$(VisualStudioVersion)' == '15.0'">v141</PlatformToolset>
59
+    <PlatformToolset Condition="'$(VisualStudioVersion)' == '16.0'">v142</PlatformToolset>
60
+    <CharacterSet>Unicode</CharacterSet>
61
+    <GenerateManifest>false</GenerateManifest>
62
+  </PropertyGroup>
63
+  <PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
64
+    <UseDebugLibraries>true</UseDebugLibraries>
65
+    <LinkIncremental>true</LinkIncremental>
66
+  </PropertyGroup>
67
+  <PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">
68
+    <UseDebugLibraries>false</UseDebugLibraries>
69
+    <WholeProgramOptimization>true</WholeProgramOptimization>
70
+    <LinkIncremental>false</LinkIncremental>
71
+  </PropertyGroup>
72
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
73
+  <ImportGroup Label="ExtensionSettings">
74
+  </ImportGroup>
75
+  <ImportGroup Label="Shared">
76
+  </ImportGroup>
77
+  <ImportGroup Label="PropertySheets">
78
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
79
+  </ImportGroup>
80
+  <ImportGroup Label="PropertySheets">
81
+    <Import Project="PropertySheet.props" />
82
+  </ImportGroup>
83
+  <PropertyGroup Label="UserMacros" />
84
+  <PropertyGroup />
85
+  <ItemDefinitionGroup>
86
+    <ClCompile>
87
+      <PrecompiledHeader>Use</PrecompiledHeader>
88
+      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
89
+      <PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
90
+      <WarningLevel>Level4</WarningLevel>
91
+      <AdditionalOptions>%(AdditionalOptions) /bigobj</AdditionalOptions>
92
+      <!--Temporarily disable cppwinrt heap enforcement to work around xaml compiler generated std::shared_ptr use -->
93
+      <AdditionalOptions Condition="'$(CppWinRTHeapEnforcement)'==''">/DWINRT_NO_MAKE_DETECTION %(AdditionalOptions)</AdditionalOptions>
94
+      <DisableSpecificWarnings>
95
+      </DisableSpecificWarnings>
96
+      <PreprocessorDefinitions>_WINRT_DLL;WIN32_LEAN_AND_MEAN;WINRT_LEAN_AND_MEAN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
97
+      <AdditionalUsingDirectories>$(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>
98
+    </ClCompile>
99
+    <Link>
100
+      <SubSystem>Console</SubSystem>
101
+      <GenerateWindowsMetadata>false</GenerateWindowsMetadata>
102
+      <ModuleDefinitionFile>WebViewBridgeComponent.def</ModuleDefinitionFile>
103
+    </Link>
104
+  </ItemDefinitionGroup>
105
+  <ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
106
+    <ClCompile>
107
+      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
108
+    </ClCompile>
109
+  </ItemDefinitionGroup>
110
+  <ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
111
+    <ClCompile>
112
+      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
113
+    </ClCompile>
114
+    <Link>
115
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
116
+      <OptimizeReferences>true</OptimizeReferences>
117
+    </Link>
118
+  </ItemDefinitionGroup>
119
+  <ItemGroup>
120
+    <ClInclude Include="pch.h" />
121
+    <ClInclude Include="WebBridge.h">
122
+      <DependentUpon>WebBridge.idl</DependentUpon>
123
+    </ClInclude>
124
+  </ItemGroup>
125
+  <ItemGroup>
126
+    <ClCompile Include="pch.cpp">
127
+      <PrecompiledHeader>Create</PrecompiledHeader>
128
+    </ClCompile>
129
+    <ClCompile Include="WebBridge.cpp">
130
+      <DependentUpon>WebBridge.idl</DependentUpon>
131
+    </ClCompile>
132
+    <ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
133
+  </ItemGroup>
134
+  <ItemGroup>
135
+    <Midl Include="WebBridge.idl" />
136
+  </ItemGroup>
137
+  <ItemGroup>
138
+    <None Include="packages.config" />
139
+    <None Include="WebViewBridgeComponent.def" />
140
+  </ItemGroup>
141
+  <ItemGroup>
142
+    <None Include="PropertySheet.props" />
143
+    <Text Include="readme.txt">
144
+      <DeploymentContent>false</DeploymentContent>
145
+    </Text>
146
+  </ItemGroup>
147
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
148
+  <ImportGroup Label="ExtensionTargets">
149
+    <Import Project="$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.targets')" />
150
+  </ImportGroup>
151
+  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
152
+    <PropertyGroup>
153
+      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
154
+    </PropertyGroup>
155
+    <Error Condition="!Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.props'))" />
156
+    <Error Condition="!Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.targets'))" />
157
+  </Target>
158
+</Project>

+ 33
- 0
windows/WebViewBridgeComponent/WebViewBridgeComponent.vcxproj.filters Wyświetl plik

@@ -0,0 +1,33 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
+  <ItemGroup>
4
+    <Filter Include="Resources">
5
+      <UniqueIdentifier>accd3aa8-1ba0-4223-9bbe-0c431709210b</UniqueIdentifier>
6
+      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tga;tiff;tif;png;wav;mfcribbon-ms</Extensions>
7
+    </Filter>
8
+    <Filter Include="Generated Files">
9
+      <UniqueIdentifier>{926ab91d-31b4-48c3-b9a4-e681349f27f0}</UniqueIdentifier>
10
+    </Filter>
11
+  </ItemGroup>
12
+  <ItemGroup>
13
+    <ClCompile Include="pch.cpp" />
14
+    <ClCompile Include="WebBridge.cpp" />
15
+    <ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
16
+  </ItemGroup>
17
+  <ItemGroup>
18
+    <ClInclude Include="pch.h" />
19
+  </ItemGroup>
20
+  <ItemGroup>
21
+    <None Include="WebViewBridgeComponent.def" />
22
+    <None Include="packages.config" />
23
+  </ItemGroup>
24
+  <ItemGroup>
25
+    <None Include="PropertySheet.props" />
26
+  </ItemGroup>
27
+  <ItemGroup>
28
+    <Text Include="readme.txt" />
29
+  </ItemGroup>
30
+  <ItemGroup>
31
+    <Midl Include="WebBridge.idl" />
32
+  </ItemGroup>
33
+</Project>

+ 4
- 0
windows/WebViewBridgeComponent/packages.config Wyświetl plik

@@ -0,0 +1,4 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<packages>
3
+  <package id="Microsoft.Windows.CppWinRT" version="2.0.200729.8" targetFramework="native" />
4
+</packages>

+ 1
- 0
windows/WebViewBridgeComponent/pch.cpp Wyświetl plik

@@ -0,0 +1 @@
1
+#include "pch.h"

+ 4
- 0
windows/WebViewBridgeComponent/pch.h Wyświetl plik

@@ -0,0 +1,4 @@
1
+#pragma once
2
+#include <unknwn.h>
3
+#include <winrt/Windows.Foundation.h>
4
+#include <winrt/Windows.Foundation.Collections.h>

+ 23
- 0
windows/WebViewBridgeComponent/readme.txt Wyświetl plik

@@ -0,0 +1,23 @@
1
+========================================================================
2
+    C++/WinRT WebViewBridgeComponent Project Overview
3
+========================================================================
4
+
5
+This project demonstrates how to get started authoring Windows Runtime 
6
+classes directly with standard C++, using the C++/WinRT SDK component 
7
+to generate implementation headers from interface (IDL) files.  The
8
+generated Windows Runtime component binary and WinMD files should then
9
+be bundled with the Universal Windows Platform (UWP) app consuming them.
10
+
11
+Steps:
12
+1. Create an interface (IDL) file to define your Windows Runtime class, 
13
+    its default interface, and any other interfaces it implements.
14
+2. Build the project once to generate module.g.cpp, module.h.cpp, and
15
+    implementation templates under the "Generated Files" folder, as 
16
+    well as skeleton class definitions under "Generated Files\sources".  
17
+3. Use the skeleton class definitions for reference to implement your
18
+    Windows Runtime classes.
19
+
20
+========================================================================
21
+Learn more about C++/WinRT here:
22
+http://aka.ms/cppwinrt/
23
+========================================================================

+ 1369
- 1341
yarn.lock
Plik diff jest za duży
Wyświetl plik