-
Notifications
You must be signed in to change notification settings - Fork 663
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
Matt Perry
authored and
Matt Perry
committed
Aug 6, 2017
1 parent
2f128e7
commit 71aec89
Showing
2 changed files
with
34 additions
and
30 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,45 @@ | ||
import React from 'react'; | ||
import { spring } from 'popmotion'; | ||
import { spring } from '../../../../lib/popmotion'; | ||
import { MotionValue } from '../../src'; | ||
|
||
const springProps = { | ||
stiffness: 10000, | ||
damping: 10, | ||
mass: 10, | ||
velocity: 1000 | ||
stiffness: 1000, | ||
damping: 500, | ||
mass: 3 | ||
}; | ||
|
||
export default () => ( | ||
<MotionValue | ||
onStateChange={{ | ||
on: ({value}) => spring({ | ||
from: value.get(), | ||
to: 300, | ||
...springProps, | ||
onUpdate: value | ||
}).start(), | ||
on: ({value}) => { | ||
spring({ | ||
from: value.get(), | ||
to: 800, | ||
...springProps, | ||
velocity: value.getVelocity(), | ||
onUpdate: value | ||
}).start() | ||
}, | ||
off: ({value}) => spring({ | ||
from: value.get(), | ||
to: 0, | ||
...springProps, | ||
velocity: value.getVelocity(), | ||
onUpdate: value | ||
}).start() | ||
}} | ||
> | ||
{({ v, state, setStateTo }) => ( | ||
<div | ||
style={{ | ||
background: 'red', | ||
width: '100px', | ||
height: '100px', | ||
transform: 'translateX(' + v + 'px)' | ||
}} | ||
onClick={state === 'on' ? setStateTo.off : setStateTo.on} | ||
/> | ||
<div style={{ width: '100vw', height: '100vh' }} onClick={state === 'on' ? setStateTo.off : setStateTo.on}> | ||
<div | ||
style={{ | ||
background: 'red', | ||
width: '100px', | ||
height: '100px', | ||
transform: 'translateX(' + v + 'px)' | ||
}} | ||
/> | ||
</div> | ||
)} | ||
</MotionValue> | ||
); |
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