-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanimationUtils.js
70 lines (63 loc) · 1.33 KB
/
animationUtils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import {
Easing,
timing as retiming,
Clock,
Value,
set,
startClock,
clockRunning,
stopClock,
cond,
block,
not,
} from 'react-native-reanimated';
export const timing = (params) => {
const { clock, easing, duration, from, to } = {
clock: new Clock(),
easing: Easing.linear,
duration: 250,
from: 0,
to: 1,
...params
};
const state = {
finished: new Value(0),
position: new Value(0),
time: new Value(0),
frameTime: new Value(0)
};
const config = {
toValue: new Value(0),
duration,
easing
};
return block([
onInit(clock, [set(config.toValue, to), set(state.frameTime, 0)]),
animate({
clock,
fn: retiming,
state,
config,
from
})
]);
};
export const animate = ({
fn,
clock,
state,
config,
from
}) =>
block([
onInit(clock, [
set(state.finished, 0),
set(state.time, 0),
set(state.position, from),
startClock(clock)
]),
fn(clock, state, config),
cond(state.finished, stopClock(clock)),
state.position
]);
export const onInit = (clock, sequence) => cond(not(clockRunning(clock)), sequence);