@@ -7,19 +7,15 @@ import {
7
7
type ForwardRefRenderFunction ,
8
8
} from 'react' ;
9
9
import { View , StyleSheet , type ViewStyle } from 'react-native' ;
10
- import {
11
- PanGestureHandler ,
12
- GestureHandlerRootView ,
13
- type PanGestureHandlerGestureEvent ,
14
- } from 'react-native-gesture-handler' ;
10
+ import { GestureHandlerRootView } from 'react-native-gesture-handler' ;
15
11
import Animated , {
16
12
useAnimatedStyle ,
17
13
useSharedValue ,
18
14
useDerivedValue ,
19
15
runOnJS ,
20
16
type SharedValue ,
21
- useAnimatedGestureHandler ,
22
17
} from 'react-native-reanimated' ;
18
+ import { Gesture , GestureDetector } from 'react-native-gesture-handler' ;
23
19
import type { RangeSliderProps } from './types' ;
24
20
25
21
// ================ Constants ================
@@ -56,11 +52,6 @@ interface PressedState {
56
52
right : boolean ;
57
53
}
58
54
59
- interface GestureContext {
60
- startX : number ;
61
- [ key : string ] : unknown ;
62
- }
63
-
64
55
// ================ Styles ================
65
56
const styles = StyleSheet . create ( {
66
57
markerContainer : {
@@ -283,22 +274,19 @@ const RangeSlider: ForwardRefRenderFunction<View, RangeSliderProps> = (
283
274
[ onValuesChange ]
284
275
) ;
285
276
286
- const leftGesture = useAnimatedGestureHandler <
287
- PanGestureHandlerGestureEvent ,
288
- GestureContext
289
- > ( {
290
- onStart : ( _ : any , ctx : GestureContext ) => {
277
+ const leftGesture = Gesture . Pan ( )
278
+ . hitSlop ( TOUCH_HITSLOP )
279
+ . onStart ( ( ) => {
291
280
'worklet' ;
292
281
if ( ! enabled ) return ;
293
- ctx . startX = leftPos . value ;
294
282
runOnJS ( setPressed ) ( { left : true , right : false } ) ;
295
283
runOnJS ( onValuesChangeStart ) ( updateValues ( leftPos . value , rightPos . value ) ) ;
296
- } ,
297
- onActive : ( event : any , ctx : GestureContext ) => {
284
+ } )
285
+ . onUpdate ( ( event ) => {
298
286
'worklet' ;
299
287
if ( ! enabled ) return ;
300
288
301
- const position = ctx . startX + event . translationX ;
289
+ const position = leftOffset . value + event . translationX ;
302
290
const minPosition = HORIZONTAL_PADDING ;
303
291
const maxPosition = allowOverlap
304
292
? rightPos . value
@@ -309,14 +297,12 @@ const RangeSlider: ForwardRefRenderFunction<View, RangeSliderProps> = (
309
297
Math . min ( maxPosition , position )
310
298
) ;
311
299
312
- // Update position directly without animation
313
300
leftPos . value = clampedPosition ;
314
- leftOffset . value = clampedPosition ;
315
301
316
302
const newValues = updateValues ( clampedPosition , rightPos . value ) ;
317
303
runOnJS ( updateOutputValues ) ( newValues ) ;
318
- } ,
319
- onEnd : ( ) => {
304
+ } )
305
+ . onEnd ( ( ) => {
320
306
'worklet' ;
321
307
if ( ! enabled ) return ;
322
308
@@ -329,25 +315,21 @@ const RangeSlider: ForwardRefRenderFunction<View, RangeSliderProps> = (
329
315
330
316
runOnJS ( onValuesChangeFinish ) ( values ) ;
331
317
runOnJS ( setPressed ) ( { left : false , right : false } ) ;
332
- } ,
333
- } ) ;
318
+ } ) ;
334
319
335
- const rightGesture = useAnimatedGestureHandler <
336
- PanGestureHandlerGestureEvent ,
337
- GestureContext
338
- > ( {
339
- onStart : ( _ : any , ctx : GestureContext ) => {
320
+ const rightGesture = Gesture . Pan ( )
321
+ . hitSlop ( TOUCH_HITSLOP )
322
+ . onStart ( ( ) => {
340
323
'worklet' ;
341
324
if ( ! enabled ) return ;
342
- ctx . startX = rightPos . value ;
343
325
runOnJS ( setPressed ) ( { left : false , right : true } ) ;
344
326
runOnJS ( onValuesChangeStart ) ( updateValues ( leftPos . value , rightPos . value ) ) ;
345
- } ,
346
- onActive : ( event : any , ctx : GestureContext ) => {
327
+ } )
328
+ . onUpdate ( ( event ) => {
347
329
'worklet' ;
348
330
if ( ! enabled ) return ;
349
331
350
- const position = ctx . startX + event . translationX ;
332
+ const position = rightOffset . value + event . translationX ;
351
333
const minPosition = allowOverlap
352
334
? leftPos . value
353
335
: leftPos . value + minimumDistance ;
@@ -358,14 +340,12 @@ const RangeSlider: ForwardRefRenderFunction<View, RangeSliderProps> = (
358
340
Math . min ( maxPosition , position )
359
341
) ;
360
342
361
- // Update position directly without animation
362
343
rightPos . value = clampedPosition ;
363
- rightOffset . value = clampedPosition ;
364
344
365
345
const newValues = updateValues ( leftPos . value , clampedPosition ) ;
366
346
runOnJS ( updateOutputValues ) ( newValues ) ;
367
- } ,
368
- onEnd : ( ) => {
347
+ } )
348
+ . onEnd ( ( ) => {
369
349
'worklet' ;
370
350
if ( ! enabled ) return ;
371
351
@@ -378,8 +358,7 @@ const RangeSlider: ForwardRefRenderFunction<View, RangeSliderProps> = (
378
358
379
359
runOnJS ( onValuesChangeFinish ) ( values ) ;
380
360
runOnJS ( setPressed ) ( { left : false , right : false } ) ;
381
- } ,
382
- } ) ;
361
+ } ) ;
383
362
384
363
// Update positions only when initial values change externally
385
364
useEffect ( ( ) => {
@@ -427,65 +406,63 @@ const RangeSlider: ForwardRefRenderFunction<View, RangeSliderProps> = (
427
406
] }
428
407
/>
429
408
430
- < PanGestureHandler
431
- onGestureEvent = { leftGesture }
432
- hitSlop = { TOUCH_HITSLOP }
433
- minDist = { 0 }
434
- activeOffsetX = { [ - 10 , 10 ] }
409
+ < Animated . View
410
+ style = { [
411
+ dynamicStyles . thumb ,
412
+ styles . markerContainer ,
413
+ thumbStyle ,
414
+ pressed . left && pressedThumbStyle ,
415
+ leftThumbStyle ,
416
+ ] }
435
417
>
436
- < Animated . View
437
- accessible = { true }
438
- accessibilityLabel = { leftThumbAccessibilityLabel }
439
- accessibilityRole = "adjustable"
440
- style = { [
441
- dynamicStyles . thumb ,
442
- styles . markerContainer ,
443
- thumbStyle ,
444
- pressed . left && pressedThumbStyle ,
445
- leftThumbStyle ,
446
- ] }
447
- >
448
- < View style = { staticStyles . thumbInner } >
449
- { showThumbLines && (
450
- < >
451
- < View style = { staticStyles . markerLine } />
452
- < View style = { staticStyles . markerLine } />
453
- < View style = { staticStyles . markerLine } />
454
- </ >
455
- ) }
456
- </ View >
457
- </ Animated . View >
458
- </ PanGestureHandler >
459
-
460
- < PanGestureHandler
461
- onGestureEvent = { rightGesture }
462
- hitSlop = { TOUCH_HITSLOP }
463
- minDist = { 0 }
464
- activeOffsetX = { [ - 10 , 10 ] }
418
+ < GestureDetector gesture = { leftGesture } >
419
+ < Animated . View
420
+ accessible = { true }
421
+ accessibilityLabel = { leftThumbAccessibilityLabel }
422
+ accessibilityRole = "adjustable"
423
+ style = { [ { width : '100%' , height : '100%' } ] }
424
+ >
425
+ < View style = { staticStyles . thumbInner } >
426
+ { showThumbLines && (
427
+ < >
428
+ < View style = { staticStyles . markerLine } />
429
+ < View style = { staticStyles . markerLine } />
430
+ < View style = { staticStyles . markerLine } />
431
+ </ >
432
+ ) }
433
+ </ View >
434
+ </ Animated . View >
435
+ </ GestureDetector >
436
+ </ Animated . View >
437
+
438
+ < Animated . View
439
+ style = { [
440
+ dynamicStyles . thumb ,
441
+ styles . markerContainer ,
442
+ thumbStyle ,
443
+ pressed . right && pressedThumbStyle ,
444
+ rightThumbStyle ,
445
+ ] }
465
446
>
466
- < Animated . View
467
- accessible = { true }
468
- accessibilityLabel = { rightThumbAccessibilityLabel }
469
- accessibilityRole = "adjustable"
470
- style = { [
471
- dynamicStyles . thumb ,
472
- styles . markerContainer ,
473
- thumbStyle ,
474
- pressed . right && pressedThumbStyle ,
475
- rightThumbStyle ,
476
- ] }
477
- >
478
- < View style = { staticStyles . thumbInner } >
479
- { showThumbLines && (
480
- < >
481
- < View style = { staticStyles . markerLine } />
482
- < View style = { staticStyles . markerLine } />
483
- < View style = { staticStyles . markerLine } />
484
- </ >
485
- ) }
486
- </ View >
487
- </ Animated . View >
488
- </ PanGestureHandler >
447
+ < GestureDetector gesture = { rightGesture } >
448
+ < Animated . View
449
+ accessible = { true }
450
+ accessibilityLabel = { rightThumbAccessibilityLabel }
451
+ accessibilityRole = "adjustable"
452
+ style = { [ { width : '100%' , height : '100%' } ] }
453
+ >
454
+ < View style = { staticStyles . thumbInner } >
455
+ { showThumbLines && (
456
+ < >
457
+ < View style = { staticStyles . markerLine } />
458
+ < View style = { staticStyles . markerLine } />
459
+ < View style = { staticStyles . markerLine } />
460
+ </ >
461
+ ) }
462
+ </ View >
463
+ </ Animated . View >
464
+ </ GestureDetector >
465
+ </ Animated . View >
489
466
</ View >
490
467
</ GestureHandlerRootView >
491
468
) ;
0 commit comments