forked from chenqingspring/react-lottie
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request chenqingspring#27 from elliotcobb/master
Keep options passed with a new animation
- Loading branch information
Showing
3 changed files
with
58 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React from 'react'; | ||
import Lottie from '../index'; | ||
import * as animationDataA from './TwitterHeart.json'; | ||
import * as animationDataB from './beating-heart.json'; | ||
|
||
/** | ||
* TransitionWithOptions: demonstrates how you can switch to a | ||
* new animation with different options. For example, you can start | ||
* with a looped animation and change to one that plays only once | ||
* without mounting the component again | ||
*/ | ||
export default class TransitionWithOptions extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
showLoopedAnimation: true, | ||
}; | ||
} | ||
|
||
clickHandler = () => { | ||
this.setState({ showLoopedAnimation: !this.state.showLoopedAnimation }); | ||
}; | ||
|
||
render() { | ||
const centerStyle = { | ||
display: 'block', | ||
margin: '20px auto', | ||
textAlign: 'center', | ||
}; | ||
const { showLoopedAnimation } = this.state; | ||
const animationOptionsWithLoop = { | ||
animationData: animationDataA, | ||
loop: true, | ||
}; | ||
const animationOptionsWithoutLoop = { | ||
animationData: animationDataB, | ||
loop: false, | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Lottie | ||
options={showLoopedAnimation ? animationOptionsWithLoop : animationOptionsWithoutLoop} | ||
height={400} | ||
width={400} | ||
/> | ||
<p style={centerStyle}>This animation is {showLoopedAnimation ? 'looped' : 'not looped'}</p> | ||
<button style={centerStyle} onClick={this.clickHandler}> | ||
switch | ||
</button> | ||
</div> | ||
); | ||
} | ||
} |
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