-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathInterpolationParser.java
More file actions
58 lines (52 loc) · 2.49 KB
/
InterpolationParser.java
File metadata and controls
58 lines (52 loc) · 2.49 KB
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
package com.reactnativenavigation.options.parsers;
import android.animation.TimeInterpolator;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.OvershootInterpolator;
import com.reactnativenavigation.options.interpolators.DecelerateAccelerateInterpolator;
import com.reactnativenavigation.options.interpolators.SpringInterpolator;
import org.json.JSONObject;
import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
public class InterpolationParser {
public static TimeInterpolator parse(JSONObject json) {
JSONObject interpolation = json.optJSONObject("interpolation");
String type = interpolation == null ? "linear" : interpolation.optString("type", "linear");
switch (type) {
case "decelerate": {
float factor = (float) interpolation.optDouble("factor", 1.0);
return new DecelerateInterpolator(factor);
}
case "accelerateDecelerate": {
return new AccelerateDecelerateInterpolator();
}
case "accelerate": {
float factor = (float) interpolation.optDouble("factor", 1.0);
return new AccelerateInterpolator(factor);
}
case "decelerateAccelerate": {
return new DecelerateAccelerateInterpolator();
}
case "fastOutSlowIn": {
return new FastOutSlowInInterpolator();
}
case "overshoot": {
double tension = interpolation.optDouble("tension", 1.0);
return new OvershootInterpolator((float) tension);
}
case "spring": {
float mass = (float) interpolation.optDouble("mass", 3.0);
float damping = (float) interpolation.optDouble("damping", 500.0);
float stiffness = (float) interpolation.optDouble("stiffness", 200.0);
boolean allowsOverdamping = interpolation.optBoolean("allowsOverdamping", false);
float initialVelocity = (float) interpolation.optDouble("initialVelocity", 0);
return new SpringInterpolator(mass, damping, stiffness, allowsOverdamping, initialVelocity);
}
case "linear":
default: {
return new LinearInterpolator();
}
}
}
}