Skip to content

Commit

Permalink
ENG-511 Image intersection issues (#894)
Browse files Browse the repository at this point in the history
  • Loading branch information
matvlaovi-flip authored Dec 17, 2024
1 parent fd80402 commit 96108e1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
8 changes: 8 additions & 0 deletions .changeset/poor-spies-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@getflip/swirl-components": minor
"@getflip/swirl-components-angular": minor
"@getflip/swirl-components-react": minor
---

Intersecting image-grid-item images only load if they're visible in the final
state
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Watch,
} from "@stencil/core";
import classnames from "classnames";
import { debounce } from "../../utils";

export type SwirlImageGridItemLoading =
| "lazy"
Expand Down Expand Up @@ -102,19 +103,20 @@ export class SwirlImageGridItem {
return;
}

this.intersectionObserver = new IntersectionObserver(
this.onVisibilityChange.bind(this),
{
threshold: 0,
}
);
this.intersectionObserver = new IntersectionObserver((entries) => {
this.handleIntersectionEntries(entries);
});

this.intersectionObserver.observe(this.el);
}

private onVisibilityChange(entries: IntersectionObserverEntry[]) {
this.inViewport = entries.some((entry) => entry.isIntersecting);
}
private handleIntersectionEntries = debounce(
(entries: IntersectionObserverEntry[]) => {
const sorted = [...entries].sort((a, b) => a.time - b.time);
this.inViewport = sorted.at(-1).isIntersecting;
},
250
);

private onLoad = () => {
this.error = false;
Expand Down

0 comments on commit 96108e1

Please sign in to comment.