@@ -14,6 +14,18 @@ export function useGestureControls({
1414 const touchStartXRef = useRef ( null ) ;
1515 const touchTargetRef = useRef ( null ) ;
1616
17+ const onSwipeLeftRef = useRef ( onSwipeLeft ) ;
18+ const onSwipeRightRef = useRef ( onSwipeRight ) ;
19+ const onSwipeUpRef = useRef ( onSwipeUp ) ;
20+ const onSwipeDownRef = useRef ( onSwipeDown ) ;
21+
22+ useEffect ( ( ) => {
23+ onSwipeLeftRef . current = onSwipeLeft ;
24+ onSwipeRightRef . current = onSwipeRight ;
25+ onSwipeUpRef . current = onSwipeUp ;
26+ onSwipeDownRef . current = onSwipeDown ;
27+ } ) ;
28+
1729 const isWithinScrollableContainer = ( target ) => {
1830 let current = target ;
1931 while ( current && current !== contentRef ?. current ) {
@@ -91,20 +103,20 @@ export function useGestureControls({
91103 : null ;
92104
93105 if ( isHorizontalSwipe && settings . songChangeGestureEnabled ) {
94- if ( deltaX > 50 && onSwipeLeft ) {
95- onSwipeLeft ( ) ;
96- } else if ( deltaX < - 50 && onSwipeRight ) {
97- onSwipeRight ( ) ;
106+ if ( deltaX > 50 && onSwipeLeftRef . current ) {
107+ onSwipeLeftRef . current ( ) ;
108+ } else if ( deltaX < - 50 && onSwipeRightRef . current ) {
109+ onSwipeRightRef . current ( ) ;
98110 }
99111 } else if (
100112 ! isHorizontalSwipe &&
101113 settings . showLyricsGestureEnabled &&
102114 ! scrollableContainer
103115 ) {
104- if ( deltaY > 50 && onSwipeUp ) {
105- onSwipeUp ( ) ;
106- } else if ( deltaY < - 50 && onSwipeDown ) {
107- onSwipeDown ( ) ;
116+ if ( deltaY > 50 && onSwipeUpRef . current ) {
117+ onSwipeUpRef . current ( ) ;
118+ } else if ( deltaY < - 50 && onSwipeDownRef . current ) {
119+ onSwipeDownRef . current ( ) ;
108120 }
109121 }
110122
@@ -127,9 +139,5 @@ export function useGestureControls({
127139 isActive ,
128140 settings . showLyricsGestureEnabled ,
129141 settings . songChangeGestureEnabled ,
130- onSwipeLeft ,
131- onSwipeRight ,
132- onSwipeUp ,
133- onSwipeDown ,
134142 ] ) ;
135143}
0 commit comments