用户3096723
用户3096723
  • 发布:2026-07-17 12:10
  • 更新:2026-07-17 12:10
  • 阅读:6

如何解决XComponent无法触发触摸事件问题

分类:Native.js

问题现象
在XComponent组件中绑定onTouch方法,但发现该方法中的日志未被输出,表明onTouch事件未能正常触发。

问题参考如下:

Column() {
XComponent({
id: 'xcomponentId-00',
type: "12314",
libraryname: 'nativerender'
})
.onTouch((event: TouchEvent) => {
console.info(onTouch ${event.type})
})
}
.height(CommonConstants.XCOMPONENT_HEIGHT)
.width('100%')
背景知识
XComponent接口提供用于图形绘制和媒体数据写入的Surface,XComponent负责将其嵌入到视图中,支持应用自定义Surface位置和大小。当XComponentType参数为SURFACE或TEXTURE时,支持onTouch等通用事件。

解决方案
当问题代码中使用XComponent(value: {id: string, type: XComponentType, libraryname?: string, controller?: XComponentController})接口时,若配置了libraryname参数,点击事件、触摸事件、按键事件等通用事件将仅响应C-API侧的事件接口,因此问题代码中的onTouch事件无法被触发。
为使onTouch事件正常响应,建议改用不含libraryname参数的XComponent(options: XComponentOptions)接口进行配置。
@Entry
@Component
struct TouchEventDemo {
xComponentController: XComponentController = new XComponentController();
private aiController: ImageAnalyzerController = new ImageAnalyzerController();
private options: ImageAIOptions = {
types: [ImageAnalyzerType.SUBJECT, ImageAnalyzerType.TEXT],
aiController: this.aiController
};

build() {
RelativeContainer() {
Column() {
XComponent({
type: XComponentType.SURFACE,
controller: this.xComponentController,
imageAIOptions: this.options
})
.onTouch((event: TouchEvent) => {
console.info(onTouch ${event.type});
})
}
.height('100%')
.width('100%')
}
}
}
https://pastebin.com/hvG11U3X
https://pastebin.com/5vptr8Vj
https://pastebin.com/spr7PWcm
https://pastebin.com/tUag4haX
https://pastebin.com/jzrFTCja
https://pastebin.com/tfu0SQsU
https://pastebin.com/2JeU38Mk
https://pastebin.com/eKgfgpUT
https://pastebin.com/73u8nze7
https://pastebin.com/4R6vjQ2e
https://pastebin.com/Ft9TAMiA
https://pastebin.com/skk2MENv
https://pastebin.com/C8J9MCsS
https://pastebin.com/D8eS2eVs
https://pastebin.com/RaU1cpC8
https://pastebin.com/wMA4np3d
https://pastebin.com/ZU1mhEvu
https://pastebin.com/5aUaBFzL
https://pastebin.com/KCTNuVQP
https://pastebin.com/PFhGqsLd
https://pastebin.com/CqqNRshL
https://pastebin.com/xyiRj81f
https://pastebin.com/156bZ7kc
https://pastebin.com/pKpShzm2
https://pastebin.com/h7PuBnh2
https://pastebin.com/8UcYTqbk
https://pastebin.com/xkMGBUL8
https://pastebin.com/BivPc7y2
https://pastebin.com/JGtxHhde
https://pastebin.com/BjDgBxnN
https://pastebin.com/ap8KeUuq
https://pastebin.com/xHKEb7rn
https://pastebin.com/DM1qdNRY
https://pastebin.com/vtxzFrXD
https://pastebin.com/aQdD2bLf
https://pastebin.com/d0ugdU4E
https://pastebin.com/Kygm5PDF
https://pastebin.com/mvAFf2cH
https://pastebin.com/wyUkyjiR
https://pastebin.com/riLYiEup
https://pastebin.com/gyyG9xim
https://pastebin.com/92KWyBzX
https://pastebin.com/SYxiX3vk
https://pastebin.com/ccQnUpjp
https://pastebin.com/9itPbhvZ
https://pastebin.com/kK5SsjRL
https://pastebin.com/fKJVLMK4
https://pastebin.com/2bRA2tTD
https://pastebin.com/bK56A1Ji
https://pastebin.com/qZdZ0ZJc
https://pastebin.com/QkWkCjEe
https://pastebin.com/uuKEVPS5
https://pastebin.com/0SqY91RV
https://pastebin.com/64YFs9BU
https://pastebin.com/KXZMGD1y
https://pastebin.com/cmDJHdy8
https://pastebin.com/XhikpFRA
https://pastebin.com/a967PHpL
https://pastebin.com/82SJ8KES
https://pastebin.com/JGUMK4Nx
https://pastebin.com/k65Apwb6
https://pastebin.com/9MKp2Bps
https://pastebin.com/dZ3k4mTn
https://pastebin.com/PgdZ425U
https://pastebin.com/ecG58Lav
https://pastebin.com/N0BBP0u7
https://pastebin.com/yHRL54ZE
https://pastebin.com/U0xa6Y0G
https://pastebin.com/UTMgGYNa
https://pastebin.com/R0zbC3rT
https://pastebin.com/97HSLFJD
https://pastebin.com/9khsxUzA
https://pastebin.com/9fNLJNN7
https://pastebin.com/4WNM1pZx
https://pastebin.com/Tw5GufjZ
https://pastebin.com/Wt26ty6F
https://pastebin.com/inqkXD0y
https://pastebin.com/ni9a0CDf
https://pastebin.com/p7MJC9KZ
https://pastebin.com/vAY8apDR
https://pastebin.com/Arn9MVZD
https://pastebin.com/QjR2Tbc9
https://pastebin.com/pZJsQkbP
https://pastebin.com/34a3s54B
https://pastebin.com/Qd8jWSJy
https://pastebin.com/5ULyrRin
https://pastebin.com/Mysz4mvi
https://pastebin.com/NSCN6QCt
https://pastebin.com/73SimwCg
https://pastebin.com/dkxTW70g
https://pastebin.com/YiqBc7eL
https://pastebin.com/T0Mi3Rtw
https://pastebin.com/5gxVnwcS
https://pastebin.com/4fcAGJqe
https://pastebin.com/DpHm4jGV
https://pastebin.com/3pgkL5s1
https://pastebin.com/xxXpzDjG
https://pastebin.com/a7GwePbx
https://pastebin.com/TiwMauwm
https://pastebin.com/Bdv3mYgA
https://pastebin.com/16hgsDGD
https://pastebin.com/VG4LgHSx
https://pastebin.com/M66rtgJR
https://pastebin.com/HtKqFQsB
https://pastebin.com/bbXWPnfj
https://pastebin.com/rWUN3huF
https://pastebin.com/UcTg7hJ1
https://pastebin.com/dn8Xx3GV
https://pastebin.com/1FP6Ntcf
https://pastebin.com/51v1RYdK
https://pastebin.com/P7UWVTwF
https://pastebin.com/Ft0AhqBE
https://pastebin.com/ZzVNTgPn
https://pastebin.com/sNjruc5F
https://pastebin.com/jMpMTVV8
https://pastebin.com/ci0DJWN1
https://pastebin.com/xxGwHDYx
https://pastebin.com/pW2P4G7e
https://pastebin.com/Zt4KZFQJ
https://pastebin.com/1zS2gHeb
https://pastebin.com/JHuHqTqf
https://pastebin.com/SwWKxw4j
https://pastebin.com/5PL1YwjX
https://pastebin.com/RrDicvTi
https://pastebin.com/UazzqSb2
https://pastebin.com/S1gyeG3P
https://pastebin.com/GKQbJJv2
https://pastebin.com/CJjdP4B3
https://pastebin.com/GB663WX1
https://pastebin.com/RQ19buAq
https://pastebin.com/148WQqS3
https://pastebin.com/U2qz1gVU
https://pastebin.com/ZeTTswjH
https://pastebin.com/vJfCU6ua
https://pastebin.com/sJgFKYdu
https://pastebin.com/F1Sj7ehQ
https://pastebin.com/CAYPv3Wv
https://pastebin.com/QC2VFSwf
https://pastebin.com/WRgpuuNh
https://pastebin.com/12Kn9u92
https://pastebin.com/yE8AK7QP
https://pastebin.com/XbqQm6PP
https://pastebin.com/WJmTxCVM
https://pastebin.com/NPNT49x6
https://pastebin.com/U1xYBpaB
https://pastebin.com/CAJ57UsS
https://pastebin.com/vqnVBxTA
https://pastebin.com/pHTHBxzP
https://pastebin.com/bqL71TeY
https://pastebin.com/wu4su4Fw
https://pastebin.com/sn6Dt1qx
https://pastebin.com/TQSHKCdX
https://pastebin.com/QbqNaMzW
https://pastebin.com/ntxUbuAm
https://pastebin.com/mTKE6ebR
https://pastebin.com/BWfdfKAF
https://pastebin.com/5i405zXJ
https://pastebin.com/tMKCxf2E
https://pastebin.com/SxfitKct

0 关注 分享

要回复文章请先登录注册