Browse Source

Merge pull request #744 from gre/pixel-push-confetti

Pixel push confetti
master
Gaëtan Renaudeau 7 years ago
committed by GitHub
parent
commit
f3777990d3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/components/ConfettiParty/Confetti.js
  2. 20
      src/components/ConfettiParty/index.js
  3. 2
      src/reducers/onboarding.js

4
src/components/ConfettiParty/Confetti.js

@ -1,6 +1,9 @@
// @flow // @flow
import React, { PureComponent } from 'react' import React, { PureComponent } from 'react'
import Animated from 'animated/lib/targets/react-dom' import Animated from 'animated/lib/targets/react-dom'
import Easing from 'animated/lib/Easing'
const easing = Easing.bezier(0.0, 0.3, 1, 1)
class Confetti extends PureComponent< class Confetti extends PureComponent<
{ {
@ -25,6 +28,7 @@ class Confetti extends PureComponent<
Animated.timing(this.state.progress, { Animated.timing(this.state.progress, {
toValue: 1, toValue: 1,
duration, duration,
easing,
}).start() }).start()
} }
render() { render() {

20
src/components/ConfettiParty/index.js

@ -31,24 +31,32 @@ const nextConfetti = (mode: ?string) =>
id: id++, id: id++,
shape: shapes[Math.floor(shapes.length * Math.random())], shape: shapes[Math.floor(shapes.length * Math.random())],
initialRotation: 360 * Math.random(), initialRotation: 360 * Math.random(),
initialYPercent: -0.15 * Math.random(), initialYPercent: -0.04 + -0.25 * Math.random(),
initialXPercent: 0.2 + 0.6 * Math.random(), initialXPercent: 0.2 + 0.6 * Math.random(),
initialScale: 1, initialScale: 1,
rotations: 8 * Math.random() - 4, rotations: 8 * Math.random() - 4,
delta: [(Math.random() - 0.5) * 600, 300 + 300 * Math.random()], delta: [(Math.random() - 0.5) * 1500, 500 + 500 * Math.random()],
duration: 6000 + 5000 * Math.random(), duration: 12000 + 8000 * Math.random(),
} }
class ConfettiParty extends PureComponent<{ emit: boolean }, { confettis: Array<Object> }> { class ConfettiParty extends PureComponent<{ emit: boolean }, { confettis: Array<Object> }> {
state = { state = {
// $FlowFixMe // $FlowFixMe
confettis: Array(64) confettis: Array(100)
.fill(null) .fill(null)
.map(nextConfetti), .map(nextConfetti),
} }
componentDidMount() { componentDidMount() {
this.setEmit(this.props.emit) this.setEmit(this.props.emit)
this.initialTimeout = setTimeout(() => {
clearInterval(this.initialInterval)
}, 10000)
this.initialInterval = setInterval(() => {
this.setState(({ confettis }) => ({
confettis: confettis.slice(confettis.length > 200 ? 1 : 0).concat(nextConfetti()),
}))
}, 100)
} }
componentDidUpdate(prevProps: *) { componentDidUpdate(prevProps: *) {
@ -59,6 +67,8 @@ class ConfettiParty extends PureComponent<{ emit: boolean }, { confettis: Array<
componentWillUnmount() { componentWillUnmount() {
this.setEmit(false) this.setEmit(false)
clearInterval(this.initialInterval)
clearTimeout(this.initialTimeout)
} }
setEmit(on: boolean) { setEmit(on: boolean) {
@ -73,6 +83,8 @@ class ConfettiParty extends PureComponent<{ emit: boolean }, { confettis: Array<
} }
} }
interval: * interval: *
initialInterval: *
initialTimeout: *
render() { render() {
const { confettis } = this.state const { confettis } = this.state

2
src/reducers/onboarding.js

@ -32,7 +32,7 @@ export type OnboardingState = {
const state: OnboardingState = { const state: OnboardingState = {
stepIndex: 0, // FIXME is this used at all? dup with stepName? stepIndex: 0, // FIXME is this used at all? dup with stepName?
stepName: SKIP_ONBOARDING ? 'finish' : 'start', stepName: SKIP_ONBOARDING ? 'analytics' : 'start',
genuine: { genuine: {
pinStepPass: false, pinStepPass: false,
recoveryStepPass: false, recoveryStepPass: false,

Loading…
Cancel
Save