HarmonyOS 点击穿透的策略

有个自定义组件 Father,有 onClick 事件,自定义组件里面有另一个自定义组件,这个自定义组件 build 就是一个 canvas。也是有 onclick 的,通过它的 onClick 传来的参数坐标,来判断用户点击了哪里,有些区域希望这个子组件响应。而有些希望不响应,而是让外层的父自定义组件去响应。

HarmonyOS
2024-12-20 16:46:58
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

参考demo:

// xxx.ets
import promptAction from '@ohos.promptAction';

@Component
struct child{
  submitArrow?: () => void
  build() {
    Column(){
    }
    .width('500px')
    .height('500px')
    .backgroundColor(0xAFEEEE)
    .onClick((event: ClickEvent)=>{
      if (event.x<50&&event.y<80) {
        if (this.submitArrow) {
          this.submitArrow()
        }
      }else {
        promptAction.showToast({ message: '子组件响应', duration: 3000 })
      }
    })
  }
}

@Entry
@Component
struct Parent {

  @State text: string = 'Button'
  pButton: () => void = () => {
    promptAction.showToast({ message: '父组件响应', duration: 3000 })
  }
  build() {
    Column() {
      child({ submitArrow: this.pButton })
    }
    .width('100%')
    .height('100%')
    .backgroundColor(0xF1F3F5)
    .justifyContent(FlexAlign.Center)
    .padding({ left: 12, right: 12, bottom: 24 })
  }
}
  • 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.
分享
微博
QQ
微信
回复
2024-12-20 17:51:38
相关问题
HarmonyOS web页面点击穿透问题
673浏览 • 1回复 待解决
HarmonyOS ReactNavigation点击事件穿透
662浏览 • 1回复 待解决
HarmonyOS 事件穿透问题
1188浏览 • 1回复 待解决
HarmonyOS 弹窗,可触摸穿透
640浏览 • 1回复 待解决
HarmonyOS 如何实现事件穿透
474浏览 • 1回复 待解决
组件有没有支持事件穿透属性
2346浏览 • 1回复 待解决
HarmonyOS 混淆加固策略
848浏览 • 1回复 待解决
HarmonyOS 图片缓存策略
1209浏览 • 1回复 待解决
如何实现悬浮窗桌面穿透
1429浏览 • 1回复 待解决
关于HarmonyOS 策略模式构建
617浏览 • 1回复 待解决
HarmonyOS 线程池使用策略咨询
894浏览 • 1回复 待解决
NFC相关代码HarmonyOS策略demo
842浏览 • 1回复 待解决
floating window可以设置事件穿透吗?
728浏览 • 1回复 待解决
如何阻止Flex容器鼠标事件穿透
2909浏览 • 1回复 待解决
taskpool管理策略是什么
1428浏览 • 1回复 待解决
多模态交互优先级策略
362浏览 • 0回复 待解决
鸿蒙系统性能优化策略有哪些?
317浏览 • 0回复 待解决
混淆策略配置都有哪些?
1421浏览 • 1回复 待解决
HarmonyOS 音频打断策略焦点模式
859浏览 • 1回复 待解决
HarmonyOS Web是否有缓存策略
778浏览 • 1回复 待解决