HarmonyOS gesture手势如何做精确的手势冲突控制?

swiper(){
  ComponentA().gesture(
    GestureGroup(
      PanGesture({ direction: PanDirection.Horizontal })
  )
  )
}

我目前有这个的UI结构,ComponentA在can\_move\_state状态下会响应左右横滑事件,如何能够使得ComponentA优先响应横滑,如果ComponentA不响应,则父组件swiper响应呢,

ps: can\_move\_state状态在touchdown事件后判定,如果是长按则进入这个状态,

阅读 434
1 个回答

可以参考:

Swiper(){
  Text("111").height(80).width("100%").backgroundColor('#ffa')
  Text("222").height(80).width("100%").backgroundColor('#ffa')
  Text("333").height(80).width("100%").backgroundColor('#ffa').gesture(PanGesture()
    .onActionStart(() => {
      console.info("child", "gesture")
    })
      // 当该手势被触发时,根据回调获得拖动的距离,修改该组件的位移距离从而实现组件的移动
    .onActionUpdate((event: GestureEvent) => {

    }))
  Text("444").height(80).width("100%").backgroundColor('#ffa')
}
// .disableSwipe(true)
.parallelGesture(PanGesture()
  .onActionStart(() => {
    console.info("12222", "gesture")
  })
    // 当该手势被触发时,根据回调获得拖动的距离,修改该组件的位移距离从而实现组件的移动
  .onActionUpdate((event: GestureEvent) => {

  })
)

swiper的简单demo如上,这样设置,第三个子组件滑动的时候,不会触发滚动翻页效果,而且最外层Swiper可以接受到滑动手势,需要如何操作,可以根据自身条件判断,什么时候执行什么,要翻页的话,可以找swiper的controller进行操作

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进