Skip to content

Commit b5a55e4

Browse files
committed
Add eventhandler example to storybook
Added transition loop example, which illustrates how an event can be used to trigger state changes. Made note of broken loop prop, to investigate. added babel-eslint parser setting to eslint (babel-eslint was already a project dependancy).
1 parent 026a6c3 commit b5a55e4

File tree

5 files changed

+5360
-8
lines changed

5 files changed

+5360
-8
lines changed

.eslintrc

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"parser": "babel-eslint",
23
"extends": "airbnb",
34
"rules": {
45
# We use _ to define private variables and methods in clases

src/stories/TransitionLoop.js

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import React from 'react';
2+
import Lottie from '../index';
3+
import * as animationDataA from './TwitterHeart.json';
4+
import * as animationDataB from './beating-heart.json';
5+
6+
/**
7+
* TransitionLoop, demonstrates the use of the eventListener Props.
8+
* NOTE: there appears to currently be a bug in either
9+
* react-lottie or bodymovin which results in a chance of the loop option not
10+
* taking effect accross different animations.
11+
*/
12+
export default class TransitionLoop extends React.Component {
13+
constructor(props) {
14+
super(props);
15+
16+
this.state = {
17+
isStopped: true,
18+
isPaused: false,
19+
speed: 1,
20+
direction: 1,
21+
isLike: false,
22+
isTransitioned: false,
23+
};
24+
}
25+
26+
transition() {
27+
console.log('transition:');
28+
this.setState({ isTransitioned: true });
29+
}
30+
31+
clickHandler = () => {
32+
this.setState({ isTransitioned: false });
33+
};
34+
35+
render() {
36+
const centerStyle = {
37+
display: 'block',
38+
margin: '10px auto',
39+
textAlign: 'center',
40+
};
41+
const { isTransitioned } = this.state;
42+
const defaultOptions = {
43+
animationData: !isTransitioned ? animationDataA : animationDataB,
44+
loop: true,
45+
autoplay: true,
46+
};
47+
48+
return (
49+
<div>
50+
<Lottie
51+
options={defaultOptions}
52+
height={400}
53+
width={400}
54+
eventListeners={
55+
!isTransitioned
56+
? [
57+
{
58+
eventName: 'loopComplete',
59+
callback: () => this.transition(),
60+
},
61+
]
62+
: []
63+
}
64+
/>
65+
<button style={centerStyle} onClick={this.clickHandler}>
66+
restart
67+
</button>
68+
</div>
69+
);
70+
}
71+
}

src/stories/beating-heart.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"assets":[],"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"corasón","ks":{"o":{"k":100},"r":{"k":0},"p":{"k":[{"i":{"x":0.34,"y":1},"o":{"x":0.167,"y":0.167},"n":"0p34_1_0p167_0p167","t":0,"s":[256,360,0],"e":[256,300,0],"to":[0,0,0],"ti":[0,0,0]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.66,"y":0},"n":"0p833_0p833_0p66_0","t":8,"s":[256,300,0],"e":[256,360,0],"to":[0,0,0],"ti":[0,0,0]},{"t":16}]},"a":{"k":[0,67,0]},"s":{"k":[{"i":{"x":[0.667,0.667,0.667],"y":[1,1,0.667]},"o":{"x":[0.333,0.333,0.333],"y":[0,0,0.333]},"n":["0p667_1_0p333_0","0p667_1_0p333_0","0p667_0p667_0p333_0p333"],"t":0,"s":[105,95,100],"e":[90,120,100]},{"i":{"x":[0.34,0.34,0.667],"y":[1,1,0.667]},"o":{"x":[0.333,0.333,0.333],"y":[0,0,0.333]},"n":["0p34_1_0p333_0","0p34_1_0p333_0","0p667_0p667_0p333_0p333"],"t":2,"s":[90,120,100],"e":[100,100,100]},{"i":{"x":[0.667,0.667,0.667],"y":[1,1,0.667]},"o":{"x":[0.66,0.66,0.333],"y":[0,0,0.333]},"n":["0p667_1_0p66_0","0p667_1_0p66_0","0p667_0p667_0p333_0p333"],"t":8,"s":[100,100,100],"e":[90,120,100]},{"i":{"x":[0.667,0.667,0.667],"y":[0.667,0.8,0.667]},"o":{"x":[0.333,0.333,0.333],"y":[0,0,0.333]},"n":["0p667_0p667_0p333_0","0p667_0p8_0p333_0","0p667_0p667_0p333_0p333"],"t":14,"s":[90,120,100],"e":[105,95,100]},{"t":16}]}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"k":{"i":[[25.079,0],[7.698,-12.8],[14.334,0],[0,-26.379],[-10.313,-12.267],[-19.972,-13.2],[0,0],[-19.972,13.201],[-10.312,12.267],[0,11.377]],"o":[[-14.334,0],[-7.698,-12.8],[-25.079,0],[0,11.377],[10.312,12.267],[19.972,13.201],[0,0],[19.972,-13.2],[10.313,-12.267],[0,-26.379]],"v":[[37.595,-64],[0,-44.8],[-37.594,-64],[-81.454,-21.898],[-66.574,16.522],[-30.154,48.522],[0,64],[30.154,48.522],[66.573,16.522],[81.454,-21.898]],"c":true}},"nm":"Trazado 1","mn":"ADBE Vector Shape - Group"},{"ty":"fl","c":{"k":[0.839,0.176,0.318,1]},"o":{"k":100},"nm":"Relleno 1","mn":"ADBE Vector Graphic - Fill"},{"ty":"tr","p":{"k":[0,0],"ix":2},"a":{"k":[0,0],"ix":1},"s":{"k":[100,100],"ix":3},"r":{"k":0,"ix":6},"o":{"k":100,"ix":7},"sk":{"k":0,"ix":4},"sa":{"k":0,"ix":5},"nm":"Transformar"}],"nm":"Forma 1","np":3,"mn":"ADBE Vector Group"}],"ip":0,"op":16,"st":0,"bm":0,"sr":1},{"ddd":0,"ind":2,"ty":1,"nm":"BG","ks":{"o":{"k":100},"r":{"k":0},"p":{"k":[256,256,0]},"a":{"k":[64,64,0]},"s":{"k":[409.375,409.375,100]}},"ao":0,"sw":128,"sh":128,"sc":"#ffffff","ip":0,"op":16,"st":0,"bm":0,"sr":1}],"v":"4.5.4","ddd":0,"ip":0,"op":16,"fr":24,"w":512,"h":512}

src/stories/index.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import React from 'react';
2-
import {storiesOf, action} from '@kadira/storybook';
3-
import LottieControl from './lottie-control'
4-
import ToggleLike from "./toggle-like";
2+
import { storiesOf, action } from '@kadira/storybook';
3+
import LottieControl from './lottie-control';
4+
import ToggleLike from './toggle-like';
5+
import TransitionLoop from './TransitionLoop';
56

67
storiesOf('Lottie Animation View', module)
7-
.add('with control', () => (
8-
<LottieControl/>
9-
)).add('toggle like', () => (
10-
<ToggleLike/>
11-
));
8+
.add('with control', () => <LottieControl />)
9+
.add('toggle like', () => <ToggleLike />)
10+
.add('transitions & loops', () => <TransitionLoop />);

0 commit comments

Comments
 (0)