Skip to content
This repository was archived by the owner on Apr 3, 2025. It is now read-only.

Commit 7320853

Browse files
Merge pull request #125 from laurenashpole/release/3.0.2
Release/3.0.2
2 parents 3506dac + 5cf8081 commit 7320853

File tree

7 files changed

+61
-23
lines changed

7 files changed

+61
-23
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# Changelog
22

3+
## [3.0.2](https://github.com/laurenashpole/react-inner-image-zoom/compare/v3.0.1...v3.0.2) (2022-07-22)
4+
5+
6+
### Fixed
7+
8+
- A bug re-zooming after clicking the close button on non-touch devices when `zoomPreload` is false.
9+
10+
🎉🎉🎉 Special thanks to [MaxDAyala](https://github.com/MaxdAyala) for tackling the following:
11+
12+
- A Firefox error when the zoomed image is dragged to the far left of the container.
13+
- The timing of the fade out `visibility` and `opacity` transitions.
14+
- An intermittent issue where zooming became disabled by panning in and out at a fast speed.
15+
16+
## [3.0.1](https://github.com/laurenashpole/react-inner-image-zoom/compare/v3.0.0...v3.0.1) (2022-06-12)
17+
18+
### Fixed
19+
20+
- Added `prop-types` to the `peerDependencies`.
21+
322
## [3.0.0](https://github.com/laurenashpole/react-inner-image-zoom/compare/v2.1.0...v3.0.0) (2022-01-03)
423

524
### Changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-inner-image-zoom",
3-
"version": "3.0.1",
3+
"version": "3.0.2",
44
"description": "A React component for magnifying an image within its original container.",
55
"main": "lib/index.js",
66
"module": "es/index.js",

src/InnerImageZoom/InnerImageZoom.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const InnerImageZoom = ({
4141

4242
const handleMouseEnter = (e) => {
4343
setIsActive(true);
44+
setIsFading(false);
4445
zoomType === 'hover' && !isZoomed && handleClick(e);
4546
};
4647

@@ -53,7 +54,7 @@ const InnerImageZoom = ({
5354
const handleClick = (e) => {
5455
if (isZoomed) {
5556
if (isTouch) {
56-
hideCloseButton && handleClose();
57+
hideCloseButton && handleClose(e);
5758
} else {
5859
!isValidDrag && zoomOut();
5960
}
@@ -100,12 +101,9 @@ const InnerImageZoom = ({
100101
};
101102

102103
const handleDragStart = (e) => {
103-
imgProps.current.offsets = getOffsets(
104-
e.pageX || e.changedTouches[0].pageX,
105-
e.pageY || e.changedTouches[0].pageY,
106-
zoomImg.current.offsetLeft,
107-
zoomImg.current.offsetTop
108-
);
104+
const pageX = typeof e.pageX === 'number' ? e.pageX : e.changedTouches[0].pageX;
105+
const pageY = typeof e.pageY === 'number' ? e.pageY : e.changedTouches[0].pageY;
106+
imgProps.current.offsets = getOffsets(pageX, pageY, zoomImg.current.offsetLeft, zoomImg.current.offsetTop);
109107

110108
setIsDragging(true);
111109

@@ -119,8 +117,10 @@ const InnerImageZoom = ({
119117

120118
const handleDragMove = useCallback((e) => {
121119
e.stopPropagation();
122-
let left = (e.pageX || e.changedTouches[0].pageX) - imgProps.current.offsets.x;
123-
let top = (e.pageY || e.changedTouches[0].pageY) - imgProps.current.offsets.y;
120+
const pageX = typeof e.pageX === 'number' ? e.pageX : e.changedTouches[0].pageX;
121+
const pageY = typeof e.pageY === 'number' ? e.pageY : e.changedTouches[0].pageY;
122+
let left = pageX - imgProps.current.offsets.x;
123+
let top = pageY - imgProps.current.offsets.y;
124124

125125
left = Math.max(Math.min(left, 0), (imgProps.current.scaledDimensions.width - imgProps.current.bounds.width) * -1);
126126
top = Math.max(Math.min(top, 0), (imgProps.current.scaledDimensions.height - imgProps.current.bounds.height) * -1);
@@ -140,14 +140,16 @@ const InnerImageZoom = ({
140140
};
141141

142142
const handleMouseLeave = (e) => {
143-
currentMoveType === 'drag' && isZoomed ? handleDragEnd(e) : handleClose();
143+
currentMoveType === 'drag' && isZoomed ? handleDragEnd(e) : handleClose(e);
144144
};
145145

146-
const handleClose = () => {
147-
if (!isZoomed || isFullscreen || !fadeDuration) {
148-
handleFadeOut({}, true);
149-
} else {
150-
setIsFading(true);
146+
const handleClose = (e) => {
147+
if (!(!isTouch && e.target.classList.contains('iiz__close'))) {
148+
if (!isZoomed || isFullscreen || !fadeDuration) {
149+
handleFadeOut({}, true);
150+
} else {
151+
setIsFading(true);
152+
}
151153
}
152154

153155
zoomOut();

src/InnerImageZoom/components/Image.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const Image = ({ src, sources, width, height, hasSpacer, imgAttributes, isZoomed
1818
createSpacer ? 'iiz__img--abs' : ''
1919
}`}
2020
style={{
21-
transition: `linear 0ms opacity ${isZoomed ? fadeDuration : 0}ms, linear ${fadeDuration}ms visibility ${
21+
transition: `opacity 0ms linear ${isZoomed ? fadeDuration : 0}ms, visibility 0ms linear ${
2222
isZoomed ? fadeDuration : 0
2323
}ms`
2424
}}
@@ -34,7 +34,7 @@ const Image = ({ src, sources, width, height, hasSpacer, imgAttributes, isZoomed
3434
createSpacer ? 'iiz__img--abs' : ''
3535
}`}
3636
style={{
37-
transition: `linear 0ms opacity ${isZoomed ? fadeDuration : 0}ms, linear ${fadeDuration}ms visibility ${
37+
transition: `opacity 0ms linear ${isZoomed ? fadeDuration : 0}ms, visibility 0ms linear ${
3838
isZoomed ? fadeDuration : 0
3939
}ms`
4040
}}

src/InnerImageZoom/components/ZoomImage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const ZoomImage = ({ src, fadeDuration, top, left, isZoomed, onLoad, onDragStart
99
style={{
1010
top: top,
1111
left: left,
12-
transition: `linear ${fadeDuration}ms opacity, linear ${fadeDuration}ms visibility`
12+
transition: `opacity ${fadeDuration}ms linear, visibility ${fadeDuration}ms linear`
1313
}}
1414
src={src}
1515
onLoad={onLoad}
@@ -26,7 +26,7 @@ const ZoomImage = ({ src, fadeDuration, top, left, isZoomed, onLoad, onDragStart
2626
<button
2727
className={`iiz__btn iiz__close ${isZoomed ? 'iiz__close--visible' : ''}`}
2828
style={{
29-
transition: `linear ${fadeDuration}ms opacity, linear ${fadeDuration}ms visibility`
29+
transition: `opacity ${fadeDuration}ms linear, visibility ${fadeDuration}ms linear`
3030
}}
3131
onClick={onClose}
3232
aria-label="Zoom Out"

tests/index.spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,23 @@ describe('InnerImageZoom', function () {
407407
};
408408
});
409409

410+
it('persists the zoomed image after clicking the close button if moveType is drag', (done) => {
411+
innerImageZoom({ moveType: 'drag' });
412+
const figure = findRenderedDOMComponentWithTag(component, 'figure');
413+
Simulate.mouseEnter(figure);
414+
Simulate.click(figure, { pageX: 100, pageY: 100 });
415+
const zoomImg = findRenderedDOMComponentWithClass(component, 'iiz__zoom-img');
416+
417+
zoomImg.onload = () => {
418+
const button = findRenderedDOMComponentWithTag(component, 'button');
419+
Simulate.click(button, { pageX: 0, pageY: 0 });
420+
Simulate.transitionEnd(zoomImg, { propertyName: 'opacity' });
421+
const img = scryRenderedDOMComponentsWithTag(component, 'img');
422+
expect(img.length).toBe(2);
423+
done();
424+
};
425+
});
426+
410427
it('fires afterZoomOut callback on zoom out', (done) => {
411428
const afterZoomOut = createSpy();
412429
innerImageZoom({ afterZoomOut: afterZoomOut });

0 commit comments

Comments
 (0)