SwipeAction滑动操作

滑动操作组件。

定义

结合手势操作,从屏幕一侧唤出操作。

规则

  • 一次只可滑动一行列表
  • 点击任意按钮之外处或往回滑动该列表可隐藏操作。

代码演示

基本用法

最简单的用法。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'demo-swipe-action-basic',
  4. template: `
  5. <NoticeBar *ngIf="!isMobile"
  6. style="margin-bottom: 10px"
  7. [option]="{'content':'该组件只支持Touch事件,请使用移动模式/设备打开此页。', 'marqueeProps': {fps: 100}}"
  8. ></NoticeBar>
  9. <br/>
  10. <List>
  11. <SwipeAction style="background-color: gray"
  12. [right]="right"
  13. [left]="left"
  14. (onOpen)="open()"
  15. (onClose)="close()"
  16. >
  17. <ListItem [extra]="'More'"
  18. [arrow]="'horizontal'"
  19. (onClick)="click()"
  20. >
  21. Have left and right buttons
  22. </ListItem>
  23. </SwipeAction>
  24. <SwipeAction style="background-color: gray"
  25. [autoClose]="true"
  26. [left]="left"
  27. (onOpen)="open()"
  28. (onClose)="close()"
  29. >
  30. <ListItem [extra]="'More'"
  31. [arrow]="'horizontal'"
  32. (onClick)="click()"
  33. >
  34. Only left buttons
  35. </ListItem>
  36. </SwipeAction>
  37. <SwipeAction style="background-color: gray"
  38. [autoClose]="true"
  39. [right]="right"
  40. (onOpen)="open()"
  41. (onClose)="close()"
  42. >
  43. <ListItem [extra]="'More'"
  44. [arrow]="'horizontal'"
  45. (onClick)="click()"
  46. >
  47. Only right buttons
  48. </ListItem>
  49. </SwipeAction>
  50. <SwipeAction style="background-color: gray"
  51. [autoClose]="true"
  52. [right]="rightDifferentWidth"
  53. (onOpen)="open()"
  54. (onClose)="close()"
  55. >
  56. <ListItem [extra]="'More'"
  57. [arrow]="'horizontal'"
  58. (onClick)="click()"
  59. >
  60. Different button width
  61. </ListItem>
  62. </SwipeAction>
  63. <SwipeAction style="background-color: gray"
  64. [autoClose]="true"
  65. [right]="right"
  66. (onOpen)="open()"
  67. (onClose)="close()"
  68. >
  69. <ListItem [extra]="'More'"
  70. [arrow]="'horizontal'"
  71. (onClick)="itemClick()"
  72. >
  73. List.Item with onClick
  74. </ListItem>
  75. </SwipeAction>
  76. </List>
  77. `,
  78. styles : [
  79. `
  80. /deep/.btnClass {
  81. background-color: #F4333C;
  82. color: white
  83. }
  84. `
  85. ]
  86. })
  87. export class DemoSwipeActionBasicComponent {
  88. isMobile = /Android|webOS|iPhone|iPod|BlackBerry/i.test(window.navigator.userAgent);
  89. right = [
  90. {
  91. text: 'Cancel',
  92. onPress: () => console.log('cancel'),
  93. style: { backgroundColor: '#ddd', color: 'white' }
  94. },
  95. {
  96. text: 'Delete',
  97. onPress: () => console.log('delete'),
  98. className: 'btnClass'
  99. }
  100. ];
  101. rightDifferentWidth = [
  102. {
  103. text: 'short',
  104. onPress: () => console.log('cancel'),
  105. style: { backgroundColor: '#ddd', color: 'white' }
  106. },
  107. {
  108. text: 'long text',
  109. onPress: () => console.log('delete'),
  110. className: 'btnClass'
  111. }
  112. ];
  113. left = [
  114. {
  115. text: 'Reply',
  116. onPress: () => console.log('reply'),
  117. style: { backgroundColor: '#108ee9', color: 'white' }
  118. },
  119. {
  120. text: 'Cancel',
  121. onPress: () => console.log('cancel'),
  122. style: { backgroundColor: '#ddd', color: 'white' }
  123. }
  124. ];
  125. open() {
  126. console.log('open');
  127. }
  128. close() {
  129. console.log('close');
  130. }
  131. click() {
  132. console.log('clicked!');
  133. }
  134. itemClick() {
  135. console.log('ListItem clicked!');
  136. }
  137. }

SwipeAction 滑动操作 - 图1

API

SwipeAction

属性说明类型默认值
left左侧按钮组Arraynull
right右侧按钮组Arraynull
autoClose点击按钮后自动隐藏按钮Booleanfalse
onOpen打开时回调函数(): voidfunction() {}
disabled禁用 swipeoutBooleanfalse
onClose关闭时回调函数(): voidfunction() {}

Button

参数说明类型默认值
text按钮文案StringClick
style按钮样式Object{}
onPress按钮点击事件(): voidfunction() {}
className按钮样式类String