2
2
3
3
package com .facebook .react .uimanager .layoutanimation ;
4
4
5
- import javax .annotation .Nullable ;
6
-
7
- import java .util .Map ;
8
-
5
+ import android .os .Build ;
9
6
import android .view .View ;
10
7
import android .view .animation .AccelerateDecelerateInterpolator ;
11
8
import android .view .animation .AccelerateInterpolator ;
12
9
import android .view .animation .Animation ;
10
+ import android .view .animation .BaseInterpolator ;
13
11
import android .view .animation .DecelerateInterpolator ;
14
12
import android .view .animation .Interpolator ;
15
13
import android .view .animation .LinearInterpolator ;
16
-
17
14
import com .facebook .react .bridge .ReadableMap ;
18
15
import com .facebook .react .common .MapBuilder ;
19
16
import com .facebook .react .uimanager .IllegalViewOperationException ;
17
+ import java .util .Map ;
18
+ import javax .annotation .Nullable ;
20
19
21
20
/**
22
21
* Class responsible for parsing and converting layout animation data into native {@link Animation}
36
35
*/
37
36
abstract @ Nullable Animation createAnimationImpl (View view , int x , int y , int width , int height );
38
37
39
- private static final Map <InterpolatorType , Interpolator > INTERPOLATOR = MapBuilder .of (
38
+ private static final Map <InterpolatorType , BaseInterpolator > INTERPOLATOR = MapBuilder .of (
40
39
InterpolatorType .LINEAR , new LinearInterpolator (),
41
40
InterpolatorType .EASE_IN , new AccelerateInterpolator (),
42
41
InterpolatorType .EASE_OUT , new DecelerateInterpolator (),
43
- InterpolatorType .EASE_IN_EASE_OUT , new AccelerateDecelerateInterpolator (),
44
- InterpolatorType .SPRING , new SimpleSpringInterpolator ());
42
+ InterpolatorType .EASE_IN_EASE_OUT , new AccelerateDecelerateInterpolator ());
45
43
46
44
private @ Nullable Interpolator mInterpolator ;
47
45
private int mDelayMs ;
@@ -64,7 +62,7 @@ public void initializeFromConfig(ReadableMap data, int globalDuration) {
64
62
if (!data .hasKey ("type" )) {
65
63
throw new IllegalArgumentException ("Missing interpolation type." );
66
64
}
67
- mInterpolator = getInterpolator (InterpolatorType .fromString (data .getString ("type" )));
65
+ mInterpolator = getInterpolator (InterpolatorType .fromString (data .getString ("type" )), data );
68
66
69
67
if (!isValid ()) {
70
68
throw new IllegalViewOperationException ("Invalid layout animation : " + data );
@@ -100,8 +98,16 @@ public void initializeFromConfig(ReadableMap data, int globalDuration) {
100
98
return animation ;
101
99
}
102
100
103
- private static Interpolator getInterpolator (InterpolatorType type ) {
104
- Interpolator interpolator = INTERPOLATOR .get (type );
101
+ private static Interpolator getInterpolator (InterpolatorType type , ReadableMap params ) {
102
+ Interpolator interpolator = null ;
103
+ if (type .equals (InterpolatorType .SPRING )) {
104
+ interpolator = new SimpleSpringInterpolator (SimpleSpringInterpolator .getSpringDamping (params ));
105
+ } else {
106
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP_MR1 ) {
107
+ // Conversion from BaseInterpolator to Interpolator is only possible on this Android versions
108
+ interpolator = INTERPOLATOR .get (type );
109
+ }
110
+ }
105
111
if (interpolator == null ) {
106
112
throw new IllegalArgumentException ("Missing interpolator for type : " + type );
107
113
}
0 commit comments