Skip to content
This repository was archived by the owner on Jun 5, 2019. It is now read-only.

Commit c439d6b

Browse files
authored
Merge pull request #112 from skellock/upgrade-popmotion
⬆️ Upgrades popmotion
2 parents a87060d + ebf07d5 commit c439d6b

File tree

9 files changed

+127
-145
lines changed

9 files changed

+127
-145
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@
7171
"electron-window-state-manager": "^0.3.2",
7272
"glamor": "^2.20.40",
7373
"mousetrap": "^1.6.1",
74-
"popmotion": "^7.8.2",
75-
"popmotion-react": "^1.1.1",
74+
"popmotion": "^8.1.7",
75+
"popmotion-react": "^2.1.0",
7676
"prop-types": "^15.6.0",
7777
"ramda": "^0.25.0",
7878
"react": "^16.2.0",

src/renderer/platform/components/spin-animation/spin-animation-state.test.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/renderer/platform/components/spin-animation/spin-animation-state.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as React from "react"
2+
import { StorybookStory as Story, StorybookGroup as Group } from "../storybook"
3+
import { storiesOf } from "@storybook/react"
4+
import { SpinAnimation } from "./index"
5+
6+
storiesOf("SpinAnimation", module).add("default", () => (
7+
<Story>
8+
<Group title="default">
9+
<span style={{ display: "inline-block", width: 100 }}>
10+
<SpinAnimation>I am going to spin.</SpinAnimation>
11+
</span>
12+
</Group>
13+
</Story>
14+
))
Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,43 @@
11
import * as React from "react"
2-
import { MotionValue, MotionStates, MotionStateProps } from "popmotion-react"
3-
import { SpinAnimationStateProps, createSpinStates, next } from "./spin-animation-state"
2+
import { MotionValue, MotionStateProps, MotionStates } from "popmotion-react"
3+
import { tween } from "popmotion"
4+
5+
const DEFAULT_DURATION = 500
6+
const DEFAULT_REVOLUTIONS = 1
7+
8+
export interface SpinAnimationProps {
9+
duration?: number
10+
revolutions?: number
11+
}
412

513
/**
614
* Provides a container which will do a barrel roll when clicked.
715
*/
8-
export class SpinAnimation extends React.PureComponent<SpinAnimationStateProps, {}> {
9-
animationStates: MotionStates
10-
11-
componentWillMount() {
12-
this.animationStates = createSpinStates(this.props)
13-
}
14-
15-
/* istanbul ignore next */
16-
componentWillReceiveProps(newProps: SpinAnimationStateProps) {
17-
this.animationStates = createSpinStates(newProps)
18-
}
19-
16+
export class SpinAnimation extends React.PureComponent<SpinAnimationProps, {}> {
2017
render() {
21-
// the view to spin
22-
// NOTE: This is a function and not a component due to popmotion-react.
23-
const spinWrapper = (motionState: MotionStateProps) => {
24-
const props = {
25-
style: { transform: `rotate(${motionState.v}deg)`, cursor: "pointer" },
26-
onClick: next(motionState),
27-
children: this.props.children,
28-
}
18+
const duration = this.props.duration || DEFAULT_DURATION
19+
const forwardAngle = 360 * (this.props.revolutions || DEFAULT_REVOLUTIONS)
2920

30-
return <div {...props} />
21+
// istanbul ignore next
22+
const motionStates: MotionStates = {
23+
on: ({ value }) => tween({ from: value.get(), to: forwardAngle, duration }).start(value),
24+
off: ({ value }) => tween({ from: value.get(), to: 0, duration }).start(value),
3125
}
3226

33-
return <MotionValue onStateChange={this.animationStates} children={spinWrapper} />
27+
return (
28+
<MotionValue onStateChange={motionStates}>
29+
{(motionState: MotionStateProps) => (
30+
<div
31+
style={{ transform: `rotate(${motionState.v}deg)`, cursor: "pointer" }}
32+
onClick={
33+
// istanbul ignore next
34+
motionState.state === "on" ? motionState.setStateTo.off : motionState.setStateTo.on
35+
}
36+
>
37+
{this.props.children}
38+
</div>
39+
)}
40+
</MotionValue>
41+
)
3442
}
3543
}

test/__snapshots__/storyshots.test.ts.snap

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,61 @@ exports[`Storyshots ScrollableContent default 1`] = `
251251
</div>
252252
`;
253253

254+
exports[`Storyshots SpinAnimation default 1`] = `
255+
<div
256+
style={
257+
Object {
258+
"paddingLeft": 20,
259+
"paddingRight": 20,
260+
}
261+
}
262+
>
263+
<div
264+
style={
265+
Object {
266+
"paddingBottom": 20,
267+
}
268+
}
269+
>
270+
<p
271+
style={
272+
Object {
273+
"borderBottom": "1px solid #eee",
274+
"color": "#3d3d3d",
275+
"fontFamily": "Helvetica Neue",
276+
"fontSize": 14,
277+
"marginBottom": 5,
278+
"marginLeft": -20,
279+
"paddingBottom": 5,
280+
}
281+
}
282+
>
283+
default
284+
</p>
285+
<span
286+
style={
287+
Object {
288+
"display": "inline-block",
289+
"width": 100,
290+
}
291+
}
292+
>
293+
<div
294+
onClick={[Function]}
295+
style={
296+
Object {
297+
"cursor": "pointer",
298+
"transform": "rotate(0deg)",
299+
}
300+
}
301+
>
302+
I am going to spin.
303+
</div>
304+
</span>
305+
</div>
306+
</div>
307+
`;
308+
254309
exports[`Storyshots Tab Tab 1`] = `
255310
<div
256311
style={

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"experimentalDecorators": true,
88
"allowSyntheticDefaultImports": false,
99
"noUnusedLocals": true,
10-
"strictNullChecks": true,
10+
"strictNullChecks": false,
1111
"noImplicitReturns": true,
1212
"noImplicitAny": true
1313
},

typings/popmotion.d.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

yarn.lock

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3464,7 +3464,7 @@ forwarded@~0.1.2:
34643464
version "0.1.2"
34653465
resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.1.2.tgz#98c23dab1175657b8c0573e8ceccd91b0ff18c84"
34663466

3467-
framesync@^3.0.1:
3467+
framesync@^3.0.2, framesync@^3.1.7:
34683468
version "3.1.7"
34693469
resolved "https://registry.yarnpkg.com/framesync/-/framesync-3.1.7.tgz#9b9aa3eff8598625302597851a428f40c3dc1c6b"
34703470

@@ -6017,15 +6017,19 @@ podda@^1.2.2:
60176017
babel-runtime "^6.11.6"
60186018
immutable "^3.8.1"
60196019

6020-
popmotion-react@^1.1.1:
6021-
version "1.1.1"
6022-
resolved "https://registry.yarnpkg.com/popmotion-react/-/popmotion-react-1.1.1.tgz#5eef3877914cdd9fb007f1e92b32142b5b5676e0"
6020+
popmotion-react@^2.1.0:
6021+
version "2.1.0"
6022+
resolved "https://registry.yarnpkg.com/popmotion-react/-/popmotion-react-2.1.0.tgz#519e7004d9d5ab5c571c2bf03627daf4ebc18152"
6023+
dependencies:
6024+
popmotion "^8.1.0"
60236025

6024-
popmotion@^7.8.2:
6025-
version "7.8.2"
6026-
resolved "https://registry.yarnpkg.com/popmotion/-/popmotion-7.8.2.tgz#984ecbdc1ea70c022ee8d4bc36a4317ed619ba1d"
6026+
popmotion@^8.1.0, popmotion@^8.1.7:
6027+
version "8.1.7"
6028+
resolved "https://registry.yarnpkg.com/popmotion/-/popmotion-8.1.7.tgz#7dba748d9fae1284fc7a5702e5ed0b7be66ffcbe"
60276029
dependencies:
6028-
framesync "^3.0.1"
6030+
framesync "^3.1.7"
6031+
style-value-types "^1.0.3"
6032+
stylefire "^1.1.8"
60296033

60306034
postcss-calc@^5.2.0:
60316035
version "5.3.1"
@@ -7556,6 +7560,17 @@ style-loader@^0.19.1:
75567560
loader-utils "^1.0.2"
75577561
schema-utils "^0.3.0"
75587562

7563+
style-value-types@^1.0.0, style-value-types@^1.0.3:
7564+
version "1.0.3"
7565+
resolved "https://registry.yarnpkg.com/style-value-types/-/style-value-types-1.0.3.tgz#651c3c75c988ea2ef86e20c6a07f98cce62efddf"
7566+
7567+
stylefire@^1.1.8:
7568+
version "1.1.8"
7569+
resolved "https://registry.yarnpkg.com/stylefire/-/stylefire-1.1.8.tgz#2e26894c5e2877c5100a7b29522d918a6fc4f1e1"
7570+
dependencies:
7571+
framesync "^3.0.2"
7572+
style-value-types "^1.0.0"
7573+
75597574
subarg@^1.0.0:
75607575
version "1.0.0"
75617576
resolved "https://registry.yarnpkg.com/subarg/-/subarg-1.0.0.tgz#f62cf17581e996b48fc965699f54c06ae268b8d2"

0 commit comments

Comments
 (0)