Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified harmony/rn_webview.har
Binary file not shown.
50 changes: 35 additions & 15 deletions harmony/rn_webview/src/main/ets/WebView.ets
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export struct WebView {
requestUrl: string = "";
messagingEnabled: boolean = false;
hasRegisterJavaScriptProxy: boolean = false;
controllerAttached: boolean = false;

aboutToAppear() {
this.descriptor = this.ctx.descriptorRegistry.getDescriptor<WebViewViewDescriptor>(this.tag)
Expand All @@ -113,24 +114,30 @@ export struct WebView {
if (this.html != "" && this.html != this.source.html) {
Logger.debug(TAG, "[RNOH] html is update")
this.html = this.source.html
try {
this.controller.loadData(
this.source.html,
"text/html",
"UTF-8",
this.source.baseUrl,
" "
);
} catch (error) {
Logger.error(TAG, "error: " + error)
if (this.controllerAttached) {
try {
this.controller.loadData(
this.source.html,
"text/html",
"UTF-8",
this.source.baseUrl,
" "
);
} catch (error) {
Logger.error(TAG, "error: " + error)
}
}
} else if (this.source.uri != "" && this.url != this.source.uri) {
Logger.debug(TAG, `[RNOH] newDescriptor props update uri: ` + this.source.uri);
this.url = this.source.uri
this.controller.loadUrl(this.descriptor.props.newSource.uri)
if (this.controllerAttached) {
this.controller.loadUrl(this.descriptor.props.newSource.uri)
}
} else {
Logger.debug(TAG, `[RNOH] newDescriptor props refresh`);
this.controller.refresh()
if (this.controllerAttached) {
this.controller.refresh()
}
}
}
)
Expand Down Expand Up @@ -225,14 +232,26 @@ export struct WebView {
switch (command) {
case "injectJavaScript":
Logger.debug(TAG,`[RNOH] injectJavaScript,${JSON.stringify(args)}`)
this.controller.runJavaScript(args[0])
if (this.controllerAttached) {
try {
this.controller.runJavaScript(args[0])
} catch (error) {
Logger.error(TAG, "error: " + error)
}
}
break
case "postMessage":
Logger.debug(TAG,`[RNOH] postMessage,${JSON.stringify(args)}`)
break
case "reload":
Logger.debug(TAG,`[RNOH] reload,${JSON.stringify(args)}`)
this.controller.refresh();
if (this.controllerAttached) {
try {
this.controller.refresh();
} catch (error) {
Logger.error(TAG, "error: " + error)
}
}
break
default:
break
Expand Down Expand Up @@ -297,7 +316,7 @@ export struct WebView {

runInjectedJavaScript() {
let injectedJS = this.descriptor.props.injectedJavaScript
if (this.javaScriptEnable && injectedJS != "") {
if (this.javaScriptEnable && injectedJS != "" && this.controllerAttached) {
try {
this.controller.runJavaScript("(function() {\n" + injectedJS + ";\n})();")
.then((result) => {
Expand Down Expand Up @@ -383,6 +402,7 @@ export struct WebView {
return true
})
.onControllerAttached(() => {
this.controllerAttached = true;
Logger.debug(TAG,"[RNOH] onControllerAttached")
let baseUrl = this.source.baseUrl
let uri = this.source.uri
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"Thibault Malbranche <malbranche.thibault@gmail.com>"
],
"license": "MIT",
"version": "13.6.2-0.0.4",
"version": "13.6.2-0.0.5",
"homepage": "https://github.com/react-native-webview/react-native-webview#readme",
"scripts": {
"android": "react-native run-android",
Expand Down