SwipeAction 滑动操作

滑动操作组件。

定义

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

规则

  • 一次只可滑动一行列表

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

代码演示

基本

  1. import { SwipeAction, List } from 'antd-mobile';
  2. function handleClick(e) {
  3. console.log('clicked', e);
  4. }
  5. const SwipeActionExample = () => (
  6. <List>
  7. <SwipeAction
  8. style={{ backgroundColor: 'gray' }}
  9. autoClose
  10. right={[
  11. {
  12. text: 'Cancel',
  13. onPress: () => console.log('cancel'),
  14. style: { backgroundColor: '#ddd', color: 'white' },
  15. },
  16. {
  17. text: 'Delete',
  18. onPress: () => console.log('delete'),
  19. style: { backgroundColor: '#F4333C', color: 'white' },
  20. },
  21. ]}
  22. left={[
  23. {
  24. text: 'Reply',
  25. onPress: () => console.log('reply'),
  26. style: { backgroundColor: '#108ee9', color: 'white' },
  27. },
  28. {
  29. text: 'Cancel',
  30. onPress: () => console.log('cancel'),
  31. style: { backgroundColor: '#ddd', color: 'white' },
  32. },
  33. ]}
  34. onOpen={() => console.log('global open')}
  35. onClose={() => console.log('global close')}
  36. >
  37. <List.Item
  38. extra="More"
  39. arrow="horizontal"
  40. onClick={handleClick}
  41. >
  42. Have left and right buttons
  43. </List.Item>
  44. </SwipeAction>
  45. <SwipeAction
  46. style={{ backgroundColor: 'gray' }}
  47. autoClose
  48. right={[
  49. {
  50. text: 'Cancel',
  51. onPress: () => console.log('cancel'),
  52. style: { backgroundColor: '#ddd', color: 'white' },
  53. },
  54. {
  55. text: 'Delete',
  56. onPress: () => console.log('delete'),
  57. style: { backgroundColor: '#F4333C', color: 'white' },
  58. },
  59. ]}
  60. left={[
  61. {
  62. text: 'Reply',
  63. onPress: () => console.log('reply'),
  64. style: { backgroundColor: '#108ee9', color: 'white' },
  65. },
  66. {
  67. text: 'Cancel',
  68. onPress: () => console.log('cancel'),
  69. style: { backgroundColor: '#ddd', color: 'white' },
  70. },
  71. ]}
  72. onOpen={() => console.log('global open')}
  73. onClose={() => console.log('global close')}
  74. >
  75. <List.Item
  76. extra="More"
  77. arrow="horizontal"
  78. onClick={handleClick}
  79. >
  80. Have left and right buttons
  81. </List.Item>
  82. </SwipeAction>
  83. </List>
  84. );
  85. ReactDOM.render(<SwipeActionExample />, mountNode);

SwipeAction滑动操作 - 图1

API

适用平台:WEB、React-Native

SwipeAction

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

Button

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