@@ -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,31 +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- try {
278- this.controller.loadData(
279- "",
280- "text/html",
281- "UTF-8",
282- "",
283- " "
284- );
285- } catch (error) {
286- Logger.error(TAG, "error: " + error)
287- }
281+ this.loadHtmlData()
288282 }
289283 if (!this.hasRegisterJavaScriptProxy) {
290284 this.registerPostMessage()
@@ -466,17 +460,7 @@ export struct RNCWebView {
466460 Logger.debug(TAG, "[RNOH] html is update")
467461 this.html = this.source.html
468462 if (this.controllerAttached) {
469- try {
470- this.controller.loadData(
471- this.source.html,
472- "text/html",
473- "UTF-8",
474- this.source.baseUrl,
475- " "
476- );
477- } catch (error) {
478- Logger.error(TAG, "error: " + error)
479- }
463+ this.loadHtmlData(this.source.html, this.source.baseUrl)
480464 }
481465 } else if (this.url != this.source.uri) {
482466 if (this.source.uri != "") {
@@ -485,17 +469,7 @@ export struct RNCWebView {
485469 this.controller.loadUrl(this.descriptorWrapper.rawProps.newSource.uri, this.headers)
486470 }
487471 } else {
488- try {
489- this.controller.loadData(
490- "",
491- "text/html",
492- "UTF-8",
493- "",
494- " "
495- );
496- } catch (error) {
497- Logger.error(TAG, "error: " + error)
498- }
472+ this.loadHtmlData()
499473 }
500474 this.url = this.source.uri as string;
501475 }
0 commit comments