SwipeAction 滑动或长按操作

滑动( iOS )或长按( android )操作组件。

定义/Definition

结合手势操作,从屏幕唤出删除键。

规则 / Rule

  • 一次只可滑动一行列表

  • 点击任意删除按钮之外任意处或往回滑动该列表可撤销该操作。

代码演示

基本使用

  1. import { SwipeAction, List } from 'antd-mobile';
  2. const SwipeActionExample = React.createClass({
  3. getInitialState() {
  4. return {
  5. items: ['00', '01', '02', '03', '04', '05'],
  6. };
  7. },
  8. onDelete(value) {
  9. const tempArr = this.state.items;
  10. this.setState({
  11. items: tempArr.filter(v => v !== value),
  12. });
  13. },
  14. render() {
  15. return (
  16. <div>
  17. <List>
  18. <SwipeAction
  19. style={{ backgroundColor: 'gray' }}
  20. autoClose
  21. right={[
  22. {
  23. text: '取消',
  24. onPress: () => console.log('取消'),
  25. style: { backgroundColor: '#ddd', color: 'white' },
  26. },
  27. {
  28. text: '删除',
  29. onPress: () => console.log('删除'),
  30. style: { backgroundColor: '#F4333C', color: 'white' },
  31. },
  32. ]}
  33. left={[
  34. {
  35. text: '回复',
  36. onPress: () => console.log('回复'),
  37. style: { backgroundColor: '#108ee9', color: 'white' },
  38. },
  39. {
  40. text: '取消',
  41. onPress: () => console.log('取消'),
  42. style: { backgroundColor: '#ddd', color: 'white' },
  43. },
  44. ]}
  45. onOpen={() => console.log('global open')}
  46. onClose={() => console.log('global close')}
  47. >
  48. <List.Item
  49. extra="更多"
  50. arrow="horizontal"
  51. >
  52. 左右都可操作
  53. </List.Item>
  54. </SwipeAction>
  55. </List>
  56. <div>
  57. <p style={{ padding: '0.16rem 0.32rem' }}>多个实例:</p>
  58. <List>
  59. {this.state.items.map((item, i) => <SwipeAction
  60. style={{ backgroundColor: 'gray' }}
  61. autoClose
  62. key={i}
  63. right={[
  64. {
  65. text: `删除${item}`,
  66. onPress: () => this.onDelete(item),
  67. style: { backgroundColor: '#F4333C', color: 'white' },
  68. },
  69. ]}
  70. >
  71. <List.Item extra="更多" arrow="horizontal" >
  72. item {item}
  73. </List.Item>
  74. </SwipeAction>
  75. )}
  76. </List>
  77. </div>
  78. </div>
  79. );
  80. },
  81. });
  82. ReactDOM.render(<SwipeActionExample />, mountNode);

SwipeAction滑动或长按操作 - 图1

API ( 适用平台:WEB、React-Native )

SwipeAction

参数说明类型默认值
styleswipeout style (iOS only)Object
leftswipeout buttons on leftArraynull
rightswipeout buttons on rightArraynull
autoCloseauto close on button pressBooleanfunction() {}
onOpen打开时回调函数(): voidfunction() {}
disableddisabled swipeoutBooleanfalse
titlemodal title (android only)String请确认操作
onClose (web only)关闭时回调函数(): voidfunction() {}

Button

参数说明类型默认值
textbutton textStringClick
stylebutton style (iOS only)Object
onPressbutton press function(): voidfunction() {}