Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add assetsPath prop to enhance assets path configuration #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ declare module 'react-lottie-player' {

/** Lottie `AnimationItem` Instance */
ref?: React.Ref<AnimationItem | undefined>
} & ({ path?: string } | { animationData?: { ['default']: object } | object })
} & ({ path?: string } | { assetsPath?: string } | { animationData?: { ['default']: object } | object })
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is correct typing. Doesnt this mean that you cannot specify both assetPath and path/animationData together? Is that intented?


const Lottie: React.FC<LottieProps>

8 changes: 7 additions & 1 deletion src/makeLottiePlayer.js
Original file line number Diff line number Diff line change
@@ -52,13 +52,18 @@ const makeLottiePlayer = ({ loadAnimation }) => {
let animationData;
/** @type {string | undefined} */
let path;
/** @type {string | undefined} */
let assetsPath;

if ('animationData' in props) {
({ animationData, ...propsFiltered } = props);
}
if ('path' in props) {
({ path, ...propsFiltered } = props);
}
if ('assetsPath' in props) {
({ assetsPath, ...propsFiltered } = props);
}

/** @type {React.MutableRefObject<HTMLDivElement | null>} */
const animElementRef = useRef(null);
@@ -122,6 +127,7 @@ const makeLottiePlayer = ({ loadAnimation }) => {
const lottie = loadAnimation({
animationData: parseAnimationData(),
path,
assetsPath,
container: animElementRef.current,
renderer,
loop: false,
@@ -141,7 +147,7 @@ const makeLottiePlayer = ({ loadAnimation }) => {
getAnim().destroy();
setLottieRefs(undefined);
};
}, [loop, renderer, rendererSettings, animationData, path, audioFactory, setLottieRefs, getAnim]);
}, [loop, renderer, rendererSettings, animationData, path, assetsPath, audioFactory, setLottieRefs, getAnim]);

useEffect(() => {
getAnim().addEventListener('DOMLoaded', onLoad);