Skip to content

Commit 1f1e4d4

Browse files
committed
fix(pat gallery): Do not reinitialize gallery image sizes too often.
1 parent 5341141 commit 1f1e4d4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/pat/gallery/gallery.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ export default Base.extend({
130130
};
131131

132132
const gallery = new PhotoSwipe(pswp_el, PhotoSwipeUI, this.images, options);
133+
134+
const gallery_reinit_sizes_debouncer = utils.debounce(() => {
135+
gallery.updateSize(true); // reinit Items
136+
}, 50);
137+
133138
gallery.listen("gettingData", function (index, item) {
134139
// Workaround for the fact that we don't know the image sizes.
135140
// https://github.com/dimsemenov/PhotoSwipe/issues/796
@@ -141,8 +146,8 @@ export default Base.extend({
141146
// will get size after load
142147
item.w = img_el.width; // set image width
143148
item.h = img_el.height; // set image height
144-
gallery.invalidateCurrItems(); // reinit Items
145-
gallery.updateSize(true); // reinit Items
149+
item.needsUpdate = true;
150+
gallery_reinit_sizes_debouncer(); // debounce to not land in a re-init loop.
146151
};
147152
img.src = item.src; // let's download image
148153
}

0 commit comments

Comments
 (0)