Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lottiefiles/dotlottie-react

Package Overview
Dependencies
Maintainers
4
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lottiefiles/dotlottie-react - npm Package Compare versions

Comparing version 0.0.0 to 0.1.0

85

dist/use-dotlottie.js

@@ -32,22 +32,50 @@ import { DotLottie } from '@lottiefiles/dotlottie-web';

const [dotLottie, setDotLottie] = React.useState(null);
const dotLottieRef = React.useRef(null);
const canvasRef = React.useRef(null);
const containerRef = React.useRef(null);
React.useEffect(() => {
return () => {
dotLottie?.destroy();
setDotLottie(null);
};
}, []);
const setCanvasRef = React.useCallback((canvas) => {
if (canvas) {
const dotLottieInstance = new DotLottie({
...dotLottieConfig,
canvas
dotLottieRef.current = dotLottie;
const [intersectionObserver] = React.useState(() => {
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
dotLottieRef.current?.unfreeze();
} else {
dotLottieRef.current?.freeze();
}
});
},
{
threshold: 0
}
);
return observer;
});
const [resizeObserver] = React.useState(() => {
const observer = new ResizeObserver((entries) => {
entries.forEach(() => {
dotLottieRef.current?.resize();
});
setDotLottie(dotLottieInstance);
} else {
dotLottie?.destroy();
}
canvasRef.current = canvas;
}, []);
});
return observer;
});
const setCanvasRef = React.useCallback(
(canvas) => {
if (canvas) {
const dotLottieInstance = new DotLottie({
...dotLottieConfig,
canvas
});
setDotLottie(dotLottieInstance);
intersectionObserver.observe(canvas);
resizeObserver.observe(canvas);
} else {
dotLottieRef.current?.destroy();
intersectionObserver.disconnect();
resizeObserver.disconnect();
}
canvasRef.current = canvas;
},
[intersectionObserver, resizeObserver]
);
const setContainerRef = React.useCallback((container) => {

@@ -62,2 +90,25 @@ containerRef.current = container;

);
React.useEffect(() => {
function onVisibilityChange() {
if (document.hidden) {
dotLottieRef.current?.freeze();
} else {
dotLottieRef.current?.unfreeze();
}
}
document.addEventListener("visibilitychange", onVisibilityChange);
return () => {
document.removeEventListener("visibilitychange", onVisibilityChange);
};
}, []);
React.useEffect(() => {
return () => {
if (!dotLottie)
return;
dotLottie.destroy();
setDotLottie(null);
resizeObserver.disconnect();
intersectionObserver.disconnect();
};
}, []);
return {

@@ -64,0 +115,0 @@ dotLottie,

4

package.json
{
"name": "@lottiefiles/dotlottie-react",
"version": "0.0.0",
"version": "0.1.0",
"type": "module",

@@ -42,3 +42,3 @@ "description": "React wrapper around the dotlottie-web library",

"dependencies": {
"@lottiefiles/dotlottie-web": "0.9.2"
"@lottiefiles/dotlottie-web": "0.10.0"
},

@@ -45,0 +45,0 @@ "devDependencies": {

@@ -20,2 +20,3 @@ # @lottiefiles/dotlottie-react

* [Usage](#usage)
* [Live Examples](#live-examples)
* [APIs](#apis)

@@ -61,2 +62,6 @@ * [DotLottieReactProps](#dotlottiereactprops)

## Live Examples
* <a href="https://codesandbox.io/p/sandbox/dotlottie-react-basic-example-66cwfq?autoresize=1&file=%2Fsrc%2FApp.tsx&fontsize=14&hidenavigation=1&theme=dark" target="_blank">Basic Example</a>
## APIs

@@ -63,0 +68,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc