简体   繁体   English

SVG 在反应原生 WebView (iOS) 中加载问题

[英]SVG loading issue in react native WebView (iOS)

Tools used使用的工具

D3 js: v4.11.0
react-native: v0.60.3
react-native-webview: v9.3.0

Previously I was using react-native 0.59.8 and I was using WebView from react-native, in this version WebView was working fine, SVG was also loading perfectly, but after upgrading react native to 0.60.3, I also have to take WebView from react-native-webview, Previously I was using react-native 0.59.8 and I was using WebView from react-native, in this version WebView was working fine, SVG was also loading perfectly, but after upgrading react native to 0.60.3, I also have to take WebView from react-native -网络视图,

React Native WebView:-反应原生 WebView:-

<WebView
scrollEnabled = {true}
originWhitelist={["*"]}
javaScriptEnabled={true}
source={{ uri: isAndroid ? "file:///android_asset/widget/index.html" : "./widget/index.html" }}
// useWebKit={false}
allowUniversalAccessFromFileURLs={true}
allowFileAccess={true}
scalesPageToFit={true}
onMessage={this.getSelectedSeat}
ref={component => (this.webview = component)}
style={{ width: deviceWidth, height: deviceHeight }}/>

Calling:来电:

this.webview.postMessage("data");

Capturing in HTML:在 HTML 中捕获:

this.window.addEventListener("message", data => {
}

Loading SVG in HTML:-在 HTML 中加载 SVG:-

function loadSVG(svgURL) {
      d3.xml(
        svgURL,
        function (xml) {
          if (xml != null) {
            var importedFile = document.importNode(xml.documentElement, true);
            d3.select("#layout")
              .node()
              .append(importedFile);
          }
        },
        err => {
          alert('error')
        }
      );
    }

In android same code is working fine, but not in iOS, every time xml is null, but it was fine in the older version of WebView where I was taking WebView from react-native, I don't know what I'm missing, may be some property. In android same code is working fine, but not in iOS, every time xml is null, but it was fine in the older version of WebView where I was taking WebView from react-native, I don't know what I'm missing, may be一些财产。 Please Help.请帮忙。

Update: I'm getting error message: {"isTrusted":true}, I think this is Cross-Origin related issue, is there any way to disable this in iOS WKWebView?更新:我收到错误消息:{“isTrusted”:true},我认为这是与跨域相关的问题,有没有办法在 iOS WKWebView 中禁用它?

The iOS WKWebView actually includes this config key in the WKWebViewConfiguration, so it's a straightforward fix. iOS WKWebView 实际上在 WKWebViewConfiguration 中包含此配置键,因此这是一个简单的修复。 I added the line:我添加了这一行:

[wkWebViewConfig setValue:@TRUE forKey:@"allowUniversalAccessFromFileURLs"];

In the file RNCWebView.m, line 200, to get it to work (after adding to the react-native shared props in the bridge.)在文件 RNCWebView.m 的第 200 行中,使其工作(在添加到桥中的 react-native 共享道具之后。)

source: https://github.com/react-native-community/react-native-webview/issues/1290来源: https://github.com/react-native-community/react-native-webview/issues/1290

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM