文档管理中心
FAQ应用框架开发UI框架组件使用如何将ListItem的swipeAction滑动效果恢复到初始状态

如何将ListItem的swipeAction滑动效果恢复到初始状态

使用 ListScroller 提供的 closeAllSwipeActions() 方法恢复滑动效果,示例代码如下:

收起
自动换行
深色代码主题
复制
  1. @Component
  2. export struct SwiperActionRecover {
  3. @State arr: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
  4. private scrollerForList: ListScroller = new ListScroller();
  5. @Builder
  6. itemEnd() {
  7. Row() {
  8. Button('Delete')
  9. Button('Set')
  10. .onClick(() => {
  11. this.scrollerForList.closeAllSwipeActions(); // This is the key line of code
  12. })
  13. }
  14. .justifyContent(FlexAlign.SpaceEvenly)
  15. }
  16. build() {
  17. Column() {
  18. List({ space: 5, scroller: this.scrollerForList }) {
  19. ForEach(this.arr, (item: number) => {
  20. ListItem() {
  21. Text('item' + item)
  22. .width('100%')
  23. .height(100)
  24. .textAlign(TextAlign.Center)
  25. .borderRadius(10)
  26. .backgroundColor(0xFFFFFF)
  27. }
  28. .transition({
  29. type: TransitionType.Delete,
  30. opacity: 0
  31. })
  32. .swipeAction({
  33. end: {
  34. builder: () => {
  35. this.itemEnd();
  36. },
  37. onAction: () => {
  38. this.getUIContext().animateTo({ duration: 1000 }, () => {
  39. let index = this.arr.indexOf(item);
  40. this.arr.splice(index, 1);
  41. });
  42. },
  43. actionAreaDistance: 56
  44. }
  45. })
  46. }, (item: string) => item)
  47. }
  48. }
  49. .padding(20)
  50. .backgroundColor(0xDCDCDC)
  51. .width('100%')
  52. .height('100%')
  53. }
  54. }
在 FAQ 中进行搜索
请输入您想要搜索的关键词