Web的桥方法的实现中,不能弹出CustomDialog

当页面有一个加载H5内容的Web时,H5内容通过调用与HarmonyOS原生内容交互桥方法,在这个桥方法中,如果使用了CustomDialog,代码不会异常,但页面上dialog并不会显示。

HarmonyOS
2024-05-07 21:52:49
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
PinkFish
import web_webview from ‘@ohos.web.webview’; 
@Entry 
@Component 
export struct thirdPage { 
  webviewController: web_webview.WebviewController = new web_webview.WebviewController(); 
 
  functionAddController: CustomDialogController = new CustomDialogController({ 
    builder: TestCustomDialog(), 
    customStyle: true, 
  }) 
 
  // 声明需要注册的对象 
  @State testObj: testClass = new testClass(this.functionAddController); 
  build() { 
    Column() { 
      Text(‘直接调用’).fontSize(40).fontColor(0xff000000).onClick(() => { 
        this.functionAddController.open() 
      }).margin(50) 
      Web({ src: $rawfile(‘jsCustomDialog.html’), controller: this.webviewController })// 将对象注入到web端 
        .javaScriptProxy({ 
          object: this.testObj, 
          name: “testObjName”, 
          methodList: [“test”], 
          controller: this.webviewController 
        }) 
    } 
  } 
} 
class testClass { 
  functionAddController?: CustomDialogController 
  constructor(functionAddController?: CustomDialogController) { 
    this.functionAddController=functionAddController 
  } 
  test(): string { 
    // let functionAddController: CustomDialogController = new CustomDialogController({ 
    // builder: TestCustomDialog(), 
    // customStyle: true, 
    // }) 
 
    this.functionAddController?.open() 
 
    return ‘ArkTS Hello World!’; 
  } 
} 
 
@CustomDialog 
export struct TestCustomDialog { 
  dialogController ?: CustomDialogController 
  build() { 
    Text(‘TestCustomDialog’).fontSize(50).fontColor(0xffff0000) 
  } 
}
分享
微博
QQ
微信
回复
2024-05-08 15:50:33
相关问题
CustomDialog如何实现半模态详情页效果
140浏览 • 1回复 待解决
使用web组件实现预览沙箱pdf
153浏览 • 1回复 待解决
对应paintbreakText方法实现
159浏览 • 1回复 待解决
同意取消弹窗怎么实现?用哪个方法
3185浏览 • 1回复 待解决
关于文档说har不能用单例疑惑
152浏览 • 1回复 待解决