HarmonyOS Swiper父组件和内部子组件PanGesture手势冲突问题如何解决?

如题:HarmonyOS Swiper父组件和内部子组件PanGesture手势冲突问题如何解决?

阅读 574
1 个回答

需要参考下面代码实现:实现类似图库图片可放大缩小滑动的效果。

参考图库源码:https://gitee.com/openharmony/applications\_photos/tree/master

关键代码:

图片Item组件:applications\_photos/common/src/main/ets/default/view/PhotoItem.ets

手势处理逻辑:PanGesture…

冲突处理逻辑:

.onTouch((event?: TouchEvent) => {
  this.dealTouchEvent(event as TouchEvent);
  this.eventPipeline?.onTouch(event as TouchEvent);
})

手势管道处理工具:

applications\_photos/common/src/main/ets/default/model/browser/photo/EventPipeline.ts

设置swiper滑动状态逻辑:

public setSwipeStatus(disable: Boolean): void {
  this.broadCast.emit(PhotoConstants.SET_DISABLE_SWIPE, [disable]);
}

整体逻辑是在手势管道中通过事件通知swiper禁用或启用滑动手势。OH当前能力是可以实现的。

图片轮播页面:applications\_photos/common/src/main/ets/default/view/PhotoSwiper.ets

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