@@ -8,9 +8,7 @@ import type {Element as ReactElement, Node as ReactNode} from 'react';
88type Axis = 'both' | 'x' | 'y' | 'none' ;
99type ResizeHandle = 's' | 'w' | 'e' | 'n' | 'sw' | 'nw' | 'se' | 'ne' ;
1010type State = {
11- resizing : boolean ,
12- width : number , height : number ,
13- slackW : number , slackH : number
11+ slackW : number , slackH : number ,
1412} ;
1513type DragCallbackData = {
1614 node : HTMLElement ,
@@ -109,22 +107,9 @@ export default class Resizable extends React.Component<Props, State> {
109107 } ;
110108
111109 state : State = {
112- resizing : false ,
113- width : this . props . width , height : this . props . height ,
114110 slackW : 0 , slackH : 0
115111 } ;
116112
117- componentWillReceiveProps ( nextProps : Object ) {
118- // If parent changes height/width, set that in our state.
119- if ( ! this . state . resizing &&
120- ( nextProps . width !== this . props . width || nextProps . height !== this . props . height ) ) {
121- this . setState ( {
122- width : nextProps . width ,
123- height : nextProps . height
124- } ) ;
125- }
126- }
127-
128113 lockAspectRatio ( width : number , height : number , aspectRatio : number ) : [ number , number ] {
129114 height = width / aspectRatio ;
130115 width = height * aspectRatio ;
@@ -134,23 +119,23 @@ export default class Resizable extends React.Component<Props, State> {
134119 // If you do this, be careful of constraints
135120 runConstraints ( width : number , height : number ) : [ number , number ] {
136121 const [ min , max ] = [ this . props . minConstraints , this . props . maxConstraints ] ;
122+ if ( ! min && ! max ) return [ width , height ] ;
137123
124+ // Fit width & height to aspect ratio
138125 if ( this . props . lockAspectRatio ) {
139- if ( height === this . state . height ) {
140- const ratio = this . state . width / this . state . height ;
126+ if ( height === this . props . height ) {
127+ const ratio = this . props . width / this . props . height ;
141128 height = width / ratio ;
142129 width = height * ratio ;
143130 } else {
144131 // Take into account vertical resize with N/S handles on locked aspect
145132 // ratio. Calculate the change height-first, instead of width-first
146- const ratio = this . state . height / this . state . width ;
133+ const ratio = this . props . height / this . props . width ;
147134 width = height / ratio ;
148135 height = width * ratio ;
149136 }
150137 }
151138
152- if ( ! min && ! max ) return [ width , height ] ;
153-
154139 const [ oldW , oldH ] = [ width , height ] ;
155140
156141 // Add slack to the values used to calculate bound position. This will ensure that if
@@ -201,27 +186,24 @@ export default class Resizable extends React.Component<Props, State> {
201186 }
202187
203188 // Update w/h
204- let width = this . state . width + ( canDragX ? deltaX : 0 ) ;
205- let height = this . state . height + ( canDragY ? deltaY : 0 ) ;
189+ let width = this . props . width + ( canDragX ? deltaX : 0 ) ;
190+ let height = this . props . height + ( canDragY ? deltaY : 0 ) ;
206191
207192 // Early return if no change
208- const widthChanged = width !== this . state . width , heightChanged = height !== this . state . height ;
193+ const widthChanged = width !== this . props . width , heightChanged = height !== this . props . height ;
209194 if ( handlerName === 'onResize' && ! widthChanged && ! heightChanged ) return ;
210195
211196 [ width , height ] = this . runConstraints ( width , height ) ;
212197
213198 // Set the appropriate state for this handler.
214199 const newState = { } ;
215200 if ( handlerName === 'onResizeStart' ) {
216- newState . resizing = true ;
201+ // nothing
217202 } else if ( handlerName === 'onResizeStop' ) {
218- newState . resizing = false ;
219203 newState . slackW = newState . slackH = 0 ;
220204 } else {
221205 // Early return if no change after constraints
222- if ( width === this . state . width && height === this . state . height ) return ;
223- newState . width = width ;
224- newState . height = height ;
206+ if ( width === this . props . width && height === this . props . height ) return ;
225207 }
226208
227209 const hasCb = typeof this . props [ handlerName ] === 'function' ;
0 commit comments