Commit 2de57ac
authored
[Android] Fix
## Description
Follow-up to #4327
On Android, `Pan`'s `updateConfig` derived `hasCustomActivationCriteria`
from a local variable recomputed from the keys present in the incoming
config map. Config updates can be partial a `SharedValue` used in the
config sends `{ [key]: value }` through `updateGestureHandlerConfig`,
which doesn't reset the handler first - so the flag reflected a single
update message instead of the accumulated configuration. Any
criteria-key update (velocity/offset) then hit the "custom criteria and
no explicit `minDist`" branch and masked an explicitly configured
`minDistance` with `Float.MAX_VALUE`, disabling distance-based
activation entirely.
`hasCustomActivationCriteria` is now a field on the handler, together
with `hasExplicitMinDist` tracking whether `minDist` was explicitly
configured; both are cleared in `resetConfig`. This mirrors how the
other platforms already model this state (web: instance field + stored
`minDist`; iOS: flag recomputed from stored recognizer state in
`updateHasCustomActivationCriteria`), which is why they don't exhibit
the bug. Full-config paths (`createGestureHandler` /
`setGestureHandlerConfig`) go through `resetConfig` first, so their
behavior is unchanged.
## Test plan
<details>
<summary>Tested on the following code:</summary>
```tsx
import React, { useState } from 'react';
import { Button, StyleSheet, Text, View } from 'react-native';
import { GestureDetector, usePanGesture } from 'react-native-gesture-handler';
import { useSharedValue } from 'react-native-reanimated';
export default function MinDistReset() {
const [log, setLog] = useState<string[]>([]);
const minVelocityY = useSharedValue(10000);
const append = (entry: string) =>
setLog((prev) => [...prev.slice(-8), entry]);
const pan = usePanGesture({
minDistance: 50,
minVelocityY,
runOnJS: true,
onActivate: () => {
append('ACTIVATED');
},
onFinalize: (e) => {
if (e.canceled) {
append('finished without activation');
}
},
});
return (
<View style={styles.container}>
<Text style={styles.title}>
minDistance = 50, minVelocityY = SharedValue(10000)
</Text>
<Text style={styles.hint}>
Slow 50pt+ drag should ACTIVATE — also after poking the shared value.
</Text>
<Button
title="poke shared value"
onPress={() => {
// Render-silent on purpose - see the note at the top of the file.
minVelocityY.value = minVelocityY.value === 9000 ? 9001 : 9000;
console.log('poked: minVelocityY ->', minVelocityY.value);
}}
/>
<GestureDetector gesture={pan}>
<View style={styles.box} testID="panBox">
<Text style={styles.boxLabel}>drag here</Text>
</View>
</GestureDetector>
<View style={styles.log}>
{log.map((entry, i) => (
<Text key={i} style={styles.logLine}>
{entry}
</Text>
))}
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
paddingTop: 16,
},
title: {
fontSize: 16,
fontWeight: 'bold',
},
hint: {
textAlign: 'center',
marginVertical: 12,
color: '#666',
},
box: {
width: 300,
height: 300,
backgroundColor: 'tomato',
borderRadius: 16,
justifyContent: 'center',
alignItems: 'center',
marginTop: 12,
},
boxLabel: {
color: 'white',
fontSize: 18,
},
log: {
marginTop: 20,
minHeight: 160,
alignSelf: 'stretch',
paddingHorizontal: 24,
},
logLine: {
fontFamily: 'monospace',
fontSize: 13,
},
});
```
</details>minDistance being reset by partial config updates (#4347)1 parent bd9650f commit 2de57ac
1 file changed
Lines changed: 23 additions & 14 deletions
File tree
- packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core
Lines changed: 23 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
30 | 36 | | |
31 | 37 | | |
32 | 38 | | |
| |||
90 | 96 | | |
91 | 97 | | |
92 | 98 | | |
| 99 | + | |
| 100 | + | |
93 | 101 | | |
94 | 102 | | |
95 | 103 | | |
| |||
270 | 278 | | |
271 | 279 | | |
272 | 280 | | |
273 | | - | |
274 | 281 | | |
275 | 282 | | |
276 | 283 | | |
277 | 284 | | |
278 | 285 | | |
279 | 286 | | |
280 | 287 | | |
281 | | - | |
| 288 | + | |
282 | 289 | | |
283 | 290 | | |
284 | 291 | | |
| |||
287 | 294 | | |
288 | 295 | | |
289 | 296 | | |
290 | | - | |
| 297 | + | |
291 | 298 | | |
292 | 299 | | |
293 | 300 | | |
| |||
296 | 303 | | |
297 | 304 | | |
298 | 305 | | |
299 | | - | |
| 306 | + | |
300 | 307 | | |
301 | 308 | | |
302 | 309 | | |
| |||
305 | 312 | | |
306 | 313 | | |
307 | 314 | | |
308 | | - | |
| 315 | + | |
309 | 316 | | |
310 | 317 | | |
311 | 318 | | |
| |||
314 | 321 | | |
315 | 322 | | |
316 | 323 | | |
317 | | - | |
| 324 | + | |
318 | 325 | | |
319 | 326 | | |
320 | 327 | | |
| |||
323 | 330 | | |
324 | 331 | | |
325 | 332 | | |
326 | | - | |
| 333 | + | |
327 | 334 | | |
328 | 335 | | |
329 | 336 | | |
| |||
332 | 339 | | |
333 | 340 | | |
334 | 341 | | |
335 | | - | |
| 342 | + | |
336 | 343 | | |
337 | 344 | | |
338 | 345 | | |
| |||
341 | 348 | | |
342 | 349 | | |
343 | 350 | | |
344 | | - | |
| 351 | + | |
345 | 352 | | |
346 | 353 | | |
347 | 354 | | |
348 | 355 | | |
349 | 356 | | |
350 | | - | |
| 357 | + | |
351 | 358 | | |
352 | 359 | | |
353 | 360 | | |
354 | | - | |
| 361 | + | |
355 | 362 | | |
356 | 363 | | |
357 | 364 | | |
358 | | - | |
| 365 | + | |
359 | 366 | | |
360 | 367 | | |
361 | 368 | | |
362 | | - | |
| 369 | + | |
| 370 | + | |
363 | 371 | | |
364 | 372 | | |
365 | | - | |
| 373 | + | |
| 374 | + | |
366 | 375 | | |
367 | 376 | | |
368 | 377 | | |
| |||
0 commit comments