Skip to content

Commit

Permalink
Fix/animation problems (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
felippenardi committed Jun 10, 2020
1 parent 5c366f8 commit a9a236a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### Bug Fixes
* Animation wasn't playing the segments stated at the initial mount
* Animation was reseted on every mount

<a name="2.1.2"></a>
## [2.1.2](https://github.com/felippenardi/lottie-react-web/compare/v2.1.1...v2.1.2) (2018-08-09)

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
},
"dependencies": {
"babel-runtime": "^6.26.0",
"lottie-web": "^5.2.1",
"lottie-api": "^1.0.0"
"lottie-web": "^5.6.1",
"lottie-api": "^1.0.2"
},
"main": "dist/index.js",
"engines": {
Expand Down
21 changes: 16 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export default class Lottie extends React.Component {
renderer = 'svg',
rendererSettings,
assetsPath,
segments,
} = options;

this.options = {
Expand All @@ -27,7 +26,6 @@ export default class Lottie extends React.Component {
renderer,
loop: loop !== false,
autoplay: autoplay !== false,
segments: segments !== false,
animationData,
rendererSettings,
assetsPath
Expand All @@ -41,6 +39,14 @@ export default class Lottie extends React.Component {
this.animApi = lottieApi.createAnimationApi(this.anim);
this.registerEvents(eventListeners);
this.setAnimationControl();

if (this.props.isStopped) {
this.stops();
} else if (this.props.segments) {
this.playSegments(true);
} else {
this.play();
}
}

componentWillUpdate(nextProps /* , nextState */) {
Expand All @@ -55,12 +61,17 @@ export default class Lottie extends React.Component {
}
}

componentDidUpdate() {
componentDidUpdate(prevProps) {
if (this.props.isStopped) {
this.stop();
} else if (this.props.segments) {
const shouldForce = !!this.props.forceSegments;
this.playSegments(shouldForce);
if (
JSON.stringify(this.props.segments) ===
JSON.stringify(prevProps.segments)
) {
return;
}
this.playSegments(this.props.forceSegments);
} else {
this.play();
}
Expand Down

0 comments on commit a9a236a

Please sign in to comment.