Skip to content

Commit 0f27ba7

Browse files
Merge pull request #21 from mh7777777/master
Pictures not showing when click on them to view full size bug fix.
2 parents 8c82509 + a7d401b commit 0f27ba7

2 files changed

Lines changed: 46 additions & 32 deletions

File tree

src/control/content/containers/Content.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Content extends Component {
4444
src => new Promise(resolve => {
4545
const image = new Image();
4646
image.onload = () => resolve(image);
47-
image.src = optimizeImg(src);
47+
image.src = src;
4848
image.originalSrc = src;
4949
})
5050
);

src/widget/containers/Widget.js

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -76,38 +76,52 @@ class Widget extends Component {
7676
preload: [1, 1]
7777
};
7878

79-
const galleryItems = (folderImages || images).map(img => {
80-
const { width, height } = img;
81-
const croppedSrc = imageLib.cropImage(img.src, {
82-
width,
83-
height,
84-
disablePixelRatio: true
85-
});
86-
const msrc = imageLib.cropImage(img.src, {
87-
width: width / 2,
88-
height: height / 2,
89-
compression: 20,
90-
disablePixelRatio: true
79+
const dimensionsTestPromises = (folderImages || images).map(img => new Promise(resolve => {
80+
if (img.width < 5 || img.height < 5) {
81+
const image = new Image();
82+
image.onload = () => resolve({ width: image.naturalWidth, height: image.naturalHeight });
83+
image.src = img.src;
84+
image.originalSrc = img.src;
85+
} else {
86+
resolve({ width: img.width, height: img.height });
87+
}
88+
}))
89+
90+
Promise.all(dimensionsTestPromises)
91+
.then(dimensions => {
92+
const galleryItems = (folderImages || images).map((img, index) => {
93+
const { width, height } = dimensions[index] ? dimensions[index] : img;
94+
const croppedSrc = imageLib.cropImage(img.src, {
95+
width,
96+
height,
97+
disablePixelRatio: true
98+
});
99+
const msrc = imageLib.cropImage(img.src, {
100+
width: width / 2,
101+
height: height / 2,
102+
compression: 20,
103+
disablePixelRatio: true
104+
});
105+
106+
return {
107+
src: croppedSrc,
108+
sourceImg: img.src,
109+
msrc,
110+
w: width,
111+
h: height
112+
};
113+
});
114+
this.gallery = new PhotoSwipe(pswpEle, photoSwipeUIdefault, galleryItems, options);
115+
this.gallery.init();
116+
117+
this.setState(() => ({ pswpOpen: true }));
118+
119+
this.gallery.listen('close', () => {
120+
spinner.hide();
121+
this.setState(() => ({ pswpOpen: false }));
122+
});
123+
this.gallery.listen('imageLoadComplete', () => spinner.hide());
91124
});
92-
93-
return {
94-
src: croppedSrc,
95-
sourceImg: img.src,
96-
msrc,
97-
w: width,
98-
h: height
99-
};
100-
});
101-
this.gallery = new PhotoSwipe(pswpEle, photoSwipeUIdefault, galleryItems, options);
102-
this.gallery.init();
103-
104-
this.setState(() => ({ pswpOpen: true }));
105-
106-
this.gallery.listen('close', () => {
107-
spinner.hide();
108-
this.setState(() => ({ pswpOpen: false }));
109-
});
110-
this.gallery.listen('imageLoadComplete', () => spinner.hide());
111125
};
112126

113127
shareImage = () => {

0 commit comments

Comments
 (0)