@@ -41,13 +41,23 @@ export const Resizable : React.FC<IProps> = (props) => {
4141 const startTouchResize = ( e : React . TouchEvent < HTMLDivElement > ) => {
4242 const originalTouchX = props . type === ResizeType . Left ? e . touches [ 0 ] . pageX + props . adjustedSize : e . touches [ 0 ] . pageX - props . adjustedSize ;
4343 const originalTouchY = props . type === ResizeType . Top ? e . touches [ 0 ] . pageY + props . adjustedSize : e . touches [ 0 ] . pageY - props . adjustedSize ;
44+ let lastX = 0 ;
45+ let lastY = 0 ;
4446 let resizing = true ;
4547 let moved = false ;
4648
47- const touchResize = ( e : TouchEvent ) => resizing && resize ( originalTouchX , originalTouchY , e . touches [ 0 ] . pageX , e . touches [ 0 ] . pageY ) ;
49+ const touchResize = ( x : number , y : number ) => resizing && resize ( originalTouchX , originalTouchY , x , y ) ;
4850 const throttledTouchResize = throttle < typeof touchResize > ( touchResize , RESIZE_THROTTLE ) ;
49- const withPreventDefault = ( e : TouchEvent ) => { moved = true ; e . preventDefault ( ) ; e . stopImmediatePropagation ( ) ; throttledTouchResize ( e ) ; } ;
51+ const withPreventDefault = ( e : TouchEvent ) => {
52+ moved = true ;
53+ lastX = e . touches [ 0 ] . pageX ;
54+ lastY = e . touches [ 0 ] . pageY ;
55+ e . preventDefault ( ) ;
56+ e . stopImmediatePropagation ( ) ;
57+ throttledTouchResize ( lastX , lastY ) ;
58+ } ;
5059 const removeListener = ( ) => {
60+ touchResize ( lastX , lastY ) ;
5161 resizing = false ;
5262 window . removeEventListener ( 'touchmove' , withPreventDefault ) ;
5363 window . removeEventListener ( 'touchend' , removeListener ) ;
@@ -63,13 +73,23 @@ export const Resizable : React.FC<IProps> = (props) => {
6373 const startResize = ( e : React . MouseEvent < HTMLDivElement , MouseEvent > ) => {
6474 const originalMouseX = props . type === ResizeType . Left ? e . pageX + props . adjustedSize : e . pageX - props . adjustedSize ;
6575 const originalMouseY = props . type === ResizeType . Top ? e . pageY + props . adjustedSize : e . pageY - props . adjustedSize ;
76+ let lastX = 0 ;
77+ let lastY = 0 ;
6678 let resizing = true ;
6779 let moved = false ;
6880
69- const mouseResize = ( e : MouseEvent ) => resizing && resize ( originalMouseX , originalMouseY , e . pageX , e . pageY ) ;
81+ const mouseResize = ( x : number , y : number ) => resizing && resize ( originalMouseX , originalMouseY , x , y ) ;
7082 const throttledMouseResize = throttle < typeof mouseResize > ( mouseResize , RESIZE_THROTTLE ) ;
71- const withPreventDefault = ( e : MouseEvent ) => { moved = true ; e . preventDefault ( ) ; e . stopImmediatePropagation ( ) ; throttledMouseResize ( e ) ; } ;
83+ const withPreventDefault = ( e : MouseEvent ) => {
84+ moved = true ;
85+ lastX = e . pageX ;
86+ lastY = e . pageY ;
87+ e . preventDefault ( ) ;
88+ e . stopImmediatePropagation ( ) ;
89+ throttledMouseResize ( lastX , lastY ) ;
90+ } ;
7291 const removeListener = ( ) => {
92+ mouseResize ( lastX , lastY ) ;
7393 resizing = false ;
7494 window . removeEventListener ( 'mousemove' , withPreventDefault ) ;
7595 window . removeEventListener ( 'mouseup' , removeListener ) ;
0 commit comments