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