@@ -25,16 +25,17 @@ export default function InteractiveAnimations({
2525 if ( ! el ) return ;
2626
2727 let dragging = false ;
28-
29- function getCoord ( e : PointerEvent | MouseEvent ) {
30- return ( e as PointerEvent ) . clientX ?? ( e as MouseEvent ) . clientX ;
31- }
28+ const resetCompositorHints = ( ) => {
29+ el . style . willChange = '' ;
30+ } ;
3231
3332 const onPointerDown = ( e : PointerEvent ) => {
3433 dragging = true ;
3534 startRef . current = axis === 'x' ? e . clientX : e . clientY ;
3635 el . setPointerCapture ( e . pointerId ) ;
3736 if ( ctrlRef . current ) ctrlRef . current . stop ( ) ;
37+ el . style . willChange = 'transform' ;
38+ el . style . transform = axis === 'x' ? 'translate3d(0,0,0)' : 'translate3d(0,0,0)' ;
3839 } ;
3940
4041 const onPointerMove = ( e : PointerEvent ) => {
@@ -66,6 +67,10 @@ export default function InteractiveAnimations({
6667 ctrlRef . current = engine . spring ( delta , 0 , ( v ) => {
6768 el . style . transform = axis === 'x' ? `translate3d(${ v } px,0,0)` : `translate3d(0,${ v } px,0)` ;
6869 } ) ;
70+ ctrlRef . current . onStop = ( ) => {
71+ el . style . transform = 'translate3d(0,0,0)' ;
72+ resetCompositorHints ( ) ;
73+ } ;
6974 }
7075 } ;
7176
@@ -77,11 +82,16 @@ export default function InteractiveAnimations({
7782 el . removeEventListener ( 'pointerdown' , onPointerDown ) ;
7883 window . removeEventListener ( 'pointermove' , onPointerMove ) ;
7984 window . removeEventListener ( 'pointerup' , onPointerUp ) ;
85+ resetCompositorHints ( ) ;
8086 } ;
8187 } , [ axis , onDismiss , threshold ] ) ;
8288
8389 return (
84- < div ref = { ref } className = { className } style = { { touchAction : 'pan-y' } } >
90+ < div
91+ ref = { ref }
92+ className = { className }
93+ style = { { touchAction : axis === 'x' ? 'pan-y' : 'pan-x' , transform : 'translate3d(0,0,0)' } }
94+ >
8595 { children }
8696 </ div >
8797 ) ;
0 commit comments