From a872e82cd630118706c2bfae139344affa47b004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=8B=A4=E6=B0=91?= Date: Thu, 22 May 2025 19:13:08 +0800 Subject: [PATCH] =?UTF-8?q?feat(SwipeView):=20=E4=B8=BA=20SwipeView=20?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=B7=BB=E5=8A=A0=E7=82=B9=E5=87=BB=E5=92=8C?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=BA=8B=E4=BB=B6=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 SwipeView 组件中添加 onItemClick 和 onDelete 属性- 修改 AIDocumentView 中的 SwipeView 使用新增的事件回调- 优化 SwipeView 的点击和删除逻辑,支持外部自定义操作 --- src/main/ets/view/SwipeView.ets | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/ets/view/SwipeView.ets b/src/main/ets/view/SwipeView.ets index cf2b96d..8edf13e 100644 --- a/src/main/ets/view/SwipeView.ets +++ b/src/main/ets/view/SwipeView.ets @@ -3,6 +3,8 @@ export struct SwipeView { private _scroller: Scroller = new Scroller() @State h: Length = 40 @State downX: number = 0 + onItemClick?: () => void + onDelete?: () => void @Builder doNothingBuilder() { @@ -15,7 +17,16 @@ export struct SwipeView { build() { Scroll(this._scroller) { Row() { - this.customBuilderParam() + Column() { + this.customBuilderParam() + }.width('100%').onClick(() => { + this._scroller.scrollTo({ + xOffset: 0, yOffset: 0, + animation: { duration: 100, curve: Curve.Linear } + }) + this.onItemClick && this.onItemClick() + }) + Text('删除') .backgroundColor('red') .width(70) @@ -23,6 +34,13 @@ export struct SwipeView { .height(this.h) .textAlign(TextAlign.Center) .fontSize(16) + .onClick(() => { + this._scroller.scrollTo({ + xOffset: 0, yOffset: 0, + animation: { duration: 100, curve: Curve.Linear } + }) + this.onDelete && this.onDelete() + }) // if (this.btnBuilder === this.doNothingBuilder) { // Text('删除') // } @@ -59,8 +77,10 @@ export struct SwipeView { toxOffset = 70 } // 滑动指定位置,设置动画 - this._scroller.scrollTo({ xOffset: toxOffset, yOffset: 0, - animation: { duration: 300, curve: Curve.Linear } }) + this._scroller.scrollTo({ + xOffset: toxOffset, yOffset: 0, + animation: { duration: 300, curve: Curve.Linear } + }) // 重置按下的x轴坐标 this.downX = 0 break