Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
passing current and velocity to dynamic poses
- Loading branch information
1 parent
ad6deda
commit 90a8b02
Showing
8 changed files
with
82 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
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,23 @@ | ||
import * as React from 'react'; | ||
import { motion, usePose } from '@framer'; | ||
import { Box } from '../styled'; | ||
import useInterval from '../inc/use-interval'; | ||
|
||
const MotionBox = motion(Box)({ | ||
ping: { | ||
x: 100, | ||
y: '0vh', | ||
transition: { duration: 100 } | ||
}, | ||
pong: ({ target }) => ({ x: target, y: '0vh' }) | ||
}); | ||
|
||
export const App = () => { | ||
const [pose, setPose] = usePose('ping'); | ||
|
||
useInterval(() => { | ||
setPose(pose.get() === 'ping' ? 'pong' : 'ping'); | ||
}, 1000); | ||
|
||
return <MotionBox pose={pose} target={-100} />; | ||
}; |
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
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
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,17 +1,16 @@ | ||
import { useMemo, CSSProperties } from 'react'; | ||
import { buildStyleProperty } from 'stylefire'; | ||
import { MotionValue } from '../motion-value'; | ||
import { resolveCurrent } from '../utils/resolve-values'; | ||
|
||
export default ( | ||
values: Map<string, MotionValue>, | ||
styles?: CSSProperties | ||
): CSSProperties => | ||
useMemo(() => { | ||
const resolvedValues = {}; | ||
values.forEach((value, key) => (resolvedValues[key] = value.get())); | ||
|
||
return { | ||
useMemo( | ||
() => ({ | ||
...styles, | ||
...buildStyleProperty(resolvedValues) | ||
}; | ||
}, []); | ||
...buildStyleProperty(resolveCurrent(values)) | ||
}), | ||
[] | ||
); |
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
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,16 @@ | ||
import { MotionValue } from '../motion-value'; | ||
|
||
export type Resolver = (value: MotionValue) => any; | ||
|
||
const createValueResolver = (resolver: Resolver) => ( | ||
values: Map<string, MotionValue> | ||
) => { | ||
const resolvedValues = {}; | ||
values.forEach((value, key) => (resolvedValues[key] = resolver(value))); | ||
return resolvedValues; | ||
}; | ||
|
||
export const resolveCurrent = createValueResolver(value => value.get()); | ||
export const resolveVelocity = createValueResolver(value => | ||
value.getVelocity() | ||
); |
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