fix(windows): Fix windows local asset path (#1335 by @kaiguo)
[skip ci]
This commit is contained in:
parent
ef3ceb24d1
commit
20a3f90c0f
|
@ -55,7 +55,7 @@ class MyWeb extends Component {
|
||||||
|
|
||||||
### Loading local HTML files
|
### Loading local HTML files
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
|
|
|
@ -16,6 +16,7 @@ import Background from './examples/Background';
|
||||||
import Downloads from './examples/Downloads';
|
import Downloads from './examples/Downloads';
|
||||||
import Uploads from './examples/Uploads';
|
import Uploads from './examples/Uploads';
|
||||||
import Injection from './examples/Injection';
|
import Injection from './examples/Injection';
|
||||||
|
import LocalPageLoad from './examples/LocalPageLoad';
|
||||||
|
|
||||||
const TESTS = {
|
const TESTS = {
|
||||||
Alerts: {
|
Alerts: {
|
||||||
|
@ -66,6 +67,14 @@ const TESTS = {
|
||||||
return <Injection />;
|
return <Injection />;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
PageLoad: {
|
||||||
|
title: 'LocalPageLoad',
|
||||||
|
testId: 'LocalPageLoad',
|
||||||
|
description: 'Local Page load test',
|
||||||
|
render() {
|
||||||
|
return <LocalPageLoad />;
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
type Props = {};
|
type Props = {};
|
||||||
|
@ -124,6 +133,11 @@ export default class App extends Component<Props, State> {
|
||||||
title="Injection"
|
title="Injection"
|
||||||
onPress={() => this._changeTest('Injection')}
|
onPress={() => this._changeTest('Injection')}
|
||||||
/>
|
/>
|
||||||
|
<Button
|
||||||
|
testID="testType_pageLoad"
|
||||||
|
title="LocalPageLoad"
|
||||||
|
onPress={() => this._changeTest('PageLoad')}
|
||||||
|
/>
|
||||||
{Platform.OS == "ios" && <Button
|
{Platform.OS == "ios" && <Button
|
||||||
testID="testType_downloads"
|
testID="testType_downloads"
|
||||||
title="Downloads"
|
title="Downloads"
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Test</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h2>Local page test</h2>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,16 @@
|
||||||
|
import React, {Component} from 'react';
|
||||||
|
import {View, Text, Alert, TextInput, Button} from 'react-native';
|
||||||
|
import WebView from 'react-native-webview';
|
||||||
|
const localHtmlFile = require('../assets/test.html');
|
||||||
|
|
||||||
|
export default class LocalPageLoad extends Component<Props, State> {
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<View style={{ width: '100%', height: '100%' }}>
|
||||||
|
<WebView source={localHtmlFile}/>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -58,7 +58,6 @@ namespace winrt::ReactNativeWebView::implementation {
|
||||||
auto const& srcMap = propertyValue.AsObject();
|
auto const& srcMap = propertyValue.AsObject();
|
||||||
if (srcMap.find("uri") != srcMap.end()) {
|
if (srcMap.find("uri") != srcMap.end()) {
|
||||||
auto uriString = srcMap.at("uri").AsString();
|
auto uriString = srcMap.at("uri").AsString();
|
||||||
// non-uri sources not yet supported
|
|
||||||
if (uriString.length() == 0) {
|
if (uriString.length() == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -67,9 +66,9 @@ namespace winrt::ReactNativeWebView::implementation {
|
||||||
if (srcMap.find("__packager_asset") != srcMap.end()) {
|
if (srcMap.find("__packager_asset") != srcMap.end()) {
|
||||||
isPackagerAsset = srcMap.at("__packager_asset").AsBoolean();
|
isPackagerAsset = srcMap.at("__packager_asset").AsBoolean();
|
||||||
}
|
}
|
||||||
|
if (isPackagerAsset && uriString.find("file://") == 0) {
|
||||||
if (isPackagerAsset && uriString.find("assets") == 0) {
|
auto bundleRootPath = winrt::to_string(ReactNativeHost().InstanceSettings().BundleRootPath());
|
||||||
uriString.replace(0, 6, "ms-appx://");
|
uriString.replace(0, 7, bundleRootPath.empty() ? "ms-appx-web:///Bundle/" : bundleRootPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
webView.Navigate(winrt::Uri(to_hstring(uriString)));
|
webView.Navigate(winrt::Uri(to_hstring(uriString)));
|
||||||
|
@ -94,10 +93,10 @@ namespace winrt::ReactNativeWebView::implementation {
|
||||||
|
|
||||||
ConstantProviderDelegate ReactWebViewManager::ExportedCustomDirectEventTypeConstants() noexcept {
|
ConstantProviderDelegate ReactWebViewManager::ExportedCustomDirectEventTypeConstants() noexcept {
|
||||||
return [](winrt::IJSValueWriter const& constantWriter) {
|
return [](winrt::IJSValueWriter const& constantWriter) {
|
||||||
WriteCustomDirectEventTypeConstant(constantWriter, "onLoadingStart");
|
WriteCustomDirectEventTypeConstant(constantWriter, "LoadingStart");
|
||||||
WriteCustomDirectEventTypeConstant(constantWriter, "onLoadingFinish");
|
WriteCustomDirectEventTypeConstant(constantWriter, "LoadingFinish");
|
||||||
WriteCustomDirectEventTypeConstant(constantWriter, "onLoadingError");
|
WriteCustomDirectEventTypeConstant(constantWriter, "LoadingError");
|
||||||
WriteCustomDirectEventTypeConstant(constantWriter, "onMessage");
|
WriteCustomDirectEventTypeConstant(constantWriter, "Message");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
36
yarn.lock
36
yarn.lock
|
@ -5233,7 +5233,7 @@ debug@^3.1.0, debug@^3.2.6:
|
||||||
dependencies:
|
dependencies:
|
||||||
ms "^2.1.1"
|
ms "^2.1.1"
|
||||||
|
|
||||||
debuglog@*, debuglog@^1.0.1:
|
debuglog@^1.0.1:
|
||||||
version "1.0.1"
|
version "1.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492"
|
resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492"
|
||||||
integrity sha1-qiT/uaw9+aI1GDfPstJ5NgzXhJI=
|
integrity sha1-qiT/uaw9+aI1GDfPstJ5NgzXhJI=
|
||||||
|
@ -7225,7 +7225,7 @@ import-local@^2.0.0:
|
||||||
pkg-dir "^3.0.0"
|
pkg-dir "^3.0.0"
|
||||||
resolve-cwd "^2.0.0"
|
resolve-cwd "^2.0.0"
|
||||||
|
|
||||||
imurmurhash@*, imurmurhash@^0.1.4:
|
imurmurhash@^0.1.4:
|
||||||
version "0.1.4"
|
version "0.1.4"
|
||||||
resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"
|
resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"
|
||||||
integrity sha1-khi5srkoojixPcT7a21XbyMUU+o=
|
integrity sha1-khi5srkoojixPcT7a21XbyMUU+o=
|
||||||
|
@ -8733,11 +8733,6 @@ lockfile@^1.0.4:
|
||||||
dependencies:
|
dependencies:
|
||||||
signal-exit "^3.0.2"
|
signal-exit "^3.0.2"
|
||||||
|
|
||||||
lodash._baseindexof@*:
|
|
||||||
version "3.1.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c"
|
|
||||||
integrity sha1-/lK1OhxnYeQmGNZU5KJXie1hgiw=
|
|
||||||
|
|
||||||
lodash._baseuniq@~4.6.0:
|
lodash._baseuniq@~4.6.0:
|
||||||
version "4.6.0"
|
version "4.6.0"
|
||||||
resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8"
|
resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8"
|
||||||
|
@ -8746,33 +8741,11 @@ lodash._baseuniq@~4.6.0:
|
||||||
lodash._createset "~4.0.0"
|
lodash._createset "~4.0.0"
|
||||||
lodash._root "~3.0.0"
|
lodash._root "~3.0.0"
|
||||||
|
|
||||||
lodash._bindcallback@*:
|
|
||||||
version "3.0.1"
|
|
||||||
resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e"
|
|
||||||
integrity sha1-5THCdkTPi1epnhftlbNcdIeJOS4=
|
|
||||||
|
|
||||||
lodash._cacheindexof@*:
|
|
||||||
version "3.0.2"
|
|
||||||
resolved "https://registry.yarnpkg.com/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92"
|
|
||||||
integrity sha1-PcaayCSY0u5ePOVgkbr9Ktx73pI=
|
|
||||||
|
|
||||||
lodash._createcache@*:
|
|
||||||
version "3.1.2"
|
|
||||||
resolved "https://registry.yarnpkg.com/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093"
|
|
||||||
integrity sha1-VtagZAF2JeeevKa4AY4XRAvc8JM=
|
|
||||||
dependencies:
|
|
||||||
lodash._getnative "^3.0.0"
|
|
||||||
|
|
||||||
lodash._createset@~4.0.0:
|
lodash._createset@~4.0.0:
|
||||||
version "4.0.3"
|
version "4.0.3"
|
||||||
resolved "https://registry.yarnpkg.com/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26"
|
resolved "https://registry.yarnpkg.com/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26"
|
||||||
integrity sha1-D0ZZ+7CddRlPqeK4imZE02PJ/iY=
|
integrity sha1-D0ZZ+7CddRlPqeK4imZE02PJ/iY=
|
||||||
|
|
||||||
lodash._getnative@*, lodash._getnative@^3.0.0:
|
|
||||||
version "3.9.1"
|
|
||||||
resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5"
|
|
||||||
integrity sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U=
|
|
||||||
|
|
||||||
lodash._root@~3.0.0:
|
lodash._root@~3.0.0:
|
||||||
version "3.0.1"
|
version "3.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/lodash._root/-/lodash._root-3.0.1.tgz#fba1c4524c19ee9a5f8136b4609f017cf4ded692"
|
resolved "https://registry.yarnpkg.com/lodash._root/-/lodash._root-3.0.1.tgz#fba1c4524c19ee9a5f8136b4609f017cf4ded692"
|
||||||
|
@ -8843,11 +8816,6 @@ lodash.merge@^4.6.1:
|
||||||
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
|
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
|
||||||
integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==
|
integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==
|
||||||
|
|
||||||
lodash.restparam@*:
|
|
||||||
version "3.6.1"
|
|
||||||
resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"
|
|
||||||
integrity sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU=
|
|
||||||
|
|
||||||
lodash.set@^4.3.2:
|
lodash.set@^4.3.2:
|
||||||
version "4.3.2"
|
version "4.3.2"
|
||||||
resolved "https://registry.yarnpkg.com/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23"
|
resolved "https://registry.yarnpkg.com/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23"
|
||||||
|
|
Loading…
Reference in New Issue