1import { describe, it, expect } from "vitest";
3 newValueImpl, newValueXYImpl, setValueImpl, setValueXYImpl,
4 setOffsetImpl, flattenOffsetImpl, extractOffsetImpl,
5 stopAnimationImpl, resetAnimationImpl, interpolateImpl,
6 timingImpl, springImpl, decayImpl,
7 startImpl, startWithCallbackImpl, stopImpl, resetImpl,
8 parallelImpl, sequenceImpl, staggerImpl, delayImpl, loopImpl,
9 addImpl, subtractImpl, multiplyImpl, divideImpl, moduloImpl, diffClampImpl,
10 _animatedViewImpl, _animatedTextImpl, _animatedImageImpl, _animatedScrollViewImpl,
12} from "../src/Yoga/React/Native/Animated.js";
14describe("Animated FFI", () => {
15 it("newValueImpl creates an AnimatedValue", () => {
16 const v = newValueImpl(42);
17 expect(v).toBeDefined();
18 expect(v._value).toBe(42);
21 it("newValueXYImpl creates an AnimatedValueXY", () => {
22 const v = newValueXYImpl(10, 20);
23 expect(v).toBeDefined();
24 expect(v.x._value).toBe(10);
25 expect(v.y._value).toBe(20);
28 it("setValueImpl sets the value", () => {
29 const v = newValueImpl(0);
31 expect(v._value).toBe(99);
34 it("setValueXYImpl sets xy values", () => {
35 const v = newValueXYImpl(0, 0);
36 setValueXYImpl(v, { x: 5, y: 10 });
37 expect(v.x._value).toBe(5);
38 expect(v.y._value).toBe(10);
41 it("setOffsetImpl sets offset", () => {
42 const v = newValueImpl(0);
44 expect(v._offset).toBe(10);
47 it("flattenOffsetImpl does not throw", () => {
48 const v = newValueImpl(0);
49 expect(() => flattenOffsetImpl(v)).not.toThrow();
52 it("extractOffsetImpl does not throw", () => {
53 const v = newValueImpl(0);
54 expect(() => extractOffsetImpl(v)).not.toThrow();
57 it("stopAnimationImpl does not throw", () => {
58 const v = newValueImpl(0);
59 expect(() => stopAnimationImpl(v)).not.toThrow();
62 it("resetAnimationImpl does not throw", () => {
63 const v = newValueImpl(0);
64 expect(() => resetAnimationImpl(v)).not.toThrow();
67 it("interpolateImpl returns an interpolated value", () => {
68 const v = newValueImpl(0);
69 const config = { inputRange: [0, 1], outputRange: [0, 100] };
70 const result = interpolateImpl(v)(config);
71 expect(result).toBeDefined();
72 expect(result._interpolated).toBe(true);
75 it("timingImpl returns a CompositeAnimation", () => {
76 const v = newValueImpl(0);
77 const anim = timingImpl(v)({ toValue: 1, duration: 300 });
78 expect(anim).toBeDefined();
79 expect(typeof anim.start).toBe("function");
80 expect(typeof anim.stop).toBe("function");
83 it("springImpl returns a CompositeAnimation", () => {
84 const v = newValueImpl(0);
85 const anim = springImpl(v)({ toValue: 1 });
86 expect(typeof anim.start).toBe("function");
89 it("decayImpl returns a CompositeAnimation", () => {
90 const v = newValueImpl(0);
91 const anim = decayImpl(v)({ velocity: 0.5 });
92 expect(typeof anim.start).toBe("function");
95 it("startImpl starts an animation", () => {
96 const v = newValueImpl(0);
97 const anim = timingImpl(v)({ toValue: 1 });
98 expect(() => startImpl(anim)).not.toThrow();
101 it("startWithCallbackImpl calls back with finished", () => {
102 const v = newValueImpl(0);
103 const anim = timingImpl(v)({ toValue: 1 });
105 startWithCallbackImpl(anim, (r) => { result = r; });
106 expect(result).toEqual({ finished: true });
109 it("stopImpl stops an animation", () => {
110 const v = newValueImpl(0);
111 const anim = timingImpl(v)({ toValue: 1 });
112 expect(() => stopImpl(anim)).not.toThrow();
115 it("resetImpl resets an animation", () => {
116 const v = newValueImpl(0);
117 const anim = timingImpl(v)({ toValue: 1 });
118 expect(() => resetImpl(anim)).not.toThrow();
121 it("parallelImpl returns a CompositeAnimation", () => {
122 const anim = parallelImpl([]);
123 expect(typeof anim.start).toBe("function");
126 it("sequenceImpl returns a CompositeAnimation", () => {
127 const anim = sequenceImpl([]);
128 expect(typeof anim.start).toBe("function");
131 it("staggerImpl returns a CompositeAnimation", () => {
132 const anim = staggerImpl(100)([]);
133 expect(typeof anim.start).toBe("function");
136 it("delayImpl returns a CompositeAnimation", () => {
137 const anim = delayImpl(100);
138 expect(typeof anim.start).toBe("function");
141 it("loopImpl returns a CompositeAnimation", () => {
142 const v = newValueImpl(0);
143 const inner = timingImpl(v)({ toValue: 1 });
144 const anim = loopImpl(inner)({});
145 expect(typeof anim.start).toBe("function");
148 it("addImpl returns an animated node", () => {
149 const a = newValueImpl(1);
150 const b = newValueImpl(2);
151 expect(addImpl(a)(b)).toBeDefined();
154 it("subtractImpl returns an animated node", () => {
155 const a = newValueImpl(1);
156 const b = newValueImpl(2);
157 expect(subtractImpl(a)(b)).toBeDefined();
160 it("multiplyImpl returns an animated node", () => {
161 expect(multiplyImpl(newValueImpl(2))(newValueImpl(3))).toBeDefined();
164 it("divideImpl returns an animated node", () => {
165 expect(divideImpl(newValueImpl(6))(newValueImpl(3))).toBeDefined();
168 it("moduloImpl returns an animated node", () => {
169 expect(moduloImpl(newValueImpl(7))(3)).toBeDefined();
172 it("diffClampImpl returns an animated node", () => {
173 expect(diffClampImpl(newValueImpl(5))(0)(10)).toBeDefined();
176 it("animated component exports are defined", () => {
177 expect(_animatedViewImpl).toBe("Animated.View");
178 expect(_animatedTextImpl).toBe("Animated.Text");
179 expect(_animatedImageImpl).toBe("Animated.Image");
180 expect(_animatedScrollViewImpl).toBe("Animated.ScrollView");
183 it("useAnimatedValueImpl returns an effect thunk that returns an animated value", () => {
184 const thunk = useAnimatedValueImpl(42);
185 expect(typeof thunk).toBe("function");
187 expect(v._value).toBe(42);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list