SwipeAction 滑动操作

滑动操作组件。

定义

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

规则

  • 一次只可滑动一行列表

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

代码演示

基本

  1. import { SwipeAction, List } from 'antd-mobile';
  2. const SwipeActionExample = () => (
  3. <List>
  4. <SwipeAction
  5. style={{ backgroundColor: 'gray' }}
  6. autoClose
  7. right={[
  8. {
  9. text: 'Cancel',
  10. onPress: () => console.log('cancel'),
  11. style: { backgroundColor: '#ddd', color: 'white' },
  12. },
  13. {
  14. text: 'Delete',
  15. onPress: () => console.log('delete'),
  16. style: { backgroundColor: '#F4333C', color: 'white' },
  17. },
  18. ]}
  19. left={[
  20. {
  21. text: 'Reply',
  22. onPress: () => console.log('reply'),
  23. style: { backgroundColor: '#108ee9', color: 'white' },
  24. },
  25. {
  26. text: 'Cancel',
  27. onPress: () => console.log('cancel'),
  28. style: { backgroundColor: '#ddd', color: 'white' },
  29. },
  30. ]}
  31. onOpen={() => console.log('global open')}
  32. onClose={() => console.log('global close')}
  33. >
  34. <List.Item
  35. extra="More"
  36. arrow="horizontal"
  37. onClick={e => console.log(e)}
  38. >
  39. Have left and right buttons
  40. </List.Item>
  41. </SwipeAction>
  42. <SwipeAction
  43. style={{ backgroundColor: 'gray' }}
  44. autoClose
  45. left={[
  46. {
  47. text: 'Reply',
  48. onPress: () => console.log('reply'),
  49. style: { backgroundColor: '#108ee9', color: 'white' },
  50. },
  51. {
  52. text: 'Cancel',
  53. onPress: () => console.log('cancel'),
  54. style: { backgroundColor: '#ddd', color: 'white' },
  55. },
  56. ]}
  57. onOpen={() => console.log('global open')}
  58. onClose={() => console.log('global close')}
  59. >
  60. <List.Item
  61. extra="More"
  62. arrow="horizontal"
  63. onClick={e => console.log(e)}
  64. >
  65. Only left buttons
  66. </List.Item>
  67. </SwipeAction>
  68. <SwipeAction
  69. style={{ backgroundColor: 'gray' }}
  70. autoClose
  71. right={[
  72. {
  73. text: 'Cancel',
  74. onPress: () => console.log('cancel'),
  75. style: { backgroundColor: '#ddd', color: 'white' },
  76. },
  77. {
  78. text: 'Delete',
  79. onPress: () => console.log('delete'),
  80. style: { backgroundColor: '#F4333C', color: 'white' },
  81. },
  82. ]}
  83. onOpen={() => console.log('global open')}
  84. onClose={() => console.log('global close')}
  85. >
  86. <List.Item
  87. extra="More"
  88. arrow="horizontal"
  89. onClick={e => console.log(e)}
  90. >
  91. Only right buttons
  92. </List.Item>
  93. </SwipeAction>
  94. <SwipeAction
  95. style={{ backgroundColor: 'gray' }}
  96. autoClose
  97. right={[
  98. {
  99. text: 'short',
  100. onPress: () => console.log('cancel'),
  101. style: { backgroundColor: '#ddd', color: 'white' },
  102. },
  103. {
  104. text: 'long text',
  105. onPress: () => console.log('delete'),
  106. style: { backgroundColor: '#F4333C', color: 'white' },
  107. },
  108. ]}
  109. onOpen={() => console.log('global open')}
  110. onClose={() => console.log('global close')}
  111. >
  112. <List.Item
  113. extra="More"
  114. arrow="horizontal"
  115. onClick={e => console.log(e)}
  116. >
  117. Different button width
  118. </List.Item>
  119. </SwipeAction>
  120. <SwipeAction
  121. style={{ backgroundColor: 'gray' }}
  122. autoClose
  123. right={[
  124. {
  125. text: 'button1',
  126. onPress: () => console.log('cancel'),
  127. style: { backgroundColor: '#ddd', color: 'white' },
  128. },
  129. {
  130. text: 'button2',
  131. onPress: () => console.log('delete'),
  132. style: { backgroundColor: '#F4333C', color: 'white' },
  133. },
  134. ]}
  135. onOpen={() => console.log('global open')}
  136. onClose={() => console.log('global close')}
  137. >
  138. <List.Item
  139. extra="More"
  140. arrow="horizontal"
  141. onClick={() => console.log('List.Item clicked!')}
  142. >
  143. List.Item with onClick
  144. </List.Item>
  145. </SwipeAction>
  146. </List>
  147. );
  148. ReactDOM.render(<SwipeActionExample />, mountNode);

SwipeAction滑动操作 - 图1

API

SwipeAction

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

Button

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