Browse Source

Merge branch 'master' into android-permissions

Thibaud Michel 4 years ago
parent
commit
72dd8dd077
No account linked to committer's email address

+ 1
- 1
.circleci/config.yml View File

34
             - node_modules-{{ arch }}-{{ checksum "yarn.lock" }}
34
             - node_modules-{{ arch }}-{{ checksum "yarn.lock" }}
35
 
35
 
36
       - run:
36
       - run:
37
-          name: Run Tests
37
+          name: Lint checks
38
           command: yarn ci
38
           command: yarn ci
39
 
39
 
40
   publish:
40
   publish:

+ 1
- 1
.github/workflows/detox.yml View File

1
 name: 'Detox CI Tests'
1
 name: 'Detox CI Tests'
2
-on: [push]
2
+on: [pull_request]
3
 
3
 
4
 jobs:
4
 jobs:
5
   tests:
5
   tests:

+ 108
- 0
.github/workflows/scripts/install-vs-features.ps1 View File

1
+param (
2
+	[Parameter(Mandatory=$true)]
3
+	[string[]] $Components,
4
+
5
+	[uri] $InstallerUri = "https://download.visualstudio.microsoft.com/download/pr/c4fef23e-cc45-4836-9544-70e213134bc8/1ee5717e9a1e05015756dff77eb27d554a79a6db91f2716d836df368381af9a1/vs_Enterprise.exe",
6
+
7
+	[string] $VsInstaller = "${env:System_DefaultWorkingDirectory}\vs_Enterprise.exe",
8
+
9
+	[string] $VsInstallOutputDir = "${env:System_DefaultWorkingDirectory}\vs",
10
+
11
+	[System.IO.FileInfo] $VsInstallPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\Enterprise",
12
+
13
+	[System.IO.FileInfo] $VsInstallerPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer",
14
+
15
+	[switch] $Collect = $false,
16
+
17
+	[switch] $Cleanup = $false,
18
+
19
+	[switch] $UseWebInstaller = $false
20
+)
21
+
22
+$Components | ForEach-Object {
23
+	$componentList += '--add', $_
24
+}
25
+
26
+$LocalVsInstaller = "$VsInstallerPath\vs_installershell.exe"
27
+
28
+$UseWebInstaller = $UseWebInstaller -or -not (Test-Path -Path "$LocalVsInstaller")
29
+
30
+if ($UseWebInstaller) {
31
+	Write-Host "Downloading web installer..."
32
+
33
+	Invoke-WebRequest -Method Get `
34
+		-Uri $InstallerUri `
35
+		-OutFile $VsInstaller
36
+
37
+	New-Item -ItemType directory -Path $VsInstallOutputDir
38
+
39
+	Write-Host "Running web installer to download requested components..."
40
+
41
+	Start-Process `
42
+		-FilePath "$VsInstaller" `
43
+		-ArgumentList ( `
44
+			'--layout', "$VsInstallOutputDir",
45
+			'--wait',
46
+			'--norestart',
47
+			'--quiet' + `
48
+			$componentList
49
+		) `
50
+		-Wait `
51
+		-PassThru
52
+
53
+	Write-Host "Running downloaded VS installer to add requested components..."
54
+
55
+	Start-Process `
56
+		-FilePath "$VsInstallOutputDir\vs_Enterprise.exe" `
57
+		-ArgumentList (
58
+			'modify',
59
+			'--installPath', "`"$VsInstallPath`"" ,
60
+			'--wait',
61
+			'--norestart',
62
+			'--quiet' + `
63
+			$componentList
64
+		) `
65
+		-Wait `
66
+		-PassThru `
67
+		-OutVariable returnCode
68
+
69
+	if ($Cleanup) {
70
+		Write-Host "Cleaning up..."
71
+
72
+		Remove-Item -Path $VsInstaller
73
+		Remove-Item -Path $VsInstallOutputDir -Recurse
74
+	}
75
+	
76
+} else {
77
+	Write-Host "Running local installer to add requested components..."
78
+
79
+	Start-Process `
80
+		-FilePath "$LocalVsInstaller" `
81
+		-ArgumentList (
82
+			'modify',
83
+			'--installPath', "`"$VsInstallPath`"" ,
84
+			'--norestart',
85
+			'--quiet' + `
86
+			$componentList
87
+		) `
88
+		-Wait `
89
+		-OutVariable returnCode
90
+}
91
+
92
+if ($Collect) {
93
+	Invoke-WebRequest -Method Get `
94
+		-Uri 'https://download.microsoft.com/download/8/3/4/834E83F6-C377-4DCE-A757-69A418B6C6DF/Collect.exe' `
95
+		-OutFile ${env:System_DefaultWorkingDirectory}\Collect.exe
96
+
97
+	# Should generate ${env:Temp}\vslogs.zip
98
+	Start-Process `
99
+		-FilePath "${env:System_DefaultWorkingDirectory}\Collect.exe" `
100
+		-Wait `
101
+		-PassThru
102
+
103
+	New-Item -ItemType Directory -Force ${env:System_DefaultWorkingDirectory}\vslogs
104
+	Expand-Archive -Path ${env:TEMP}\vslogs.zip -DestinationPath ${env:System_DefaultWorkingDirectory}\vslogs\
105
+
106
+	Write-Host "VC versions after installation:"
107
+	Get-ChildItem -Name "$VsInstallPath\VC\Tools\MSVC\"
108
+}

+ 67
- 0
.github/workflows/windows-ci.yml View File

1
+name: Windows CI
2
+on: [pull_request]
3
+
4
+jobs:
5
+  run-windows-tests:
6
+    name: Build & run tests
7
+    runs-on: windows-2019
8
+
9
+    steps:
10
+    - uses: actions/checkout@v2
11
+      name: Checkout Code
12
+     
13
+    - name: Setup Node.js
14
+      uses: actions/setup-node@v1
15
+      with:
16
+        node-version: '12.9.1'
17
+
18
+    - name: Install Visual Studio components
19
+      shell: powershell
20
+      run: .\.github\workflows\scripts\install-vs-features.ps1 Microsoft.VisualStudio.Component.VC.v141.x86.x64,Microsoft.VisualStudio.ComponentGroup.UWP.VC.v141
21
+
22
+    - name: Setup MSBuild
23
+      uses: microsoft/setup-msbuild@v1.0.0
24
+      with:
25
+        vs-version: 16.5
26
+       
27
+    - name: Setup NuGet
28
+      uses: NuGet/setup-nuget@v1.0.2
29
+
30
+    - name: Check node modules cache
31
+      uses: actions/cache@v1
32
+      id: yarn-cache
33
+      with:
34
+        path: ./node_modules
35
+        key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
36
+        restore-keys: |
37
+          ${{ runner.os }}-yarn-
38
+
39
+    - name: Install node modules
40
+      if: steps.yarn-cache.outputs.cache-hit != 'true'
41
+      run: yarn --pure-lockfile
42
+    
43
+    - name: yarn build
44
+      if: steps.yarn-cache.outputs.cache-hit == 'true'
45
+      run: |
46
+        yarn build
47
+        yarn tsc
48
+ 
49
+    - name: NuGet restore
50
+      run: nuget restore example\windows\WebViewWindows.sln
51
+
52
+    - name: Build x64 release
53
+      run: msbuild example\windows\WebViewWindows.sln /p:Configuration=Release /p:Platform=x64 -m
54
+
55
+    - name: Deploy
56
+      shell: powershell
57
+      run: |
58
+        cd example
59
+        Copy-Item -Path windows\x64\Release -Recurse -Destination windows\
60
+        npx react-native run-windows --arch x64 --release --no-build --no-packager
61
+
62
+    - name: Start Appium server
63
+      shell: powershell
64
+      run: Start-Process PowerShell -ArgumentList "yarn appium"
65
+      
66
+    - name: Run tests
67
+      run: yarn test:windows

+ 2
- 0
.gitignore View File

57
 .classpath
57
 .classpath
58
 .project
58
 .project
59
 .settings/
59
 .settings/
60
+msbuild.binlog
61
+example/msbuild.binlog

+ 31
- 0
__tests__/Alert.test.js View File

1
+/**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+import { driver, By2 } from 'selenium-appium'
7
+import { until } from 'selenium-webdriver';
8
+
9
+const setup = require('../jest-setups/jest.setup');
10
+jest.setTimeout(50000);
11
+
12
+beforeAll(() => {
13
+  return driver.startWithCapabilities(setup.capabilites);
14
+});
15
+
16
+afterAll(() => {
17
+  return driver.quit();
18
+});
19
+
20
+describe('Alert Tests', () => {
21
+  
22
+  test('Show Alert', async () => {
23
+    const showAlertButton = await driver.wait(until.elementLocated(By2.nativeName('Show alert')));
24
+    await showAlertButton.click();
25
+    await driver.wait(until.elementLocated(By2.nativeName('Hello! I am an alert box!')));
26
+    await By2.nativeName('OK').click();
27
+    const dismissMessage = await driver.wait(until.elementLocated(By2.nativeName('Alert dismissed!')));
28
+    expect(dismissMessage).not.toBeNull();
29
+  });
30
+
31
+});

+ 1
- 1
docs/Guide.md View File

55
 
55
 
56
 ### Loading local HTML files
56
 ### Loading local HTML files
57
 
57
 
58
-Sometimes you would have bundled an HTML file along with the app and would like to load the HTML asset into your WebView. To do this on iOS, you can just import the html file like any other asset as shown below.
58
+Sometimes you would have bundled an HTML file along with the app and would like to load the HTML asset into your WebView. To do this on iOS and Windows, you can just import the html file like any other asset as shown below.
59
 
59
 
60
 ```js
60
 ```js
61
 import React, { Component } from 'react';
61
 import React, { Component } from 'react';

+ 14
- 0
example/App.tsx View File

16
 import Downloads from './examples/Downloads';
16
 import Downloads from './examples/Downloads';
17
 import Uploads from './examples/Uploads';
17
 import Uploads from './examples/Uploads';
18
 import Injection from './examples/Injection';
18
 import Injection from './examples/Injection';
19
+import LocalPageLoad from './examples/LocalPageLoad';
19
 
20
 
20
 const TESTS = {
21
 const TESTS = {
21
   Alerts: {
22
   Alerts: {
66
       return <Injection />;
67
       return <Injection />;
67
     },
68
     },
68
   },
69
   },
70
+  PageLoad: {
71
+    title: 'LocalPageLoad',
72
+    testId: 'LocalPageLoad',
73
+    description: 'Local Page load test',
74
+    render() {
75
+      return <LocalPageLoad />;
76
+    },
77
+  },
69
 };
78
 };
70
 
79
 
71
 type Props = {};
80
 type Props = {};
124
             title="Injection"
133
             title="Injection"
125
             onPress={() => this._changeTest('Injection')}
134
             onPress={() => this._changeTest('Injection')}
126
           />
135
           />
136
+          <Button
137
+            testID="testType_pageLoad"
138
+            title="LocalPageLoad"
139
+            onPress={() => this._changeTest('PageLoad')}
140
+          />
127
           {Platform.OS == "ios" && <Button
141
           {Platform.OS == "ios" && <Button
128
             testID="testType_downloads"
142
             testID="testType_downloads"
129
             title="Downloads"
143
             title="Downloads"

+ 9
- 0
example/assets/test.html View File

1
+<!doctype html>
2
+<html>
3
+    <head>
4
+        <title>Test</title>
5
+    </head>
6
+    <body>
7
+        <h2>Local page test</h2>
8
+    </body>
9
+</html>

+ 16
- 0
example/examples/LocalPageLoad.tsx View File

1
+import React, {Component} from 'react';
2
+import {View, Text, Alert, TextInput, Button} from 'react-native';
3
+import WebView from 'react-native-webview';
4
+const localHtmlFile = require('../assets/test.html');
5
+
6
+export default class LocalPageLoad extends Component<Props, State> {
7
+    render() {
8
+      return (
9
+        <View>
10
+            <View style={{ width: '100%', height: '100%' }}>
11
+                <WebView source={localHtmlFile}/>
12
+          </View>
13
+        </View>
14
+      );
15
+    }
16
+  }

+ 1
- 0
example/windows/.gitignore View File

1
 *AppPackages*
1
 *AppPackages*
2
 *BundleArtifacts*
2
 *BundleArtifacts*
3
+*Bundle
3
 
4
 
4
 #OS junk files
5
 #OS junk files
5
 [Tt]humbs.db
6
 [Tt]humbs.db

+ 1
- 1
example/windows/WebViewWindows/Package.appxmanifest View File

7
   IgnorableNamespaces="uap mp">
7
   IgnorableNamespaces="uap mp">
8
 
8
 
9
  <Identity
9
  <Identity
10
-    Name="6b4ef5e9-85c1-4006-87d7-77c61c62f84f"
10
+    Name="WebViewWindows"
11
     Publisher="CN=kaigu"
11
     Publisher="CN=kaigu"
12
     Version="1.0.0.0" />
12
     Version="1.0.0.0" />
13
 
13
 

+ 4
- 2
example/windows/WebViewWindows/WebViewWindows.vcxproj View File

18
     <PackageCertificateKeyFile>WebViewWindows_TemporaryKey.pfx</PackageCertificateKeyFile>
18
     <PackageCertificateKeyFile>WebViewWindows_TemporaryKey.pfx</PackageCertificateKeyFile>
19
     <PackageCertificateThumbprint>82A0D300B0912A62746FFB3E6E04F88985BC2798</PackageCertificateThumbprint>
19
     <PackageCertificateThumbprint>82A0D300B0912A62746FFB3E6E04F88985BC2798</PackageCertificateThumbprint>
20
     <PackageCertificatePassword>password</PackageCertificatePassword>
20
     <PackageCertificatePassword>password</PackageCertificatePassword>
21
+    <AppxPackageSigningEnabled>true</AppxPackageSigningEnabled>
21
   </PropertyGroup>
22
   </PropertyGroup>
22
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
23
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
23
   <ItemGroup Label="ProjectConfigurations">
24
   <ItemGroup Label="ProjectConfigurations">
145
   <ItemGroup>
146
   <ItemGroup>
146
     <None Include="packages.config" />
147
     <None Include="packages.config" />
147
     <None Include="PropertySheet.props" />
148
     <None Include="PropertySheet.props" />
149
+    <None Include="WebViewWindows_TemporaryKey.pfx" />
148
     <Text Include="readme.txt">
150
     <Text Include="readme.txt">
149
       <DeploymentContent>false</DeploymentContent>
151
       <DeploymentContent>false</DeploymentContent>
150
     </Text>
152
     </Text>
160
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
162
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
161
   <PropertyGroup>
163
   <PropertyGroup>
162
     <BundleCommand>
164
     <BundleCommand>
163
-      cd $(SolutionDir)..
164
-      react-native bundle --platform windows --entry-file example/index.js --bundle-output windows/$(SolutionName)/Bundle/index.windows.bundle --assets-dest windows/$(SolutionName)/Bundle
165
+      cd $(SolutionDir)..\..
166
+      npx react-native bundle --platform windows --entry-file example/index.js --bundle-output example/windows/WebViewWindows/Bundle/index.windows.bundle --assets-dest example/windows/WebViewWindows/Bundle --use-react-native-windows
165
     </BundleCommand>
167
     </BundleCommand>
166
   </PropertyGroup>
168
   </PropertyGroup>
167
   <Import Project="..\..\..\node_modules\react-native-windows\PropertySheets\Bundle.Cpp.targets" />
169
   <Import Project="..\..\..\node_modules\react-native-windows\PropertySheets\Bundle.Cpp.targets" />

+ 1
- 0
example/windows/WebViewWindows/WebViewWindows.vcxproj.filters View File

51
   <ItemGroup>
51
   <ItemGroup>
52
     <None Include="PropertySheet.props" />
52
     <None Include="PropertySheet.props" />
53
     <None Include="packages.config" />
53
     <None Include="packages.config" />
54
+    <None Include="WebViewWindows_TemporaryKey.pfx" />
54
   </ItemGroup>
55
   </ItemGroup>
55
   <ItemGroup>
56
   <ItemGroup>
56
     <Text Include="readme.txt" />
57
     <Text Include="readme.txt" />

+ 12
- 0
jest-setups/jest.setup.js View File

1
+import { windowsAppDriverCapabilities } from 'selenium-appium'
2
+
3
+switch (platform) {
4
+    case "windows":
5
+        const webViewWindowsAppId = 'WebViewWindows_3x6rhkkr9xcf6!App';
6
+        module.exports = {
7
+            capabilites: windowsAppDriverCapabilities(webViewWindowsAppId)
8
+        }
9
+        break;
10
+    default:
11
+        throw "Unknown platform: " + platform;
12
+}

+ 1
- 0
jest-setups/jest.setup.windows.js View File

1
+platform = "windows"

+ 11
- 7
package.json View File

16
     "start:ios": "react-native run-ios --project-path example/ios --scheme example",
16
     "start:ios": "react-native run-ios --project-path example/ios --scheme example",
17
     "start:macos": "node node_modules/react-native-macos/local-cli/cli.js start --use-react-native-macos",
17
     "start:macos": "node node_modules/react-native-macos/local-cli/cli.js start --use-react-native-macos",
18
     "start:windows": "react-native start --use-react-native-windows",
18
     "start:windows": "react-native start --use-react-native-windows",
19
-    "ci": "CI=true && yarn lint && yarn test",
19
+    "ci": "CI=true && yarn lint",
20
     "ci:publish": "yarn semantic-release",
20
     "ci:publish": "yarn semantic-release",
21
     "lint": "yarn tsc --noEmit && yarn eslint ./src --ext .ts,.tsx",
21
     "lint": "yarn tsc --noEmit && yarn eslint ./src --ext .ts,.tsx",
22
     "build": "yarn tsc",
22
     "build": "yarn tsc",
23
     "prepare": "yarn build",
23
     "prepare": "yarn build",
24
-    "test": "yarn jest"
24
+    "appium": "appium",
25
+    "test:windows": "yarn jest --setupFiles=./jest-setups/jest.setup.windows.js"
25
   },
26
   },
26
   "rn-docs": {
27
   "rn-docs": {
27
     "title": "Webview",
28
     "title": "Webview",
29
   },
30
   },
30
   "peerDependencies": {
31
   "peerDependencies": {
31
     "react": "^16.9",
32
     "react": "^16.9",
32
-    "react-native": ">=0.60 <0.62",
33
-    "react-native-windows": "^0.61.0-beta.58"
33
+    "react-native": ">=0.60 <0.62"
34
   },
34
   },
35
   "dependencies": {
35
   "dependencies": {
36
     "escape-string-regexp": "2.0.0",
36
     "escape-string-regexp": "2.0.0",
47
     "@types/jest": "24.0.18",
47
     "@types/jest": "24.0.18",
48
     "@types/react": "16.8.8",
48
     "@types/react": "16.8.8",
49
     "@types/react-native": "0.60.11",
49
     "@types/react-native": "0.60.11",
50
+    "@types/selenium-webdriver": "4.0.9",
50
     "@typescript-eslint/eslint-plugin": "2.1.0",
51
     "@typescript-eslint/eslint-plugin": "2.1.0",
51
     "@typescript-eslint/parser": "2.1.0",
52
     "@typescript-eslint/parser": "2.1.0",
52
     "babel-eslint": "10.0.3",
53
     "babel-eslint": "10.0.3",
60
     "eslint-plugin-react": "7.14.3",
61
     "eslint-plugin-react": "7.14.3",
61
     "eslint-plugin-react-native": "3.7.0",
62
     "eslint-plugin-react-native": "3.7.0",
62
     "jest": "24.9.0",
63
     "jest": "24.9.0",
64
+    "metro": "0.56.4",
63
     "metro-react-native-babel-preset": "0.54.1",
65
     "metro-react-native-babel-preset": "0.54.1",
64
     "react": "16.9.0",
66
     "react": "16.9.0",
65
     "react-native": "0.61.5",
67
     "react-native": "0.61.5",
66
     "react-native-macos": "0.60.0-microsoft.73",
68
     "react-native-macos": "0.60.0-microsoft.73",
67
-    "react-native-windows": "^0.61.0-beta.58",
68
-    "rnpm-plugin-windows": "^0.5.1-0",
69
+    "react-native-windows": "0.61.5",
69
     "semantic-release": "15.13.24",
70
     "semantic-release": "15.13.24",
70
-    "typescript": "3.6.2"
71
+    "typescript": "3.6.2",
72
+    "appium": "1.17.0",
73
+    "selenium-appium": "0.0.15",
74
+    "selenium-webdriver": "4.0.0-alpha.7"
71
   },
75
   },
72
   "repository": {
76
   "repository": {
73
     "type": "git",
77
     "type": "git",

+ 15
- 15
windows/ReactNativeWebView/ReactWebView.cpp View File

97
                 eventDataWriter.WriteObjectEnd();
97
                 eventDataWriter.WriteObjectEnd();
98
             });
98
             });
99
 
99
 
100
-        winrt::hstring windowAlert = L"window.alert = function (msg) {window.external.notify(`{\"type\":\"alert\",\"message\":\"${msg}\"}`)};";
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))}};";
101
         winrt::hstring postMessage = L"window.ReactNativeWebView = {postMessage: function (data) {window.external.notify(String(data))}};";
102
         m_webView.InvokeScriptAsync(L"eval", { windowAlert + postMessage });
102
         m_webView.InvokeScriptAsync(L"eval", { windowAlert + postMessage });
103
     }
103
     }
119
 
119
 
120
     void ReactWebView::OnScriptNotify(winrt::IInspectable const& /*sender*/, winrt::Windows::UI::Xaml::Controls::NotifyEventArgs const& args) {
120
     void ReactWebView::OnScriptNotify(winrt::IInspectable const& /*sender*/, winrt::Windows::UI::Xaml::Controls::NotifyEventArgs const& args) {
121
         winrt::JsonObject jsonObject;
121
         winrt::JsonObject jsonObject;
122
-        if (winrt::JsonObject::TryParse(args.Value(), jsonObject)) {
122
+        if (winrt::JsonObject::TryParse(args.Value(), jsonObject) && jsonObject.HasKey(L"type")) {
123
             auto type = jsonObject.GetNamedString(L"type");
123
             auto type = jsonObject.GetNamedString(L"type");
124
-            if (type == L"alert") {
124
+            if (type == L"__alert") {
125
                 auto dialog = winrt::MessageDialog(jsonObject.GetNamedString(L"message"));
125
                 auto dialog = winrt::MessageDialog(jsonObject.GetNamedString(L"message"));
126
                 dialog.Commands().Append(winrt::UICommand(L"OK"));
126
                 dialog.Commands().Append(winrt::UICommand(L"OK"));
127
                 dialog.ShowAsync();
127
                 dialog.ShowAsync();
128
+                return;
128
             }
129
             }
129
         }
130
         }
130
-        else {
131
-            m_reactContext.DispatchEvent(
132
-                m_webView,
133
-                L"topMessage",
134
-                [&](winrt::Microsoft::ReactNative::IJSValueWriter const& eventDataWriter) noexcept {
135
-                    eventDataWriter.WriteObjectBegin();
136
-                    {
137
-                        WriteProperty(eventDataWriter, L"data", winrt::to_string(args.Value()));
138
-                    }
139
-                    eventDataWriter.WriteObjectEnd();
140
-                });
141
-        }
131
+
132
+        m_reactContext.DispatchEvent(
133
+            m_webView,
134
+            L"topMessage",
135
+            [&](winrt::Microsoft::ReactNative::IJSValueWriter const& eventDataWriter) noexcept {
136
+                eventDataWriter.WriteObjectBegin();
137
+                {
138
+                    WriteProperty(eventDataWriter, L"data", winrt::to_string(args.Value()));
139
+                }
140
+                eventDataWriter.WriteObjectEnd();
141
+            });
142
     }
142
     }
143
 
143
 
144
 } // namespace winrt::ReactNativeWebView::implementation
144
 } // namespace winrt::ReactNativeWebView::implementation

+ 9
- 9
windows/ReactNativeWebView/ReactWebViewManager.cpp View File

58
                     auto const& srcMap = propertyValue.AsObject();
58
                     auto const& srcMap = propertyValue.AsObject();
59
                     if (srcMap.find("uri") != srcMap.end()) {
59
                     if (srcMap.find("uri") != srcMap.end()) {
60
                         auto uriString = srcMap.at("uri").AsString();
60
                         auto uriString = srcMap.at("uri").AsString();
61
-                        // non-uri sources not yet supported
62
                         if (uriString.length() == 0) {
61
                         if (uriString.length() == 0) {
63
                             continue;
62
                             continue;
64
                         }
63
                         }
67
                         if (srcMap.find("__packager_asset") != srcMap.end()) {
66
                         if (srcMap.find("__packager_asset") != srcMap.end()) {
68
                             isPackagerAsset = srcMap.at("__packager_asset").AsBoolean();
67
                             isPackagerAsset = srcMap.at("__packager_asset").AsBoolean();
69
                         }
68
                         }
70
-
71
-                        if (isPackagerAsset && uriString.find("assets") == 0) {
72
-                            uriString.replace(0, 6, "ms-appx://");
69
+                        if (isPackagerAsset && uriString.find("file://") == 0) {
70
+                            auto bundleRootPath = winrt::to_string(ReactNativeHost().InstanceSettings().BundleRootPath());
71
+                            uriString.replace(0, 7, bundleRootPath.empty() ? "ms-appx-web:///Bundle/" : bundleRootPath);
73
                         }
72
                         }
74
 
73
 
75
                         webView.Navigate(winrt::Uri(to_hstring(uriString)));
74
                         webView.Navigate(winrt::Uri(to_hstring(uriString)));
94
 
93
 
95
     ConstantProviderDelegate ReactWebViewManager::ExportedCustomDirectEventTypeConstants() noexcept {
94
     ConstantProviderDelegate ReactWebViewManager::ExportedCustomDirectEventTypeConstants() noexcept {
96
         return [](winrt::IJSValueWriter const& constantWriter) {
95
         return [](winrt::IJSValueWriter const& constantWriter) {
97
-            WriteCustomDirectEventTypeConstant(constantWriter, "onLoadingStart");
98
-            WriteCustomDirectEventTypeConstant(constantWriter, "onLoadingFinish");
99
-            WriteCustomDirectEventTypeConstant(constantWriter, "onLoadingError");
100
-            WriteCustomDirectEventTypeConstant(constantWriter, "onMessage");
96
+            WriteCustomDirectEventTypeConstant(constantWriter, "LoadingStart");
97
+            WriteCustomDirectEventTypeConstant(constantWriter, "LoadingFinish");
98
+            WriteCustomDirectEventTypeConstant(constantWriter, "LoadingError");
99
+            WriteCustomDirectEventTypeConstant(constantWriter, "Message");
101
         };
100
         };
102
     }
101
     }
103
 
102
 
116
         FrameworkElement const& view,
115
         FrameworkElement const& view,
117
         int64_t commandId,
116
         int64_t commandId,
118
         winrt::IJSValueReader const& commandArgsReader) noexcept {
117
         winrt::IJSValueReader const& commandArgsReader) noexcept {
118
+        auto commandArgs = JSValue::ReadArrayFrom(commandArgsReader);
119
         if (auto webView = view.try_as<winrt::WebView>()) {
119
         if (auto webView = view.try_as<winrt::WebView>()) {
120
             switch (commandId) {
120
             switch (commandId) {
121
                 case static_cast<int64_t>(WebViewCommands::GoForward) :
121
                 case static_cast<int64_t>(WebViewCommands::GoForward) :
135
                     webView.Stop();
135
                     webView.Stop();
136
                     break;
136
                     break;
137
                 case static_cast<int64_t>(WebViewCommands::InjectJavaScript) :
137
                 case static_cast<int64_t>(WebViewCommands::InjectJavaScript) :
138
-                    webView.InvokeScriptAsync(L"eval", { commandArgsReader.GetString() });
138
+                    webView.InvokeScriptAsync(L"eval", { winrt::to_hstring(commandArgs[0].AsString()) });
139
                     break;
139
                     break;
140
             }
140
             }
141
         }
141
         }

+ 5357
- 1499
yarn.lock
File diff suppressed because it is too large
View File