SwipeAction滑动操作

滑动操作组件。

定义

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

规则

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

代码演示

基本用法

最简单的用法。

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

SwipeAction滑动操作 - 图1

API

SwipeAction

参数说明类型默认值
[left]左侧按钮组Array-
[right]右侧按钮组Array-
[autoClose]点击按钮后自动隐藏按钮booleanfalse
[disabled]禁用 swipeoutbooleanfalse
(onOpen)打开时回调函数EventEmitter<void>-
(onClose)关闭时回调函数EventEmitter<void>-

Button

参数说明类型默认值
[text]按钮文案string‘Click’
[style]按钮样式object{}
[onPress]按钮点击事件EventEmitter<void>-
[className]按钮样式类string-