-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
1,484 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
components/gathering/PockyGatheringAnimation/AnimateEatPocky.js
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,24 @@ | ||
import data from './animationData'; | ||
|
||
export default class AnimateEatPocky { | ||
constructor(domRef) { | ||
this.anim = window.lottie.loadAnimation({ | ||
container: domRef, | ||
renderer: 'svg', | ||
loop: false, | ||
autoplay: false, | ||
animationData: data, | ||
}); | ||
this.anim.addEventListener('complete', () => { | ||
this.isAnimating = false; | ||
}); | ||
this.isAnimating = false; | ||
} | ||
|
||
play() { | ||
if (!this.isAnimating) { | ||
this.isAnimating = true; | ||
this.anim.goToAndPlay(0, true); | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
components/gathering/PockyGatheringAnimation/PockyGatheringAnimation.js
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,57 @@ | ||
import React, { PureComponent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Head from 'next/head'; | ||
|
||
import AnimateEatPocky from './AnimateEatPocky'; | ||
|
||
const lottieCDN = | ||
'https://cdnjs.cloudflare.com/ajax/libs/bodymovin/5.4.1/lottie.min.js'; | ||
|
||
export default class PockyGatheringAnimation extends PureComponent { | ||
static propTypes = { | ||
number: PropTypes.number, | ||
}; | ||
|
||
componentDidMount() { | ||
// can't get global lottie after onload, don't know why... | ||
var lottie_script = document.createElement('script'); | ||
lottie_script.onload = this._init; | ||
lottie_script.src = lottieCDN; | ||
document.head.appendChild(lottie_script); | ||
} | ||
|
||
componentDidUpdate = prevProps => { | ||
const isInit = prevProps.number > 1000 || this.props.number > 1000; | ||
if ( | ||
this.animEatPocky && | ||
!isInit && | ||
prevProps.number !== this.props.number | ||
) { | ||
this.animEatPocky.play('lottie-pocky'); | ||
} | ||
}; | ||
|
||
_init = () => { | ||
this.animEatPocky = new AnimateEatPocky(this.refContainer); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<div id="lottie-pocky" ref={container => (this.refContainer = container)}> | ||
<Head> | ||
<script src={lottieCDN} /> | ||
</Head> | ||
<style jsx>{` | ||
#lottie-pocky { | ||
position: absolute; | ||
z-index: 1; | ||
right: 0; | ||
left: 0; | ||
top: 0; | ||
bottom: 0; | ||
} | ||
`}</style> | ||
</div> | ||
); | ||
} | ||
} |
1,401 changes: 1,401 additions & 0 deletions
1,401
components/gathering/PockyGatheringAnimation/animationData.js
Large diffs are not rendered by default.
Oops, something went wrong.
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