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

Commit fdd7734

Browse files
Merge pull request #116 from mingmingaini/sig
fix:修复webview加载崩溃问题
2 parents 7fce16b + 3fa5098 commit fdd7734

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ export struct RNCWebView {
8989

9090
aboutToAppear() {
9191
try {
92-
this.eventEmitter = new RNC.RNCWebView.EventEmitter(this.ctx.rnInstance, this.tag)
9392
this.initVariable()
9493
this.url = this.source.uri as string;
9594
webview.WebviewController.setWebDebuggingAccess(this.descriptorWrapper.props.webviewDebuggingEnabled)
@@ -109,7 +108,6 @@ export struct RNCWebView {
109108
}
110109
})
111110
}
112-
this.webViewBaseOperate = BaseOperate.getInstance(this.eventEmitter, this.controller)
113111
} catch (error) {
114112
Logger.error(TAG, `[RNOH]Errorcode: ${error.code}, Message: ${error.message}`);
115113
}
@@ -360,6 +358,13 @@ export struct RNCWebView {
360358
this.webViewBaseOperate?.ignoreSilentHardwareSwitchMethods(ignoreSilentHardwareSwitch)
361359
}
362360

361+
controllerAttachedInit(): void {
362+
this.controllerAttached = true;
363+
this.eventEmitter = new RNC.RNCWebView.EventEmitter(this.ctx.rnInstance, this.tag)
364+
this.webViewBaseOperate = BaseOperate.getInstance(this.eventEmitter, this.controller)
365+
this.ignoreSilentHardwareSwitchMethods(this.descriptorWrapper.props.ignoreSilentHardwareSwitch)
366+
}
367+
363368
build() {
364369
Stack() {
365370
Web({ src: "", controller: this.controller, renderMode: this.renderMode })
@@ -433,8 +438,7 @@ export struct RNCWebView {
433438
}
434439
})
435440
.onControllerAttached(() => {
436-
this.ignoreSilentHardwareSwitchMethods(this.descriptorWrapper.props.ignoreSilentHardwareSwitch)
437-
this.controllerAttached = true;
441+
this.controllerAttachedInit()
438442
Logger.debug(TAG, "[RNOH] onControllerAttached")
439443
let baseUrl = this.source.baseUrl
440444
let uri = this.source.uri
@@ -458,7 +462,6 @@ export struct RNCWebView {
458462
if (!this.hasRegisterJavaScriptProxy) {
459463
this.registerPostMessage()
460464
}
461-
this.ignoreSilentHardwareSwitchMethods(this.descriptorWrapper.props.ignoreSilentHardwareSwitch)
462465
})
463466
.onAlert((event) => this.onJavascriptAlert(event))
464467
.onConfirm((event) => this.onJavascriptConfirm(event))

harmony/rn_webview/src/main/ets/WebViewBaseOperate.ets

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,6 @@ export class BaseOperate {
198198
}
199199

200200
ignoreSilentHardwareSwitchMethods(ignoreSilentHardwareSwitch: boolean) {
201-
Logger.info(TAG,
202-
`ignoreSilentHardwareSwitchignoreSilentHardwareSwitchignoreSilentHardwareSwitch==${JSON.stringify(!ignoreSilentHardwareSwitch)}`)
203201
this.controller.setAudioMuted(!ignoreSilentHardwareSwitch)
204202
}
205203
}

0 commit comments

Comments
 (0)