Skip to content
This repository was archived by the owner on Nov 27, 2025. It is now read-only.

Commit 626dd2c

Browse files
authored
Merge pull request #283 from DoubleOrange66/sig
fix: 修复在url传空的场景下直接崩溃问题
2 parents fc35987 + 8c8e2ef commit 626dd2c

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

harmony/rn_webview/src/main/ets/RNCWebView.ets

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,20 @@ export struct RNCWebView {
250250
this.webViewBaseOperate?.ignoreSilentHardwareSwitchMethods(ignoreSilentHardwareSwitch)
251251
}
252252

253+
loadHtmlData(html: string = '', url: string = '') {
254+
try {
255+
this.controller.loadData(
256+
html,
257+
"text/html",
258+
"UTF-8",
259+
url,
260+
" "
261+
);
262+
} catch (error) {
263+
Logger.error(TAG, "error:" + error)
264+
}
265+
}
266+
253267
controllerAttachedInit(): void {
254268
this.controllerAttached = true;
255269
this.eventEmitter = new RNC.RNCWebView.EventEmitter(this.ctx.rnInstance, this.tag)
@@ -260,21 +274,11 @@ export struct RNCWebView {
260274
let baseUrl = this.source.baseUrl
261275
let uri = this.source.uri
262276
if (this.source.html != undefined && this.source.html != "") {
263-
try {
264-
this.controller.loadData(
265-
this.source.html,
266-
"text/html",
267-
"UTF-8",
268-
baseUrl,
269-
" "
270-
);
271-
} catch (error) {
272-
Logger.error(TAG, "error:" + error)
273-
}
277+
this.loadHtmlData(this.source.html, baseUrl)
274278
} else if (uri != undefined && uri != "") {
275279
this.controller.loadUrl(uri, this.headers);
276280
} else {
277-
this.controller.loadUrl(uri, this.headers);
281+
this.loadHtmlData()
278282
}
279283
if (!this.hasRegisterJavaScriptProxy) {
280284
this.registerPostMessage()
@@ -456,24 +460,18 @@ export struct RNCWebView {
456460
Logger.debug(TAG, "[RNOH] html is update")
457461
this.html = this.source.html
458462
if (this.controllerAttached) {
459-
try {
460-
this.controller.loadData(
461-
this.source.html,
462-
"text/html",
463-
"UTF-8",
464-
this.source.baseUrl,
465-
" "
466-
);
467-
} catch (error) {
468-
Logger.error(TAG, "error: " + error)
463+
this.loadHtmlData(this.source.html, this.source.baseUrl)
464+
}
465+
} else if (this.url != this.source.uri) {
466+
if (this.source.uri != "") {
467+
Logger.debug(TAG, `[RNOH] newDescriptor props update uri: ` + this.source.uri);
468+
if (this.controllerAttached) {
469+
this.controller.loadUrl(this.descriptorWrapper.rawProps.newSource.uri, this.headers)
469470
}
471+
} else {
472+
this.loadHtmlData()
470473
}
471-
} else if (this.source.uri != "" && this.url != this.source.uri) {
472-
Logger.debug(TAG, `[RNOH] newDescriptor props update uri: ` + this.source.uri);
473474
this.url = this.source.uri as string;
474-
if (this.controllerAttached) {
475-
this.controller.loadUrl(this.descriptorWrapper.rawProps.newSource.uri, this.headers)
476-
}
477475
}
478476
if (this.controllerAttached) {
479477
this.controller?.setScrollable(this.descriptorWrapper.rawProps.scrollEnabled)

0 commit comments

Comments
 (0)