Skip to content

Commit e8f3433

Browse files
Merge pull request #119 from LottieFiles/feat/get-versions
feat: added getVersions, updated lottie-web
2 parents 8753827 + 9e5ed09 commit e8f3433

File tree

6 files changed

+49
-9
lines changed

6 files changed

+49
-9
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 3.5.0
4+
5+
### Minor Changes
6+
7+
- 978552b: added getVersions(), updated lottie-web
8+
39
## 3.4.9
410

511
### Patch Changes

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lottiefiles/react-lottie-player",
3-
"version": "3.4.9",
3+
"version": "3.5.0",
44
"description": "Lottie web player wrapper for React",
55
"main": "dist/lottie-react.js",
66
"module": "dist/lottie-react.esm.js",
@@ -82,10 +82,12 @@
8282
"react": "16 - 18"
8383
},
8484
"dependencies": {
85-
"lottie-web": "^5.7.8"
85+
"lottie-web": "^5.10.0"
8686
},
8787
"scripts": {
88+
"predev": "node -p \"'export const LOTTIE_PLAYER_VERSION = ' + JSON.stringify(require('./package.json').version) + '; \\n' + 'export const LOTTIE_WEB_VERSION = ' + JSON.stringify(require('./package.json').dependencies['lottie-web']) + ';'\" > src/versions.ts",
8889
"dev": "rollup -c -w",
90+
"prebuild": "node -p \"'export const LOTTIE_PLAYER_VERSION = ' + JSON.stringify(require('./package.json').version) + '; \\n' + 'export const LOTTIE_WEB_VERSION = ' + JSON.stringify(require('./package.json').dependencies['lottie-web']) + ';'\" > src/versions.ts",
8991
"build": "rollup -c",
9092
"prepublishOnly": "yarn build",
9193
"run-tests": "while ! nc -z localhost 8080 ; do sleep 1 ; done && yarn run start-cypress && npx nyc report --reporter=text-summary",

src/Player.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import lottie, { AnimationItem } from 'lottie-web';
22
import * as React from 'react';
33

4+
import { LOTTIE_PLAYER_VERSION, LOTTIE_WEB_VERSION } from './versions';
5+
46
/**
57
* Parse a resource into a JSON object or a URL string
68
*/
@@ -56,6 +58,11 @@ export enum PlayerEvent {
5658
Frame = 'frame',
5759
}
5860

61+
export type Versions = {
62+
lottieWebVersion: string;
63+
lottiePlayerVersion: string;
64+
};
65+
5966
export type PlayerDirection = -1 | 1;
6067

6168
export interface IPlayerProps {
@@ -126,6 +133,16 @@ export class Player extends React.Component<IPlayerProps, IPlayerState> {
126133
};
127134
}
128135

136+
/**
137+
* Returns the lottie-web version and this player's version
138+
*/
139+
public getVersions(): Versions {
140+
return {
141+
lottieWebVersion: LOTTIE_WEB_VERSION,
142+
lottiePlayerVersion: LOTTIE_PLAYER_VERSION,
143+
};
144+
}
145+
129146
static defaultProps = {
130147
loop: false,
131148
};

src/versions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const LOTTIE_PLAYER_VERSION = '3.4.9';
2+
export const LOTTIE_WEB_VERSION = '^5.10.0';

stories/index.stories.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import '@storybook/addon-console';
22

33
import * as React from 'react';
4+
import { useCallback, useRef, useEffect } from 'react';
45

56
import { Controls } from '../src/Controls';
67
import { Player } from '../src/Player';
@@ -12,13 +13,25 @@ export default {
1213
},
1314
};
1415

15-
export const LottiePlayer = () => {
16-
const onEvent = (event: any) => {
16+
export const LottiePlayer = (): any => {
17+
const playerRef = useRef(null);
18+
19+
const onEvent = useCallback((event: any) => {
1720
console.log('event', event);
18-
};
21+
}, []);
22+
23+
useEffect(() => {
24+
if (playerRef !== null && playerRef.current !== null) {
25+
// @ts-ignore: Object is possibly 'null'.
26+
console.log(playerRef.current.getVersions());
27+
console.log('Calling versions()');
28+
}
29+
}, [playerRef]);
30+
1931
return (
2032
<div style={{ width: '374px' }}>
2133
<Player
34+
ref={playerRef}
2235
src="https://assets1.lottiefiles.com/packages/lf20_ybj0fjlo.json"
2336
hover
2437
loop

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12691,10 +12691,10 @@ loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.4.0:
1269112691
dependencies:
1269212692
js-tokens "^3.0.0 || ^4.0.0"
1269312693

12694-
lottie-web@^5.7.8:
12695-
version "5.9.1"
12696-
resolved "https://registry.yarnpkg.com/lottie-web/-/lottie-web-5.9.1.tgz#0090e575de74e49843606c1722767604e068f061"
12697-
integrity sha512-3uKtU6BhIK6ZRCE/QyiXq/KuRvPeEAz/VFwqd99jPbpgFY9gHLw2krqvcuCFGepeW94BipS/B3TqIfTc9pUeZg==
12694+
lottie-web@^5.10.0:
12695+
version "5.10.0"
12696+
resolved "https://registry.yarnpkg.com/lottie-web/-/lottie-web-5.10.0.tgz#72563f22efdcf2b8f7e8359743514930ebaf5f8c"
12697+
integrity sha512-q2hfqKrGXNkwjSSZjKxf3fWMi0e3ZBc03qBkVWoGbwUJ7BcG+9YXjMPtmmhitzk8Nc6VQ5PRnh9yInPdfq0PZg==
1269812698

1269912699
lower-case@^2.0.2:
1270012700
version "2.0.2"

0 commit comments

Comments
 (0)