feat(SwipeView): 为 SwipeView 组件添加点击和删除事件回调

- 在 SwipeView 组件中添加 onItemClick 和 onDelete 属性- 修改 AIDocumentView 中的 SwipeView 使用新增的事件回调- 优化 SwipeView 的点击和删除逻辑,支持外部自定义操作
这个提交包含在:
徐勤民 2025-05-22 19:13:08 +08:00
父节点 19c6da53f9
当前提交 a872e82cd6

查看文件

@ -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() {
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