Skip to content

Commit d8fd22d

Browse files
author
Marek Rozmus
committed
Add typescript typings and change progress callback name
1 parent 4a4180a commit d8fd22d

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

examples/src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function App() {
8787
swipeLeft={swipeLeftDataSimple('Item with both swipes')}
8888
onSwipeStart={() => console.log('Swipe started')}
8989
onSwipeEnd={() => console.log('Swipe ended')}
90-
onSwipeStateChange={state => console.log(state)}
90+
onSwipeProgress={progress => console.log(progress)}
9191
>
9292
{itemContentSimple('Item with both swipes')}
9393
</SwipeableListItem>

src/SwipeableListItem.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ class SwipeableListItem extends PureComponent {
294294

295295
const opacity = (Math.abs(this.left) / 100).toFixed(2);
296296

297-
if (this.props.onSwipeStateChange) {
297+
if (this.props.onSwipeProgress) {
298298
const swipeDistance = Math.max(
299299
0,
300300
this.listElement.offsetWidth - Math.abs(this.left)
@@ -305,9 +305,7 @@ class SwipeableListItem extends PureComponent {
305305
Math.round((100 * swipeDistance) / this.listElement.offsetWidth);
306306

307307
if (this.prevSwipeDistancePercent !== swipeDistancePercent) {
308-
this.props.onSwipeStateChange({
309-
swipeDistancePercent
310-
});
308+
this.props.onSwipeProgress(swipeDistancePercent);
311309
this.prevSwipeDistancePercent = swipeDistancePercent;
312310
}
313311
}
@@ -396,9 +394,9 @@ SwipeableListItem.propTypes = {
396394
swipeStartThreshold: PropTypes.number,
397395
threshold: PropTypes.number,
398396

399-
onSwipeStart: PropTypes.func,
400397
onSwipeEnd: PropTypes.func,
401-
onSwipeStateChange: PropTypes.func
398+
onSwipeProgress: PropTypes.func,
399+
onSwipeStart: PropTypes.func
402400
};
403401

404402
export default SwipeableListItem;

src/module.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ interface ISwipeableListItemProps {
2020
scrollStartThreshold?: number;
2121
swipeStartThreshold?: number;
2222
threshold?: number;
23+
onSwipeStart: () => void;
24+
onSwipeEnd: () => void;
25+
onSwipeProgress: (progress: number) => void;
2326
}
2427

2528
export class SwipeableListItem extends React.Component<

0 commit comments

Comments
 (0)