Skip to content

Commit be3c5d6

Browse files
committed
fix(SwipeAction): SwipeAction 增加 moveRatio 支持设置判断是否展开的滑动比例阈值
1 parent 9383c0d commit be3c5d6

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

packages/taro-ui/src/components/swipe-action/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ export default class AtSwipeAction extends React.Component<
2121
private maxOffsetSize: number
2222
private moveX: number
2323
private eleWidth: number
24+
private moveRatio: number
2425

2526
public constructor(props: AtSwipeActionProps) {
2627
super(props)
27-
const { isOpened, maxDistance, areaWidth } = props
28+
const { isOpened, maxDistance, areaWidth, moveRatio } = props
2829
this.maxOffsetSize = maxDistance
2930
this.state = {
3031
componentId: uuid(),
@@ -34,6 +35,7 @@ export default class AtSwipeAction extends React.Component<
3435
}
3536
this.moveX = 0
3637
this.eleWidth = areaWidth
38+
this.moveRatio = moveRatio || 0.5
3739
}
3840

3941
public UNSAFE_componentWillReceiveProps(nextProps: AtSwipeActionProps): void {
@@ -114,7 +116,7 @@ export default class AtSwipeAction extends React.Component<
114116
this.handleClosed(e)
115117
return
116118
}
117-
if (this.maxOffsetSize - this.moveX < this.maxOffsetSize * 0.4) {
119+
if (this.maxOffsetSize - this.moveX < this.maxOffsetSize * this.moveRatio) {
118120
this._reset(false)
119121
this.handleClosed(e)
120122
} else {

packages/taro-ui/types/swipe-action.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,20 @@ export interface AtSwipeActionProps extends AtComponent {
5454
*/
5555
onClosed?: CommonEventFunction
5656

57+
/**
58+
* 滑块最大滑动距离,一般是按钮个数乘以按钮宽度
59+
*/
5760
maxDistance: number
5861

62+
/**
63+
* SwipeAction 组件宽度
64+
*/
5965
areaWidth: number
66+
67+
/**
68+
* 判断是否需要打开的比例阈值,即 滑块滑动距离 / 滑块最大滑动距离, 默认为 0.5
69+
*/
70+
moveRatio?: number
6071
}
6172

6273
export interface AtSwipeActionState {

0 commit comments

Comments
 (0)