8
8
*/
9
9
package com .facebook .react .modules .core ;
10
10
11
- import android .annotation .TargetApi ;
12
- import android .os .Build ;
13
11
import android .os .Handler ;
14
- import android .os .Looper ;
15
12
import android .view .Choreographer ;
16
13
import com .facebook .react .bridge .UiThreadUtil ;
17
14
22
19
public class ChoreographerCompat {
23
20
24
21
private static final long ONE_FRAME_MILLIS = 17 ;
25
- private static final boolean IS_JELLYBEAN_OR_HIGHER =
26
- Build .VERSION .SDK_INT >= Build .VERSION_CODES .JELLY_BEAN ;
27
22
private static ChoreographerCompat sInstance ;
28
23
29
24
private Handler mHandler ;
@@ -38,55 +33,35 @@ public static ChoreographerCompat getInstance() {
38
33
}
39
34
40
35
private ChoreographerCompat () {
41
- if (IS_JELLYBEAN_OR_HIGHER ) {
42
- mChoreographer = getChoreographer ();
43
- } else {
44
- mHandler = new Handler (Looper .getMainLooper ());
45
- }
36
+ mChoreographer = getChoreographer ();
46
37
}
47
38
48
39
public void postFrameCallback (FrameCallback callbackWrapper ) {
49
- if (IS_JELLYBEAN_OR_HIGHER ) {
50
- choreographerPostFrameCallback (callbackWrapper .getFrameCallback ());
51
- } else {
52
- mHandler .postDelayed (callbackWrapper .getRunnable (), 0 );
53
- }
40
+ choreographerPostFrameCallback (callbackWrapper .getFrameCallback ());
54
41
}
55
42
56
43
public void postFrameCallbackDelayed (FrameCallback callbackWrapper , long delayMillis ) {
57
- if (IS_JELLYBEAN_OR_HIGHER ) {
58
- choreographerPostFrameCallbackDelayed (callbackWrapper .getFrameCallback (), delayMillis );
59
- } else {
60
- mHandler .postDelayed (callbackWrapper .getRunnable (), delayMillis + ONE_FRAME_MILLIS );
61
- }
44
+ choreographerPostFrameCallbackDelayed (callbackWrapper .getFrameCallback (), delayMillis );
62
45
}
63
46
64
47
public void removeFrameCallback (FrameCallback callbackWrapper ) {
65
- if (IS_JELLYBEAN_OR_HIGHER ) {
66
- choreographerRemoveFrameCallback (callbackWrapper .getFrameCallback ());
67
- } else {
68
- mHandler .removeCallbacks (callbackWrapper .getRunnable ());
69
- }
48
+ choreographerRemoveFrameCallback (callbackWrapper .getFrameCallback ());
70
49
}
71
50
72
- @ TargetApi (Build .VERSION_CODES .JELLY_BEAN )
73
51
private Choreographer getChoreographer () {
74
52
return Choreographer .getInstance ();
75
53
}
76
54
77
- @ TargetApi (Build .VERSION_CODES .JELLY_BEAN )
78
55
private void choreographerPostFrameCallback (Choreographer .FrameCallback frameCallback ) {
79
56
mChoreographer .postFrameCallback (frameCallback );
80
57
}
81
58
82
- @ TargetApi (Build .VERSION_CODES .JELLY_BEAN )
83
59
private void choreographerPostFrameCallbackDelayed (
84
60
Choreographer .FrameCallback frameCallback ,
85
61
long delayMillis ) {
86
62
mChoreographer .postFrameCallbackDelayed (frameCallback , delayMillis );
87
63
}
88
64
89
- @ TargetApi (Build .VERSION_CODES .JELLY_BEAN )
90
65
private void choreographerRemoveFrameCallback (Choreographer .FrameCallback frameCallback ) {
91
66
mChoreographer .removeFrameCallback (frameCallback );
92
67
}
@@ -101,7 +76,6 @@ public static abstract class FrameCallback {
101
76
private Runnable mRunnable ;
102
77
private Choreographer .FrameCallback mFrameCallback ;
103
78
104
- @ TargetApi (Build .VERSION_CODES .JELLY_BEAN )
105
79
Choreographer .FrameCallback getFrameCallback () {
106
80
if (mFrameCallback == null ) {
107
81
mFrameCallback = new Choreographer .FrameCallback () {
0 commit comments