Skip to content

Commit f22ada3

Browse files
authored
Fix onUp in Fling (#2709)
## Description Fling gesture ends when pointer was moved farther than minimum distance. The problem is that `onUp` method calls `endFling` after pointer was removed from tracker. This means that calling `this.tracker.getLastX(this.keyPointer)` (the same for `Y` position) inside `tryEndFling` will return undefined. It is rather cosmetic change - it doesn't really affect behavior since we call `tryEndFling` inside `onPointerMove`. This PR also changes minimum distance the pointer has to travel, since `160` is way to big. ## Test plan <details> <summary> Tested on the following code </summary> ```jsx import React from 'react'; import { View, StyleSheet } from 'react-native'; import { Gesture, GestureDetector } from 'react-native-gesture-handler'; export default function App() { const f = Gesture.Fling() .onEnd((e) => console.log(e)) .onFinalize((e, s) => console.log(e, s)); return ( <View style={styles.container}> <GestureDetector gesture={f}> <View style={styles.box} /> </GestureDetector> </View> ); } const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', justifyContent: 'center', backgroundColor: '#ecf0f1', padding: 8, }, box: { width: 500, height: 500, backgroundColor: 'blue', }, }); ``` </details>
1 parent b4eba25 commit f22ada3

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/web/handlers/FlingGestureHandler.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { AdaptedEvent, Config } from '../interfaces';
55
import GestureHandler from './GestureHandler';
66

77
const DEFAULT_MAX_DURATION_MS = 800;
8-
const DEFAULT_MIN_ACCEPTABLE_DELTA = 160;
8+
const DEFAULT_MIN_ACCEPTABLE_DELTA = 32;
99
const DEFAULT_DIRECTION = Direction.RIGHT;
1010
const DEFAULT_NUMBER_OF_TOUCHES_REQUIRED = 1;
1111

@@ -141,11 +141,11 @@ export default class FlingGestureHandler extends GestureHandler {
141141
}
142142

143143
private onUp(event: AdaptedEvent): void {
144-
this.tracker.removeFromTracker(event.pointerId);
145-
if (this.currentState !== State.BEGAN) {
146-
return;
144+
if (this.currentState === State.BEGAN) {
145+
this.endFling();
147146
}
148-
this.endFling();
147+
148+
this.tracker.removeFromTracker(event.pointerId);
149149
}
150150

151151
public activate(force?: boolean): void {

0 commit comments

Comments
 (0)