HarmonyOS JsBridge里面如何调用自定义弹窗

HarmonyOS
2024-12-17 13:59:41
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
aquaa
<!DOCTYPE html>
  <html>
  <head>
  <meta name="viewport"
content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no,viewport-fit=cover">
  <title>
  </title>
  <script>
  function openWindow() {
    window.myJsb.openDialog()
  }
  </script>
  </head>
  <body>
  <button onclick="openWindow()" style="width: 200px;height: 200px">
  前端调用JSB打开窗口
  </button>
  </body>
  </html>
   

  import webview from '@ohos.web.webview'

export interface JsbObject {
  openDialog: () => void
}

@Entry()
@Component
struct Page2 {
  webviewController = new webview.WebviewController()
  dialogController: CustomDialogController = new CustomDialogController({
    builder: CustomDialogExample({})
  })
  jsbObject: JsbObject = {
    openDialog: () => {
      this.showDialog(this)
    }
  }

  showDialog(context: object) {
    // 怎么把自定义弹窗调出来
    this.dialogController.open()
  }

  build() {
    Column() {
      Web({
        src: "resource://rawfile/aa.html", controller: this.webviewController
      })
        .javaScriptAccess(true)
        .javaScriptProxy({
          name: "myJsb",
          object: this.jsbObject,
          methodList: ["openDialog"],
          controller: this.webviewController
        }).width('100%')
    }
    .backgroundColor(Color.Brown)
  }
}

@CustomDialog
struct CustomDialogExample {
  dialogControllerTwo: CustomDialogController | null = new CustomDialogController({
    builder: CustomDialogExample(), alignment: DialogAlignment.Bottom, offset: { dx: 0, dy: -25 }
  })
  controller?: CustomDialogController

  build() {
    Row() {
      Text("自定义键盘")
    }.height('40%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
分享
微博
QQ
微信
回复
2024-12-17 15:48:59


相关问题
HarmonyOS 自定义弹窗CustomDialog调用问题
1097浏览 • 1回复 待解决
HarmonyOS 关于自定义弹窗的封装调用
1433浏览 • 2回复 待解决
自定义弹窗自定义转场动画
1927浏览 • 1回复 待解决
HarmonyOS 如何封装自定义弹窗
895浏览 • 1回复 待解决
HarmonyOS 在ArkTS类中想调用自定义弹窗
749浏览 • 1回复 待解决
HarmonyOS 自定义弹窗如何更新弹窗的UI
872浏览 • 1回复 待解决
如何自定义弹窗中再次弹窗
3190浏览 • 1回复 待解决
HarmonyOS 自定义弹窗选择
1287浏览 • 1回复 待解决
HarmonyOS 自定义弹窗CustomDialog
740浏览 • 1回复 待解决
自定义弹窗如何嵌套使用
2509浏览 • 1回复 待解决
如何设置自定义弹窗位置
2800浏览 • 1回复 待解决
HarmonyOS 如何设置自定义弹窗透明
885浏览 • 1回复 待解决
HarmonyOS 如何制作自定义加载弹窗
1202浏览 • 1回复 待解决
使用自定义弹窗实现分享弹窗
1342浏览 • 1回复 待解决