-
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(📉): cubicBezier, getPointAtLength, and interpolatePath (#43)
Breaking change: * SVG function API has changed to be symmetric with [getTotalLength](https://developer.mozilla.org/en-US/docs/Web/API/SVGPathElement/getTotalLength) and [getPointAtLength](https://developer.mozilla.org/en-US/docs/Web/API/SVGPathElement/getPointAtLength) * binaryInterpolation has been renamed to bInterpolate
- Loading branch information
1 parent
947e13c
commit a2c66f0
Showing
14 changed files
with
1,432 additions
and
337 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
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,46 @@ | ||
import Animated from "react-native-reanimated"; | ||
|
||
import { min } from "./Math"; | ||
|
||
const { | ||
Value, | ||
add, | ||
multiply, | ||
cond, | ||
eq, | ||
abs, | ||
sub, | ||
interpolate, | ||
divide | ||
} = Animated; | ||
|
||
export const snapPoint = ( | ||
value: Animated.Adaptable<number>, | ||
velocity: Animated.Adaptable<number>, | ||
points: number[] | ||
) => { | ||
const point = add(value, multiply(0.2, velocity)); | ||
const diffPoint = (p: Animated.Adaptable<number>) => abs(sub(point, p)); | ||
const deltas = points.map(p => diffPoint(p)); | ||
const minDelta = min(...deltas); | ||
return points.reduce( | ||
(acc: Animated.Node<any>, p: number) => | ||
cond(eq(diffPoint(p), minDelta), p, acc), | ||
new Value() | ||
); | ||
}; | ||
|
||
export const bInterpolate = ( | ||
value: Animated.Adaptable<number>, | ||
origin: Animated.Adaptable<number>, | ||
destination: Animated.Adaptable<number> | ||
) => | ||
interpolate(value, { | ||
inputRange: [0, 1], | ||
outputRange: [origin, destination] | ||
}); | ||
|
||
export const translateZ = ( | ||
perspective: Animated.Adaptable<number>, | ||
z: Animated.Adaptable<number> | ||
) => ({ scale: divide(perspective, sub(perspective, z)) }); |
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,16 +1,15 @@ | ||
import Animated from "react-native-reanimated"; | ||
|
||
const { | ||
Value, cond, eq, or, | ||
} = Animated; | ||
const { Value, cond, eq, or } = Animated; | ||
|
||
export const find = ( | ||
array: Animated.Adaptable<number>[], | ||
index: Animated.Adaptable<number>, | ||
notFound: Animated.Node<any> = new Value(), | ||
notFound: Animated.Node<any> = new Value() | ||
) => array.reduce((acc, v, i) => cond(eq(i, index), v, acc), notFound); | ||
|
||
export const contains = ( | ||
values: Animated.Node<number>[], | ||
value: Animated.Node<number>, | ||
): Animated.Node<number> => values.reduce((acc, v) => or(acc, eq(value, v)), new Value(0)); | ||
value: Animated.Node<number> | ||
): Animated.Node<number> => | ||
values.reduce((acc, v) => or(acc, eq(value, v)), new Value(0)); |
Oops, something went wrong.