6
6
import android .content .res .Resources ;
7
7
import android .graphics .Typeface ;
8
8
import android .location .Location ;
9
- import android .util .Log ;
10
9
11
10
import androidx .annotation .NonNull ;
12
11
import androidx .annotation .Nullable ;
13
12
14
13
import com .batch .android .Batch ;
15
14
import com .batch .android .BatchActivityLifecycleHelper ;
16
15
import com .batch .android .BatchAttributesFetchListener ;
17
- import com .batch .android .BatchEventDispatcher ;
18
- import com .batch .android .BatchPushPayload ;
19
16
import com .batch .android .BatchTagCollectionsFetchListener ;
20
17
import com .batch .android .BatchUserAttribute ;
21
18
import com .batch .android .PushNotificationType ;
25
22
import com .batch .android .BatchUserDataEditor ;
26
23
import com .batch .android .Config ;
27
24
import com .batch .android .json .JSONObject ;
28
- import com .facebook .react .bridge .Arguments ;
29
25
import com .facebook .react .bridge .Promise ;
30
26
import com .facebook .react .bridge .ReactApplicationContext ;
31
- import com .facebook .react .bridge .ReactContext ;
32
27
import com .facebook .react .bridge .ReactContextBaseJavaModule ;
33
28
import com .facebook .react .bridge .ReactMethod ;
34
29
import com .facebook .react .bridge .ReadableArray ;
38
33
import com .facebook .react .bridge .WritableMap ;
39
34
import com .facebook .react .bridge .WritableNativeArray ;
40
35
import com .facebook .react .bridge .WritableNativeMap ;
41
- import com .facebook .react .modules .core .DeviceEventManagerModule ;
42
36
43
37
import java .net .URI ;
44
38
import java .util .Date ;
49
43
import java .util .Set ;
50
44
import java .util .UUID ;
51
45
52
- public class RNBatchModule extends ReactContextBaseJavaModule implements BatchEventDispatcher {
46
+ public class RNBatchModule extends ReactContextBaseJavaModule {
53
47
54
48
private static final String NAME = "RNBatch" ;
55
49
private static final String PLUGIN_VERSION_ENVIRONMENT_VARIABLE = "batch.plugin.version" ;
56
50
private static final String PLUGIN_VERSION = "ReactNative/8.1.0" ;
57
51
52
+ public static final String LOGGER_TAG = "RNBatchBridge" ;
53
+
58
54
private static final String BATCH_BRIDGE_ERROR_CODE = "BATCH_BRIDGE_ERROR" ;
59
55
60
56
private final ReactApplicationContext reactContext ;
61
57
62
58
private final Map <String , BatchInboxFetcher > batchInboxFetcherMap ;
63
59
60
+ private static final RNBatchEventDispatcher eventDispatcher = new RNBatchEventDispatcher ();
61
+
64
62
static {
65
63
System .setProperty ("batch.plugin.version" , PLUGIN_VERSION );
66
64
}
@@ -94,7 +92,7 @@ public static void initialize(Application application) {
94
92
String packageName = application .getPackageName ();
95
93
String batchAPIKey = resources .getString (resources .getIdentifier ("BATCH_API_KEY" , "string" , packageName ));
96
94
Batch .setConfig (new Config (batchAPIKey ));
97
-
95
+ Batch . EventDispatcher . addDispatcher ( eventDispatcher );
98
96
try {
99
97
boolean doNotDisturbEnabled = resources .getBoolean (resources .getIdentifier ("BATCH_DO_NOT_DISTURB_INITIAL_STATE" , "bool" , packageName ));
100
98
Batch .Messaging .setDoNotDisturbEnabled (doNotDisturbEnabled );
@@ -112,7 +110,7 @@ public RNBatchModule(ReactApplicationContext reactContext) {
112
110
super (reactContext );
113
111
this .reactContext = reactContext ;
114
112
this .batchInboxFetcherMap = new HashMap <>();
115
- Batch . EventDispatcher . addDispatcher ( this );
113
+ eventDispatcher . setReactContext ( reactContext );
116
114
}
117
115
118
116
public void start () {
@@ -145,20 +143,6 @@ public void optOutAndWipeData(Promise promise) {
145
143
promise .resolve (null );
146
144
}
147
145
148
- // EVENT EventDispatcher
149
-
150
- private void sendEvent (ReactContext reactContext ,
151
- String eventName ,
152
- @ Nullable WritableMap params ) {
153
-
154
- if (!reactContext .hasActiveCatalystInstance ()) {
155
- Log .d (NAME , "React context has no active catalyst instance. Aborting send event." );
156
- return ;
157
- }
158
- reactContext
159
- .getJSModule (DeviceEventManagerModule .RCTDeviceEventEmitter .class )
160
- .emit (eventName , params );
161
- }
162
146
163
147
@ ReactMethod
164
148
public void addListener (String eventName ) {
@@ -170,52 +154,6 @@ public void removeListeners(double count) {
170
154
// iOS only
171
155
}
172
156
173
- @ Override
174
- public void dispatchEvent (@ NonNull Batch .EventDispatcher .Type type ,
175
- @ NonNull Batch .EventDispatcher .Payload payload ) {
176
- String eventName = this .mapBatchEventDispatcherTypeToRNEvent (type );
177
- if (eventName != null ) {
178
- WritableMap params = Arguments .createMap ();
179
- params .putBoolean ("isPositiveAction" , payload .isPositiveAction ());
180
- params .putString ("deeplink" , payload .getDeeplink ());
181
- params .putString ("trackingId" , payload .getTrackingId ());
182
- params .putString ("webViewAnalyticsIdentifier" , payload .getWebViewAnalyticsID ());
183
-
184
- BatchPushPayload pushPayload = payload .getPushPayload ();
185
- if (pushPayload != null ) {
186
- params .putMap ("pushPayload" , Arguments .fromBundle (pushPayload .getPushBundle ()));
187
- }
188
-
189
- sendEvent (reactContext , eventName , params );
190
- }
191
- }
192
-
193
- private @ Nullable
194
- String mapBatchEventDispatcherTypeToRNEvent (@ NonNull Batch .EventDispatcher .Type type ) {
195
- switch (type ) {
196
- case MESSAGING_SHOW :
197
- return "messaging_show" ;
198
- case MESSAGING_CLICK :
199
- return "messaging_click" ;
200
- case MESSAGING_CLOSE :
201
- return "messaging_close" ;
202
- case MESSAGING_AUTO_CLOSE :
203
- return "messaging_auto_close" ;
204
- case MESSAGING_CLOSE_ERROR :
205
- return "messaging_close_error" ;
206
- case MESSAGING_WEBVIEW_CLICK :
207
- return "messaging_webview_click" ;
208
- case NOTIFICATION_OPEN :
209
- return "notification_open" ;
210
- case NOTIFICATION_DISMISS :
211
- return "notification_dismiss" ;
212
- case NOTIFICATION_DISPLAY :
213
- return "notification_display" ;
214
- default :
215
- return null ;
216
- }
217
- }
218
-
219
157
// PUSH MODULE
220
158
221
159
@ ReactMethod
0 commit comments