@@ -50,7 +50,7 @@ export const LayeredImage: React.FC<ILayeredImageProps> = ({
5050 style,
5151} ) => {
5252 const [ size , setSize ] = useState < Size > ( { width : 0 , height : 0 } )
53- const [ interaction , setInteraction ] = useState < Interaction > ( Interaction . None )
53+ const interactionRef = useRef < Interaction > ( Interaction . None )
5454 const [ loaded , setLoaded ] = useState < number > ( 0 )
5555 const [ , setError ] = useState < number > ( 0 )
5656
@@ -119,13 +119,13 @@ export const LayeredImage: React.FC<ILayeredImageProps> = ({
119119 }
120120
121121 const computeStyles = (
122- _interaction : Interaction = interaction ,
122+ interaction : Interaction = interactionRef . current ,
123123 event ?: React . SyntheticEvent < HTMLDivElement > ,
124124 pageX ?: number ,
125125 pageY ?: number ,
126126 preventDefault = false ,
127127 ) => {
128- const { width, height } = _interaction === Interaction . Resize ? getDimensions ( ) : size
128+ const { width, height } = interaction === Interaction . Resize ? getDimensions ( ) : size
129129
130130 const scrollLeft =
131131 document . documentElement . scrollLeft ||
@@ -200,7 +200,7 @@ export const LayeredImage: React.FC<ILayeredImageProps> = ({
200200 transitionDuration : "0.075s" ,
201201 } ,
202202 } ,
203- } [ _interaction ]
203+ } [ interaction ]
204204
205205 if ( preventDefault ) {
206206 event . preventDefault ( )
@@ -216,21 +216,24 @@ export const LayeredImage: React.FC<ILayeredImageProps> = ({
216216 }
217217 }
218218
219- setSize ( { width, height } )
220- setInteraction ( _interaction )
219+ if ( interaction === Interaction . Resize ) {
220+ setSize ( { width, height } )
221+ }
222+
223+ interactionRef . current = interaction
221224 }
222225
223226 // prettier-ignore
224227 const handleMouseInteraction =
225- ( _interaction ?: Interaction ) =>
228+ ( interaction ?: Interaction ) =>
226229 ( event : React . MouseEvent < HTMLDivElement > ) =>
227- computeStyles ( _interaction , event , event . pageX , event . pageY , true ) ;
230+ computeStyles ( interaction , event , event . pageX , event . pageY , true ) ;
228231
229232 // prettier-ignore
230233 const handleTouchInteraction =
231- ( _interaction ?: Interaction ) =>
234+ ( interaction ?: Interaction ) =>
232235 ( event : React . TouchEvent < HTMLDivElement > ) =>
233- computeStyles ( _interaction , event , event . touches [ 0 ] . pageX , event . touches [ 0 ] . pageY ) ;
236+ computeStyles ( interaction , event , event . touches [ 0 ] . pageX , event . touches [ 0 ] . pageY ) ;
234237
235238 const handleInteractionEnd = ( ) => computeStyles ( Interaction . None )
236239
0 commit comments