feat(SwipeView): 优化滑动视图的点击和滚动逻辑
- 添加 UUID 生成和本地存储功能,用于唯一标识每个 SwipeView 实例 - 实现点击 ID 变化时自动滚动到起始位置的功能 - 在触摸事件中添加本地存储操作,确保滑动操作的正确性
这个提交包含在:
父节点
a872e82cd6
当前提交
fbc929fcf8
@ -1,3 +1,5 @@
|
|||||||
|
import { SZYXLocalStorageHelper, ToolsHelper } from '../../../../Index'
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
export struct SwipeView {
|
export struct SwipeView {
|
||||||
private _scroller: Scroller = new Scroller()
|
private _scroller: Scroller = new Scroller()
|
||||||
@ -5,6 +7,17 @@ export struct SwipeView {
|
|||||||
@State downX: number = 0
|
@State downX: number = 0
|
||||||
onItemClick?: () => void
|
onItemClick?: () => void
|
||||||
onDelete?: () => void
|
onDelete?: () => void
|
||||||
|
ids: string = ToolsHelper.getUuid()
|
||||||
|
@LocalStorageLink('XBasicSwipeClick') @Watch('onClickIdChange') clickId: string | undefined = undefined
|
||||||
|
|
||||||
|
onClickIdChange() {
|
||||||
|
if (this.clickId !== this.ids) {
|
||||||
|
this._scroller.scrollTo({
|
||||||
|
xOffset: 0, yOffset: 0,
|
||||||
|
animation: { duration: 100, curve: Curve.Linear }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
doNothingBuilder() {
|
doNothingBuilder() {
|
||||||
@ -20,6 +33,7 @@ export struct SwipeView {
|
|||||||
Column() {
|
Column() {
|
||||||
this.customBuilderParam()
|
this.customBuilderParam()
|
||||||
}.width('100%').onClick(() => {
|
}.width('100%').onClick(() => {
|
||||||
|
// SZYXLocalStorageHelper.storage.setOrCreate('XBasicSwipeClick', this.ids)
|
||||||
this._scroller.scrollTo({
|
this._scroller.scrollTo({
|
||||||
xOffset: 0, yOffset: 0,
|
xOffset: 0, yOffset: 0,
|
||||||
animation: { duration: 100, curve: Curve.Linear }
|
animation: { duration: 100, curve: Curve.Linear }
|
||||||
@ -35,6 +49,7 @@ export struct SwipeView {
|
|||||||
.textAlign(TextAlign.Center)
|
.textAlign(TextAlign.Center)
|
||||||
.fontSize(16)
|
.fontSize(16)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
|
// SZYXLocalStorageHelper.storage.setOrCreate('XBasicSwipeClick', this.ids)
|
||||||
this._scroller.scrollTo({
|
this._scroller.scrollTo({
|
||||||
xOffset: 0, yOffset: 0,
|
xOffset: 0, yOffset: 0,
|
||||||
animation: { duration: 100, curve: Curve.Linear }
|
animation: { duration: 100, curve: Curve.Linear }
|
||||||
@ -58,6 +73,7 @@ export struct SwipeView {
|
|||||||
// 根据触摸类型判断
|
// 根据触摸类型判断
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case TouchType.Down: // 触摸按下
|
case TouchType.Down: // 触摸按下
|
||||||
|
SZYXLocalStorageHelper.storage.setOrCreate('XBasicSwipeClick', this.ids)
|
||||||
// 记录按下的x轴坐标
|
// 记录按下的x轴坐标
|
||||||
this.downX = event.touches[0].x
|
this.downX = event.touches[0].x
|
||||||
break
|
break
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户