-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9954aef
commit a9351bc
Showing
7 changed files
with
130 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const intersectionObserverCache = new WeakMap() | ||
|
||
export function intersectionObserverAction (node, abortSignal, listener) { | ||
/* istanbul ignore else */ | ||
if (import.meta.env.MODE === 'test') { | ||
// jsdom doesn't support intersection observer; just fake it | ||
listener([{ target: node, isIntersecting: true }]) | ||
} else { | ||
// The scroll root is always `.tabpanel` | ||
const root = node.closest('.tabpanel') | ||
|
||
let observer = intersectionObserverCache.get(root) | ||
if (!observer) { | ||
// TODO: replace this with the contentvisibilityautostatechange event when all supported browsers support it. | ||
// For now we use IntersectionObserver because it has better cross-browser support, and it would be bad for | ||
// old Safari versions if they eagerly downloaded all custom emoji all at once. | ||
observer = new IntersectionObserver(listener, { | ||
root, | ||
// trigger if we are 1/2 scroll container height away so that the images load a bit quicker while scrolling | ||
rootMargin: '50% 0px 50% 0px', | ||
// trigger if any part of the emoji grid is intersecting | ||
threshold: 0 | ||
}) | ||
|
||
// avoid creating a new IntersectionObserver for every category; just use one for the whole root | ||
intersectionObserverCache.set(root, observer) | ||
|
||
// assume that the abortSignal is always the same for this root node; just add one event listener | ||
abortSignal.addEventListener('abort', () => { | ||
console.log('IntersectionObserver destroyed') | ||
observer.disconnect() | ||
}) | ||
} | ||
|
||
observer.observe(node) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters