Skip to content

Commit 24a2305

Browse files
committed
Added direction, event, and gestureState to swipeGestureEnded data
1 parent 928d8f2 commit 24a2305

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

components/SwipeListView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class SwipeListView extends PureComponent {
183183
}
184184
ref={row => (this._rows[key] = row)}
185185
swipeGestureBegan={() => this.rowSwipeGestureBegan(key)}
186-
swipeGestureEnded={data =>
186+
swipeGestureEnded={(swipeKey, data) =>
187187
this.rowSwipeGestureEnded(key, data)
188188
}
189189
onRowOpen={toValue => this.onRowOpen(key, toValue)}

components/SwipeRow.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,11 @@ class SwipeRow extends Component {
341341

342342
handlePanResponderRelease(e, gestureState) {
343343
this.props.swipeGestureEnded &&
344-
this.props.swipeGestureEnded({
344+
this.props.swipeGestureEnded(this.props.swipeKey, {
345345
translateX: this.currentTranslateX,
346+
direction: this.previousTrackedDirection,
347+
event: e,
348+
gestureState,
346349
});
347350
this.handlePanResponderEnd(e, gestureState);
348351
}

docs/SwipeListView.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ A List that renders `<SwipeRow />`s
3333
| `swipeToOpenVelocityContribution` | Describes how much the ending velocity of the gesture affects whether the swipe will result in the item being closed or open. A velocity factor of 0 (the default) means that the velocity will have no bearing on whether the swipe settles on a closed or open position and it'll just take into consideration the swipeToOpenPercent. Ideal values for this prop tend to be between 5 and 15. | `number` | | `0` |
3434
| `recalculateHiddenLayout` | Enable hidden row onLayout calculations to run always. By default, hidden row size calculations are only done on the first onLayout event for performance reasons. Passing ```true``` here will cause calculations to run on every onLayout event. You may want to do this if your rows' sizes can change. One case is a SwipeListView with rows of different heights and an options to delete rows. | `bool` | | `false` |
3535
| `swipeGestureBegan` | Called when a swipe row is animating swipe | `func` | `{ rowKey: string } : void` |
36-
| `swipeGestureEnded` | Called when user has ended their swipe gesture | `func` | `{ rowKey: string, data: { translateX: number; } } : void` |
36+
| `swipeGestureEnded` | Called when user has ended their swipe gesture | `func` | `{ rowKey: string; data: { translateX: number; direction: 'left' \| 'right'; event: GestureResponderEvent; gestureState: PanResponderGestureState; } } : void` |
3737
| `onRowOpen` | Called when a swipe row is animating open. This has a param of `toValue` which is the new X value the row (after it has opened). This can be used to calculate which direction the row has been swiped open. | `func` | `{ rowKey: string, rowMap: { string: SwipeRowRef }, toValue: number } : void` |
3838
| `onRowDidOpen` | Called when a swipe row has animated open | `func` | `{ rowKey: string, rowMap: { string: SwipeRowRef }, toValue: number } : void` |
3939
| `onRowClose` | Called when a swipe row is animating closed | `func` | `{ rowKey: string, rowMap: { string: SwipeRowRef } } : void` |

docs/SwipeRow.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ e.g.
5454
| `previewOpenValue` | TranslateX value for the slide out preview animation | `number` | | 0.5 * props.rightOpenValue |
5555
| `onSwipeValueChange` | Callback invoked any time the translateX value of the row changes | `func` | <code>{ swipeData: { key: string, value: number, direction: 'left' &#124; 'right', isOpen: bool } } : void</code> |
5656
| `swipeGestureBegan` | Called when the row is animating swipe | `func` | `{ } : void` |
57-
| `swipeGestureEnded` | Called when user has ended their swipe gesture | `func` | `{ data: { translateX: number; } } : void`
57+
| `swipeGestureEnded` | Called when user has ended their swipe gesture | `func` | `{ rowKey: string; data: { translateX: number; direction: 'left' \| 'right'; event: GestureResponderEvent; gestureState: PanResponderGestureState; } } : void` |
5858
| `swipeToOpenVelocityContribution` | Describes how much the ending velocity of the gesture affects whether the swipe will result in the item being closed or open. A velocity factor of 0 (the default) means that the velocity will have no bearing on whether the swipe settles on a closed or open position and it'll just take into consideration the swipeToOpenPercent. Ideal values for this prop tend to be between 5 and 15. | `number` | | `0` |
5959
| `shouldItemUpdate` | Callback to determine whether component should update | `func` | `{ currentItem: any, newItem: any }` |
6060
| `forceCloseToLeftThreshold` | TranslateX amount(not value!) threshold that triggers force-closing the row to the Left End (positive number) | `number` |

types/index.d.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { Component } from 'react';
2-
import { StyleProp, ViewStyle, ListView, NativeSyntheticEvent, NativeScrollEvent, ListRenderItemInfo, ListViewDataSource, SectionListProps, FlatListProps } from 'react-native';
2+
import { StyleProp, ViewStyle, ListView, NativeSyntheticEvent, NativeScrollEvent, ListRenderItemInfo, ListViewDataSource, SectionListProps, FlatListProps, GestureResponderEvent, PanResponderGestureState } from 'react-native';
3+
4+
type SwipeGestureEndedData = {
5+
translateX: number;
6+
direction: 'left' | 'right';
7+
event: GestureResponderEvent;
8+
gestureState: PanResponderGestureState;
9+
}
310

411
interface IPropsSwipeRow<T> {
512
/**
@@ -14,7 +21,7 @@ interface IPropsSwipeRow<T> {
1421
/**
1522
* Called when user has ended their swipe gesture
1623
*/
17-
swipeGestureEnded(data: { translateX: number; }): void;
24+
swipeGestureEnded(swipeKey: string, data: SwipeGestureEndedData): void;
1825
/**
1926
* Called when a swipe row is animating open. Used by the SwipeListView
2027
* to keep references to open rows.
@@ -327,7 +334,7 @@ interface IPropsSwipeListView<T> {
327334
/**
328335
* Called when user has ended their swipe gesture
329336
*/
330-
swipeGestureEnded(rowKey: string, data: { translateX: number; }): void;
337+
swipeGestureEnded(rowKey: string, data: SwipeGestureEndedData): void;
331338
/**
332339
* Called when a swipe row is animating open
333340
*/

0 commit comments

Comments
 (0)