12
12
import android .util .Log ;
13
13
import android .util .SparseArray ;
14
14
import com .facebook .infer .annotation .Assertions ;
15
+ import com .facebook .react .bridge .ReactApplicationContext ;
15
16
import com .facebook .react .bridge .WritableArray ;
16
17
import com .facebook .react .bridge .WritableMap ;
17
18
import com .facebook .react .uimanager .common .UIManagerType ;
@@ -24,8 +25,11 @@ public class ReactEventEmitter implements RCTEventEmitter {
24
25
25
26
private static final String TAG = ReactEventEmitter .class .getSimpleName ();
26
27
private final SparseArray <RCTEventEmitter > mEventEmitters = new SparseArray <>();
28
+ private final ReactApplicationContext mReactContext ;
27
29
28
- public ReactEventEmitter () { }
30
+ public ReactEventEmitter (ReactApplicationContext reactContext ) {
31
+ mReactContext = reactContext ;
32
+ }
29
33
30
34
public void register (@ UIManagerType int uiManagerType , RCTEventEmitter eventEmitter ) {
31
35
mEventEmitters .put (uiManagerType , eventEmitter );
@@ -48,12 +52,16 @@ public void receiveTouches(
48
52
49
53
Assertions .assertCondition (touches .size () > 0 );
50
54
51
- int targetReactTag = touches .getMap (0 ).getInt (TARGET_KEY );
52
- getEventEmitter (targetReactTag ).receiveTouches (eventName , touches , changedIndices );
55
+ int reactTag = touches .getMap (0 ).getInt (TARGET_KEY );
56
+ getEventEmitter (reactTag ).receiveTouches (eventName , touches , changedIndices );
53
57
}
54
58
55
59
private RCTEventEmitter getEventEmitter (int reactTag ) {
56
60
int type = ViewUtil .getUIManagerType (reactTag );
57
- return mEventEmitters .get (type );
61
+ RCTEventEmitter eventEmitter = mEventEmitters .get (type );
62
+ if (eventEmitter == null ) {
63
+ eventEmitter = mReactContext .getJSModule (RCTEventEmitter .class );
64
+ }
65
+ return eventEmitter ;
58
66
}
59
67
}
0 commit comments