@@ -6,6 +6,7 @@ import * as PropTypes from 'prop-types';
66
77interface IProps {
88 type : ResizeType ,
9+ adjustedSize : number ,
910 width ?: number ,
1011 height ?: number ,
1112 minimumAdjust : number ,
@@ -14,8 +15,6 @@ interface IProps {
1415}
1516
1617export const Resizable : React . FC < IProps > = ( props ) => {
17- const [ adjustedSize , setAdjustedSize ] = React . useState ( 0 ) ;
18-
1918 const resize = ( originalX : number , originalY : number , x : number , y : number ) => {
2019 const adjustmentX =
2120 Math . min (
@@ -29,15 +28,14 @@ export const Resizable : React.FC<IProps> = (props) => {
2928 ) ;
3029 const adjustment = props . type === ResizeType . Left || props . type === ResizeType . Right ? adjustmentX : adjustmentY ;
3130
32- if ( adjustment !== adjustedSize ) {
33- setAdjustedSize ( adjustment ) ;
31+ if ( adjustment !== props . adjustedSize ) {
3432 props . onResize ( adjustment ) ;
3533 }
3634 }
3735
3836 const startTouchResize = ( e : React . TouchEvent < HTMLDivElement > ) => {
39- const originalTouchX = props . type === ResizeType . Left ? e . touches [ 0 ] . pageX + adjustedSize : e . touches [ 0 ] . pageX - adjustedSize ;
40- const originalTouchY = props . type === ResizeType . Top ? e . touches [ 0 ] . pageY + adjustedSize : e . touches [ 0 ] . pageY - adjustedSize ;
37+ const originalTouchX = props . type === ResizeType . Left ? e . touches [ 0 ] . pageX + props . adjustedSize : e . touches [ 0 ] . pageX - props . adjustedSize ;
38+ const originalTouchY = props . type === ResizeType . Top ? e . touches [ 0 ] . pageY + props . adjustedSize : e . touches [ 0 ] . pageY - props . adjustedSize ;
4139
4240 const touchResize = ( e : TouchEvent ) => resize ( originalTouchX , originalTouchY , e . touches [ 0 ] . pageX , e . touches [ 0 ] . pageY ) ;
4341 const debouncedTouchResize = debounce < typeof touchResize > ( touchResize , 10 ) ;
@@ -49,8 +47,8 @@ export const Resizable : React.FC<IProps> = (props) => {
4947 }
5048
5149 const startResize = ( e : React . MouseEvent < HTMLDivElement , MouseEvent > ) => {
52- const originalMouseX = props . type === ResizeType . Left ? e . pageX + adjustedSize : e . pageX - adjustedSize ;
53- const originalMouseY = props . type === ResizeType . Top ? e . pageY + adjustedSize : e . pageY - adjustedSize ;
50+ const originalMouseX = props . type === ResizeType . Left ? e . pageX + props . adjustedSize : e . pageX - props . adjustedSize ;
51+ const originalMouseY = props . type === ResizeType . Top ? e . pageY + props . adjustedSize : e . pageY - props . adjustedSize ;
5452
5553 const mouseResize = ( e : MouseEvent ) => resize ( originalMouseX , originalMouseY , e . pageX , e . pageY ) ;
5654 const debouncedMouseResize = debounce < typeof mouseResize > ( mouseResize , 10 ) ;
0 commit comments