react-native-radar 3.23.0 → 3.23.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Radar.podspec CHANGED
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
16
16
  s.source_files = "ios/**/*.{h,m,mm,cpp}"
17
17
  s.private_header_files = "ios/**/*.h"
18
18
 
19
- s.dependency "RadarSDK", "3.23.1"
19
+ s.dependency "RadarSDK", "3.23.2"
20
20
 
21
21
  install_modules_dependencies(s)
22
22
  end
@@ -1,3 +1,5 @@
1
+ def radar_sdk_version = '3.23.2'
2
+
1
3
  buildscript {
2
4
  ext.getExtOrDefault = {name ->
3
5
  return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['Radar_' + name]
@@ -83,7 +85,7 @@ dependencies {
83
85
  // Keep Kotlin stdlib internal to this module
84
86
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
85
87
 
86
- api 'io.radar:sdk:3.23.2'
88
+ api "io.radar:sdk:$radar_sdk_version"
87
89
  }
88
90
 
89
91
  react {
@@ -38,6 +38,7 @@ import io.radar.sdk.model.RadarRoutes;
38
38
  import io.radar.sdk.model.RadarTrip;
39
39
  import io.radar.sdk.model.RadarUser;
40
40
  import io.radar.sdk.model.RadarVerifiedLocationToken;
41
+ import io.radar.sdk.model.RadarInAppMessage;
41
42
  import io.radar.sdk.RadarNotificationOptions;
42
43
 
43
44
  import org.json.JSONException;
@@ -1243,7 +1244,6 @@ public class RadarModuleImpl {
1243
1244
  });
1244
1245
  }
1245
1246
 
1246
-
1247
1247
  public void logConversion(ReadableMap optionsMap, final Promise promise) throws JSONException {
1248
1248
  if (promise == null) {
1249
1249
  return;
@@ -1287,4 +1287,15 @@ public class RadarModuleImpl {
1287
1287
  Radar.logConversion(name, metadataObj, callback);
1288
1288
  }
1289
1289
  }
1290
+
1291
+ public void showInAppMessage(ReadableMap inAppMessageMap) {
1292
+ RadarInAppMessage inAppMessage;
1293
+ try {
1294
+ inAppMessage = RadarInAppMessage.fromJson(RadarUtils.jsonForMap(inAppMessageMap).toString());
1295
+ } catch (JSONException e) {
1296
+ Log.e(TAG, "JSONException", e);
1297
+ return;
1298
+ }
1299
+ Radar.showInAppMessage(inAppMessage);
1300
+ }
1290
1301
  }
@@ -24,7 +24,9 @@ import io.radar.sdk.model.RadarRouteMatrix
24
24
  import io.radar.sdk.model.RadarRoutes
25
25
  import io.radar.sdk.model.RadarTrip
26
26
  import io.radar.sdk.model.RadarVerifiedLocationToken
27
+ import io.radar.sdk.model.RadarInAppMessage
27
28
  import io.radar.sdk.RadarNotificationOptions
29
+ import io.radar.sdk.RadarInAppMessageReceiver
28
30
  import android.content.Context
29
31
  import android.location.Location
30
32
  import com.facebook.react.bridge.Arguments
@@ -33,6 +35,7 @@ import com.facebook.react.bridge.Promise
33
35
  import com.facebook.react.bridge.ReadableMap
34
36
  import com.facebook.react.bridge.ReadableArray
35
37
  import org.json.JSONException
38
+ import org.json.JSONObject
36
39
 
37
40
  @ReactModule(name = RadarModule.NAME)
38
41
  class RadarModule(reactContext: ReactApplicationContext) :
@@ -85,6 +88,41 @@ class RadarModule(reactContext: ReactApplicationContext) :
85
88
  }
86
89
  }
87
90
 
91
+ private val radarInAppMessageReceiver = object : RadarInAppMessageReceiver {
92
+ override fun onNewInAppMessage(message: RadarInAppMessage) {
93
+ try {
94
+ val eventBlob = Arguments.createMap().apply {
95
+ putMap("inAppMessage", RadarUtils.mapForJson(JSONObject(message.toJson())))
96
+ }
97
+ emitNewInAppMessageEmitter(eventBlob)
98
+ } catch (e: Exception) {
99
+ Log.e(TAG, "Exception", e)
100
+ }
101
+ }
102
+
103
+ override fun onInAppMessageDismissed(message: RadarInAppMessage) {
104
+ try {
105
+ val eventBlob = Arguments.createMap().apply {
106
+ putMap("inAppMessage", RadarUtils.mapForJson(JSONObject(message.toJson())))
107
+ }
108
+ emitInAppMessageDismissedEmitter(eventBlob)
109
+ } catch (e: Exception) {
110
+ Log.e(TAG, "Exception", e)
111
+ }
112
+ }
113
+
114
+ override fun onInAppMessageButtonClicked(message: RadarInAppMessage) {
115
+ try {
116
+ val eventBlob = Arguments.createMap().apply {
117
+ putMap("inAppMessage", RadarUtils.mapForJson(JSONObject(message.toJson())))
118
+ }
119
+ emitInAppMessageClickedEmitter(eventBlob)
120
+ } catch (e: Exception) {
121
+ Log.e(TAG, "Exception", e)
122
+ }
123
+ }
124
+ }
125
+
88
126
  private val radarVerifiedReceiver = object : RadarVerifiedReceiver() {
89
127
  override fun onTokenUpdated(context: Context, token: RadarVerifiedLocationToken) {
90
128
  val eventBlob = Arguments.createMap().apply {
@@ -105,16 +143,13 @@ class RadarModule(reactContext: ReactApplicationContext) :
105
143
  override fun initialize(publishableKey: String, fraud: Boolean): Unit {
106
144
  val editor = reactApplicationContext.getSharedPreferences("RadarSDK", Context.MODE_PRIVATE).edit()
107
145
  editor.putString("x_platform_sdk_type", "ReactNative")
108
- editor.putString("x_platform_sdk_version", "3.23.0")
146
+ editor.putString("x_platform_sdk_version", "3.23.2")
109
147
  editor.apply()
110
148
 
149
+ Radar.initialize(reactApplicationContext, publishableKey, radarReceiver, Radar.RadarLocationServicesProvider.GOOGLE, fraud, null, radarInAppMessageReceiver, currentActivity)
111
150
  if (fraud) {
112
- Radar.initialize(reactApplicationContext, publishableKey, radarReceiver, Radar.RadarLocationServicesProvider.GOOGLE, fraud)
113
151
  Radar.setVerifiedReceiver(radarVerifiedReceiver)
114
- } else {
115
- Radar.initialize(reactApplicationContext, publishableKey)
116
- Radar.setReceiver(radarReceiver)
117
- }
152
+ }
118
153
  }
119
154
 
120
155
  override fun setLogLevel(level: String): Unit {
@@ -393,6 +428,10 @@ class RadarModule(reactContext: ReactApplicationContext) :
393
428
  radarModuleImpl.getPublishableKey(promise)
394
429
  }
395
430
 
431
+ override fun showInAppMessage(inAppMessage: ReadableMap): Unit {
432
+ radarModuleImpl.showInAppMessage(inAppMessage)
433
+ }
434
+
396
435
 
397
436
  companion object {
398
437
  const val NAME = "RNRadar"
@@ -54,6 +54,7 @@ public class RadarModule extends ReactContextBaseJavaModule implements Permissio
54
54
 
55
55
  private RadarOldArchReceiver receiver;
56
56
  private RadarOldArchVerifiedReceiver verifiedReceiver;
57
+ private RadarOldArchInAppMessageReceiver inAppMessageReceiver;
57
58
  private int listenerCount = 0;
58
59
  private boolean fraud = false;
59
60
  private RadarModuleImpl radarModuleImpl;
@@ -62,6 +63,7 @@ public class RadarModule extends ReactContextBaseJavaModule implements Permissio
62
63
  super(reactContext);
63
64
  receiver = new RadarOldArchReceiver();
64
65
  verifiedReceiver = new RadarOldArchVerifiedReceiver();
66
+ inAppMessageReceiver = new RadarOldArchInAppMessageReceiver(reactContext);
65
67
  radarModuleImpl = new RadarModuleImpl();
66
68
  }
67
69
 
@@ -72,6 +74,7 @@ public class RadarModule extends ReactContextBaseJavaModule implements Permissio
72
74
  verifiedReceiver.hasListeners = true;
73
75
  }
74
76
  receiver.hasListeners = true;
77
+ inAppMessageReceiver.hasListeners = true;
75
78
  }
76
79
 
77
80
  listenerCount += 1;
@@ -85,6 +88,7 @@ public class RadarModule extends ReactContextBaseJavaModule implements Permissio
85
88
  verifiedReceiver.hasListeners = false;
86
89
  }
87
90
  receiver.hasListeners = false;
91
+ inAppMessageReceiver.hasListeners = false;
88
92
  }
89
93
  }
90
94
 
@@ -98,14 +102,11 @@ public class RadarModule extends ReactContextBaseJavaModule implements Permissio
98
102
  this.fraud = fraud;
99
103
  SharedPreferences.Editor editor = getReactApplicationContext().getSharedPreferences("RadarSDK", Context.MODE_PRIVATE).edit();
100
104
  editor.putString("x_platform_sdk_type", "ReactNative");
101
- editor.putString("x_platform_sdk_version", "3.23.0");
105
+ editor.putString("x_platform_sdk_version", "3.23.2");
102
106
  editor.apply();
103
- if (fraud) {
104
- Radar.initialize(getReactApplicationContext(), publishableKey, receiver, Radar.RadarLocationServicesProvider.GOOGLE, fraud);
107
+ Radar.initialize(getReactApplicationContext(), publishableKey, receiver, Radar.RadarLocationServicesProvider.GOOGLE, fraud, null, inAppMessageReceiver, getCurrentActivity());
108
+ if (fraud) {
105
109
  Radar.setVerifiedReceiver(verifiedReceiver);
106
- } else {
107
- Radar.initialize(getReactApplicationContext(), publishableKey);
108
- Radar.setReceiver(receiver);
109
110
  }
110
111
  }
111
112
 
@@ -438,4 +439,9 @@ public class RadarModule extends ReactContextBaseJavaModule implements Permissio
438
439
  radarModuleImpl.getPublishableKey(promise);
439
440
  }
440
441
 
442
+ @ReactMethod
443
+ public void showInAppMessage(ReadableMap inAppMessageMap) {
444
+ radarModuleImpl.showInAppMessage(inAppMessageMap);
445
+ }
446
+
441
447
  }
@@ -0,0 +1,98 @@
1
+ package com.radar;
2
+
3
+ import android.content.Context;
4
+ import android.view.View;
5
+ import android.util.Log;
6
+
7
+ import kotlin.Unit;
8
+ import kotlin.jvm.functions.Function0;
9
+ import kotlin.jvm.functions.Function1;
10
+
11
+ import org.json.JSONObject;
12
+
13
+ import com.facebook.react.ReactApplication;
14
+ import com.facebook.react.ReactInstanceManager;
15
+ import com.facebook.react.ReactNativeHost;
16
+ import com.facebook.react.bridge.Arguments;
17
+ import com.facebook.react.bridge.ReactContext;
18
+ import com.facebook.react.bridge.ReactMethod;
19
+ import com.facebook.react.bridge.WritableMap;
20
+ import com.facebook.react.modules.core.DeviceEventManagerModule;
21
+
22
+ import io.radar.sdk.Radar;
23
+ import io.radar.sdk.model.RadarInAppMessage;
24
+ import io.radar.sdk.RadarInAppMessageReceiver;
25
+
26
+ public class RadarOldArchInAppMessageReceiver implements RadarInAppMessageReceiver {
27
+ private ReactNativeHost reactNativeHost;
28
+ private static final String TAG = "RadarOldArchInAppMessageReceiver";
29
+ protected boolean hasListeners = false;
30
+
31
+ public RadarOldArchInAppMessageReceiver(Context context) {
32
+ try {
33
+ ReactApplication reactApplication = ((ReactApplication)context.getApplicationContext());
34
+ this.reactNativeHost = reactApplication.getReactNativeHost();
35
+ } catch (Exception e) {
36
+ Log.e(TAG, "Failed to initialize ReactNativeHost", e);
37
+ }
38
+ }
39
+
40
+ private void sendEvent(final String eventName, final Object data) {
41
+ if (reactNativeHost == null) {
42
+ Log.w(TAG, "ReactNativeHost not initialized, cannot send event: " + eventName);
43
+ return;
44
+ }
45
+
46
+ final ReactInstanceManager reactInstanceManager = reactNativeHost.getReactInstanceManager();
47
+ ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
48
+ if (reactContext != null && hasListeners) {
49
+ reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, data);
50
+ }
51
+ }
52
+
53
+ @Override
54
+ public void onNewInAppMessage(RadarInAppMessage message) {
55
+ try {
56
+ WritableMap map = Arguments.createMap();
57
+ map.putMap("inAppMessage", RadarUtils.mapForJson(new JSONObject(message.toJson())));
58
+ sendEvent("newInAppMessageEmitter", map);
59
+ } catch (Exception e) {
60
+ Log.e(TAG, "Exception", e);
61
+ }
62
+ }
63
+
64
+ @Override
65
+ public void onInAppMessageDismissed(RadarInAppMessage message) {
66
+ try {
67
+ WritableMap map = Arguments.createMap();
68
+ map.putMap("inAppMessage", RadarUtils.mapForJson(new JSONObject(message.toJson())));
69
+ sendEvent("inAppMessageDismissedEmitter", map);
70
+ } catch (Exception e) {
71
+ Log.e(TAG, "Exception", e);
72
+ }
73
+ }
74
+
75
+ @Override
76
+ public void onInAppMessageButtonClicked(RadarInAppMessage message) {
77
+ try {
78
+ WritableMap map = Arguments.createMap();
79
+ map.putMap("inAppMessage", RadarUtils.mapForJson(new JSONObject(message.toJson())));
80
+ sendEvent("inAppMessageClickedEmitter", map);
81
+ } catch (Exception e) {
82
+ Log.e(TAG, "Exception", e);
83
+ }
84
+ }
85
+
86
+ @Override
87
+ public void createInAppMessageView(
88
+ Context context,
89
+ RadarInAppMessage inAppMessage,
90
+ Function0<Unit> onDismissListener,
91
+ Function0<Unit> onInAppMessageButtonClicked,
92
+ Function1<? super View, Unit> onViewReady
93
+ ) {
94
+ RadarInAppMessageReceiver.DefaultImpls.createInAppMessageView(
95
+ this, context, inAppMessage, onDismissListener, onInAppMessageButtonClicked, onViewReady
96
+ );
97
+ }
98
+ }
@@ -1,4 +1,4 @@
1
- import type { RadarPermissionsStatus, RadarTrackCallback, RadarTrackOnceOptions, RadarLocationUpdateCallback, RadarClientLocationUpdateCallback, RadarErrorCallback, RadarLogUpdateCallback, RadarEventUpdateCallback, RadarTokenUpdateCallback, RadarLogLevel, RadarMetadata, RadarTrackingOptionsDesiredAccuracy, RadarLocationCallback, RadarTrackVerifiedCallback, RadarTrackVerifiedOptions, RadarTrackingOptions, RadarVerifiedTrackingOptions, RadarMockTrackingOptions, RadarTrackingOptionsForegroundService, RadarNotificationOptions, RadarTripOptions, RadarStartTripOptions, RadarTripCallback, RadarUpdateTripOptions, RadarContextCallback, RadarSearchPlacesOptions, RadarSearchPlacesCallback, RadarSearchGeofencesCallback, RadarSearchGeofencesOptions, RadarAutocompleteOptions, RadarAddressCallback, RadarReverseGeocodeOptions, RadarGeocodeOptions, RadarValidateAddressCallback, RadarIPGeocodeCallback, RadarAddress, RadarLogConversionOptions, RadarGetDistanceOptions, RadarRouteCallback, RadarGetMatrixOptions, RadarLogConversionCallback, RadarRouteMatrix, Location } from "./types";
1
+ import type { RadarPermissionsStatus, RadarTrackCallback, RadarTrackOnceOptions, RadarLocationUpdateCallback, RadarClientLocationUpdateCallback, RadarErrorCallback, RadarLogUpdateCallback, RadarEventUpdateCallback, RadarTokenUpdateCallback, RadarLogLevel, RadarMetadata, RadarTrackingOptionsDesiredAccuracy, RadarLocationCallback, RadarTrackVerifiedCallback, RadarTrackVerifiedOptions, RadarTrackingOptions, RadarVerifiedTrackingOptions, RadarMockTrackingOptions, RadarTrackingOptionsForegroundService, RadarNotificationOptions, RadarTripOptions, RadarStartTripOptions, RadarTripCallback, RadarUpdateTripOptions, RadarContextCallback, RadarSearchPlacesOptions, RadarSearchPlacesCallback, RadarSearchGeofencesCallback, RadarSearchGeofencesOptions, RadarAutocompleteOptions, RadarAddressCallback, RadarReverseGeocodeOptions, RadarGeocodeOptions, RadarValidateAddressCallback, RadarIPGeocodeCallback, RadarAddress, RadarLogConversionOptions, RadarGetDistanceOptions, RadarRouteCallback, RadarGetMatrixOptions, RadarLogConversionCallback, RadarRouteMatrix, Location, RadarNewInAppMessageCallback, RadarInAppMessageDismissedCallback, RadarInAppMessageClickedCallback, RadarInAppMessage } from "./types";
2
2
  export interface RadarNativeInterface {
3
3
  initialize: (publishableKey: string, fraud?: boolean) => void;
4
4
  setLogLevel: (level: RadarLogLevel) => void;
@@ -56,12 +56,16 @@ export interface RadarNativeInterface {
56
56
  logConversion: (options: RadarLogConversionOptions) => Promise<RadarLogConversionCallback>;
57
57
  nativeSdkVersion: () => Promise<string>;
58
58
  rnSdkVersion: () => string;
59
+ showInAppMessage: (inAppMessage: RadarInAppMessage) => void;
59
60
  onLocationUpdated: (callback: RadarLocationUpdateCallback | null) => void;
60
61
  onClientLocationUpdated: (callback: RadarClientLocationUpdateCallback | null) => void;
61
62
  onError: (callback: RadarErrorCallback | null) => void;
62
63
  onLog: (callback: RadarLogUpdateCallback | null) => void;
63
64
  onEventsReceived: (callback: RadarEventUpdateCallback | null) => void;
64
65
  onTokenUpdated: (callback: RadarTokenUpdateCallback | null) => void;
66
+ onNewInAppMessage: (callback: RadarNewInAppMessageCallback | null) => void;
67
+ onInAppMessageDismissed: (callback: RadarInAppMessageDismissedCallback | null) => void;
68
+ onInAppMessageClicked: (callback: RadarInAppMessageClickedCallback | null) => void;
65
69
  getHost: () => Promise<string>;
66
70
  getPublishableKey: () => Promise<string>;
67
71
  }
@@ -251,6 +251,35 @@ export interface RadarLogUpdateCallback {
251
251
  export interface RadarTokenUpdateCallback {
252
252
  (token: Object): void;
253
253
  }
254
+ export interface RadarInAppMessage {
255
+ title: {
256
+ text: string;
257
+ color: string;
258
+ };
259
+ body: {
260
+ text: string;
261
+ color: string;
262
+ };
263
+ button?: {
264
+ text: string;
265
+ color: string;
266
+ backgroundColor: string;
267
+ deepLink?: string;
268
+ };
269
+ image?: {
270
+ name: string;
271
+ url: string;
272
+ };
273
+ }
274
+ export interface RadarNewInAppMessageCallback {
275
+ (inAppMessage: RadarInAppMessage): void;
276
+ }
277
+ export interface RadarInAppMessageDismissedCallback {
278
+ (inAppMessage: RadarInAppMessage): void;
279
+ }
280
+ export interface RadarInAppMessageClickedCallback {
281
+ (inAppMessage: RadarInAppMessage): void;
282
+ }
254
283
  export type RadarListenerCallback = RadarEventUpdateCallback | RadarLocationUpdateCallback | RadarClientLocationUpdateCallback | RadarErrorCallback | RadarLogUpdateCallback | RadarTokenUpdateCallback;
255
284
  export type RadarPermissionsStatus = "GRANTED_FOREGROUND" | "GRANTED_BACKGROUND" | "DENIED" | "NOT_DETERMINED" | "UNKNOWN";
256
285
  export type RadarLocationSource = "FOREGROUND_LOCATION" | "BACKGROUND_LOCATION" | "MANUAL_LOCATION" | "VISIT_ARRIVAL" | "VISIT_DEPARTURE" | "GEOFENCE_ENTER" | "GEOFENCE_DWELL" | "GEOFENCE_EXIT" | "MOCK_LOCATION" | "BEACON_ENTER" | "BEACON_EXIT" | "UNKNOWN";
@@ -22,6 +22,15 @@ export type EventsEmitter = {
22
22
  export type TokenEmitter = {
23
23
  token: Object;
24
24
  };
25
+ export type NewInAppMessageEmitter = {
26
+ inAppMessage: Object;
27
+ };
28
+ export type InAppMessageDismissedEmitter = {
29
+ inAppMessage: Object;
30
+ };
31
+ export type InAppMessageClickedEmitter = {
32
+ inAppMessage: Object;
33
+ };
25
34
  export interface Spec extends TurboModule {
26
35
  initialize(publishableKey: string, fraud: boolean): void;
27
36
  requestPermissions(background: boolean): Promise<string>;
@@ -80,12 +89,16 @@ export interface Spec extends TurboModule {
80
89
  nativeSdkVersion(): Promise<string>;
81
90
  getHost(): Promise<string>;
82
91
  getPublishableKey(): Promise<string>;
92
+ showInAppMessage(inAppMessage: Object): void;
83
93
  readonly locationEmitter: EventEmitter<LocationEmitter>;
84
94
  readonly clientLocationEmitter: EventEmitter<ClientLocationEmitter>;
85
95
  readonly errorEmitter: EventEmitter<ErrorEmitter>;
86
96
  readonly logEmitter: EventEmitter<LogEmitter>;
87
97
  readonly eventsEmitter: EventEmitter<EventsEmitter>;
88
98
  readonly tokenEmitter: EventEmitter<TokenEmitter>;
99
+ readonly newInAppMessageEmitter: EventEmitter<NewInAppMessageEmitter>;
100
+ readonly inAppMessageDismissedEmitter: EventEmitter<InAppMessageDismissedEmitter>;
101
+ readonly inAppMessageClickedEmitter: EventEmitter<InAppMessageClickedEmitter>;
89
102
  }
90
103
  declare const _default: Spec;
91
104
  export default _default;
@@ -1,7 +1,7 @@
1
1
  import type { EventSubscription } from "react-native";
2
2
  import type { RadarNativeInterface } from "./@types/RadarNativeInterface";
3
3
  declare const NativeRadar: import("./NativeRadar").Spec;
4
- type Events = "locationEmitter" | "clientLocationEmitter" | "errorEmitter" | "logEmitter" | "eventsEmitter" | "tokenEmitter";
4
+ type Events = "locationEmitter" | "clientLocationEmitter" | "errorEmitter" | "logEmitter" | "eventsEmitter" | "tokenEmitter" | "newInAppMessageEmitter" | "inAppMessageDismissedEmitter" | "inAppMessageClickedEmitter";
5
5
  export declare function addListener<EventT extends Events>(event: EventT, handler: Parameters<(typeof NativeRadar)[EventT]>[0]): EventSubscription;
6
6
  declare const Radar: RadarNativeInterface;
7
7
  export default Radar;
@@ -45,9 +45,16 @@ let errorUpdateSubscription = null;
45
45
  let logUpdateSubscription = null;
46
46
  let eventsUpdateSubscription = null;
47
47
  let tokenUpdateSubscription = null;
48
+ let newInAppMessageUpdateSubscription = null;
49
+ let inAppMessageDismissedUpdateSubscription = null;
50
+ let inAppMessageClickedUpdateSubscription = null;
48
51
  const Radar = {
49
52
  initialize: (publishableKey, fraud) => {
50
- return NativeRadar.initialize(publishableKey, !!fraud);
53
+ NativeRadar.initialize(publishableKey, !!fraud);
54
+ Radar.onNewInAppMessage((inAppMessage) => {
55
+ Radar.showInAppMessage(inAppMessage);
56
+ });
57
+ return;
51
58
  },
52
59
  trackOnce: (options) => __awaiter(void 0, void 0, void 0, function* () {
53
60
  return NativeRadar.trackOnce(options || null);
@@ -145,6 +152,45 @@ const Radar = {
145
152
  callback(event.token);
146
153
  });
147
154
  },
155
+ onNewInAppMessage: (callback) => {
156
+ if (newInAppMessageUpdateSubscription) {
157
+ newInAppMessageUpdateSubscription.remove();
158
+ newInAppMessageUpdateSubscription = null;
159
+ }
160
+ if (!callback) {
161
+ return;
162
+ }
163
+ newInAppMessageUpdateSubscription = addListener("newInAppMessageEmitter", (event) => {
164
+ callback(event.inAppMessage);
165
+ });
166
+ },
167
+ onInAppMessageDismissed: (callback) => {
168
+ if (inAppMessageDismissedUpdateSubscription) {
169
+ inAppMessageDismissedUpdateSubscription.remove();
170
+ inAppMessageDismissedUpdateSubscription = null;
171
+ }
172
+ if (!callback) {
173
+ return;
174
+ }
175
+ inAppMessageDismissedUpdateSubscription = addListener("inAppMessageDismissedEmitter", (event) => {
176
+ callback(event.inAppMessage);
177
+ });
178
+ },
179
+ onInAppMessageClicked: (callback) => {
180
+ if (inAppMessageClickedUpdateSubscription) {
181
+ inAppMessageClickedUpdateSubscription.remove();
182
+ inAppMessageClickedUpdateSubscription = null;
183
+ }
184
+ if (!callback) {
185
+ return;
186
+ }
187
+ inAppMessageClickedUpdateSubscription = addListener("inAppMessageClickedEmitter", (event) => {
188
+ callback(event.inAppMessage);
189
+ });
190
+ },
191
+ showInAppMessage: (inAppMessage) => {
192
+ return NativeRadar.showInAppMessage(inAppMessage);
193
+ },
148
194
  requestPermissions: (background) => {
149
195
  return NativeRadar.requestPermissions(background);
150
196
  },
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "3.23.0";
1
+ export declare const VERSION = "3.23.2";
package/dist/version.js CHANGED
@@ -3,4 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  // This file contains the version of the react-native-radar package
5
5
  // It should be updated to match the version in package.json
6
- exports.VERSION = '3.23.0';
6
+ exports.VERSION = '3.23.2';
package/ios/RNRadar.h CHANGED
@@ -9,9 +9,9 @@
9
9
  #import <React/RCTBridgeModule.h>
10
10
 
11
11
  #ifdef RCT_NEW_ARCH_ENABLED
12
- @interface RNRadar : NativeRadarSpecBase <NativeRadarSpec, RadarDelegate, CLLocationManagerDelegate, RadarVerifiedDelegate>
12
+ @interface RNRadar : NativeRadarSpecBase <NativeRadarSpec, RadarDelegate, CLLocationManagerDelegate, RadarVerifiedDelegate, RadarInAppMessageProtocol>
13
13
  #else
14
- @interface RNRadar : RCTEventEmitter <RCTBridgeModule, RadarDelegate, CLLocationManagerDelegate, RadarVerifiedDelegate>
14
+ @interface RNRadar : RCTEventEmitter <RCTBridgeModule, RadarDelegate, CLLocationManagerDelegate, RadarVerifiedDelegate, RadarInAppMessageProtocol>
15
15
  #endif
16
16
 
17
17
  @end
package/ios/RNRadar.mm CHANGED
@@ -18,6 +18,7 @@ RCT_EXPORT_MODULE()
18
18
  locationManager.delegate = self;
19
19
  [Radar setDelegate:self];
20
20
  [Radar setVerifiedDelegate:self];
21
+ [Radar setInAppMessageDelegate:self];
21
22
  }
22
23
  return self;
23
24
  }
@@ -38,7 +39,7 @@ RCT_EXPORT_MODULE()
38
39
  }
39
40
 
40
41
  - (NSArray<NSString *> *)supportedEvents {
41
- return @[@"eventsEmitter", @"locationEmitter", @"clientLocationEmitter", @"errorEmitter", @"logEmitter", @"tokenEmitter"];
42
+ return @[@"eventsEmitter", @"locationEmitter", @"clientLocationEmitter", @"errorEmitter", @"logEmitter", @"tokenEmitter", @"newInAppMessageEmitter", @"inAppMessageDismissedEmitter", @"inAppMessageClickedEmitter"];
42
43
  }
43
44
 
44
45
  - (void)startObserving {
@@ -49,6 +50,52 @@ RCT_EXPORT_MODULE()
49
50
  hasListeners = NO;
50
51
  }
51
52
 
53
+ - (void)onNewInAppMessage:(RadarInAppMessage *)inAppMessage {
54
+
55
+ NSMutableDictionary *body = [NSMutableDictionary new];
56
+ [body setValue:[Radar dictionaryForInAppMessage:inAppMessage] forKey:@"inAppMessage"];
57
+ #ifdef RCT_NEW_ARCH_ENABLED
58
+ [self emitNewInAppMessageEmitter:body];
59
+ #else
60
+ if (hasListeners) {
61
+ [self sendEventWithName:@"newInAppMessageEmitter" body:body];
62
+ }
63
+ #endif
64
+ }
65
+
66
+ - (void)onInAppMessageDismissed:(RadarInAppMessage *)inAppMessage {
67
+ NSMutableDictionary *body = [NSMutableDictionary new];
68
+ [body setValue:[Radar dictionaryForInAppMessage:inAppMessage] forKey:@"inAppMessage"];
69
+ #ifdef RCT_NEW_ARCH_ENABLED
70
+ [self emitInAppMessageDismissedEmitter:body];
71
+ #else
72
+ if (hasListeners) {
73
+ [self sendEventWithName:@"inAppMessageDismissedEmitter" body:body];
74
+ }
75
+ #endif
76
+ }
77
+
78
+ - (void)onInAppMessageButtonClicked:(RadarInAppMessage *)inAppMessage {
79
+ NSMutableDictionary *body = [NSMutableDictionary new];
80
+ [body setValue:[Radar dictionaryForInAppMessage:inAppMessage] forKey:@"inAppMessage"];
81
+ #ifdef RCT_NEW_ARCH_ENABLED
82
+ [self emitInAppMessageClickedEmitter:body];
83
+ #else
84
+ if (hasListeners) {
85
+ [self sendEventWithName:@"inAppMessageClickedEmitter" body:body];
86
+ }
87
+ #endif
88
+ }
89
+
90
+ - (void) createInAppMessageView:(RadarInAppMessage * _Nonnull)message
91
+ onDismiss:(void (^)(void))onDismiss
92
+ onInAppMessageClicked:(void (^)(void))onInAppMessageClicked
93
+ completionHandler:(void (^)(UIViewController *))completionHandler {
94
+ RadarInAppMessageDelegate *delegate = [RadarInAppMessageDelegate new];
95
+ [delegate createInAppMessageView:message onDismiss:onDismiss onInAppMessageClicked:onInAppMessageClicked completionHandler:completionHandler];
96
+
97
+ }
98
+
52
99
  - (void)didReceiveEvents:(NSArray<RadarEvent *> *)events user:(RadarUser * _Nullable )user {
53
100
  NSMutableDictionary *body = [NSMutableDictionary new];
54
101
  [body setValue:[RadarEvent arrayForEvents:events] forKey:@"events"];
@@ -139,7 +186,7 @@ RCT_EXPORT_MODULE()
139
186
 
140
187
  RCT_EXPORT_METHOD(initialize:(NSString *)publishableKey fraud:(BOOL)fraud) {
141
188
  [[NSUserDefaults standardUserDefaults] setObject:@"ReactNative" forKey:@"radar-xPlatformSDKType"];
142
- [[NSUserDefaults standardUserDefaults] setObject:@"3.23.0" forKey:@"radar-xPlatformSDKVersion"];
189
+ [[NSUserDefaults standardUserDefaults] setObject:@"3.23.2" forKey:@"radar-xPlatformSDKVersion"];
143
190
  [Radar initializeWithPublishableKey:publishableKey];
144
191
  }
145
192
 
@@ -1240,6 +1287,13 @@ RCT_EXPORT_METHOD(getMatrix:(NSDictionary *)optionsDict resolve:(RCTPromiseResol
1240
1287
  }];
1241
1288
  }
1242
1289
 
1290
+ RCT_EXPORT_METHOD(showInAppMessage:(NSDictionary *)inAppMessageDict) {
1291
+ RadarInAppMessage *inAppMessage = [RadarInAppMessage fromDictionary:inAppMessageDict];
1292
+ if (inAppMessage != nil) {
1293
+ [Radar showInAppMessage:inAppMessage];
1294
+ }
1295
+ }
1296
+
1243
1297
  RCT_EXPORT_METHOD(logConversion:(NSDictionary *)optionsDict resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
1244
1298
  if (optionsDict == nil) {
1245
1299
  if (reject) {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "React Native module for Radar, the leading geofencing and location tracking platform",
4
4
  "homepage": "https://radar.com",
5
5
  "license": "Apache-2.0",
6
- "version": "3.23.0",
6
+ "version": "3.23.2",
7
7
  "main": "dist/index.js",
8
8
  "files": [
9
9
  "dist",
@@ -4,6 +4,7 @@ exports.withRadarIOS = void 0;
4
4
  const { withInfoPlist, withDangerousMod } = require("expo/config-plugins");
5
5
  const fs = require('fs/promises');
6
6
  const path = require('path');
7
+ const pkg = require("../../package.json");
7
8
  const withRadarIOS = (config, args) => {
8
9
  config = withInfoPlist(config, (config) => {
9
10
  config.modResults.NSLocationWhenInUseUsageDescription =
@@ -48,7 +49,7 @@ const withRadarIOS = (config, args) => {
48
49
  const filePath = path.join(config.modRequest.platformProjectRoot, 'Podfile');
49
50
  const contents = await fs.readFile(filePath, 'utf-8');
50
51
  // Check if the pod declaration already exists
51
- if (contents.indexOf("pod 'RadarSDKMotion', '3.20.1'") === -1) {
52
+ if (contents.indexOf(`pod 'RadarSDKMotion', '${pkg.version}'`) === -1) {
52
53
  // Find the target block
53
54
  const targetRegex = /target '(\w+)' do/g;
54
55
  const match = targetRegex.exec(contents);
@@ -58,7 +59,7 @@ const withRadarIOS = (config, args) => {
58
59
  // Insert the pod declaration within the target block
59
60
  const targetBlock = contents.substring(targetStartIndex, targetEndIndex);
60
61
  // Just for this version of the SDK, we will be using 3.21.1 of the SDKMotion pod. There is no difference between the source code of 3.21.2 and 3.21.1 for RadarSDKMotion.
61
- const updatedTargetBlock = targetBlock.replace(/(target '(\w+)' do)/, `$1\n pod 'RadarSDKMotion', '3.20.1'`);
62
+ const updatedTargetBlock = targetBlock.replace(/(target '(\w+)' do)/, `$1\n pod 'RadarSDKMotion', '${pkg.version}'`);
62
63
  const newContents = contents.replace(targetBlock, updatedTargetBlock);
63
64
  // Write the updated contents back to the Podfile
64
65
  await fs.writeFile(filePath, newContents);
@@ -42,6 +42,10 @@ import type {
42
42
  RadarLogConversionCallback,
43
43
  RadarRouteMatrix,
44
44
  Location,
45
+ RadarNewInAppMessageCallback,
46
+ RadarInAppMessageDismissedCallback,
47
+ RadarInAppMessageClickedCallback,
48
+ RadarInAppMessage,
45
49
  } from "./types";
46
50
 
47
51
  export interface RadarNativeInterface {
@@ -119,6 +123,7 @@ export interface RadarNativeInterface {
119
123
  ) => Promise<RadarLogConversionCallback>;
120
124
  nativeSdkVersion: () => Promise<string>;
121
125
  rnSdkVersion: () => string;
126
+ showInAppMessage: (inAppMessage: RadarInAppMessage) => void;
122
127
 
123
128
  onLocationUpdated: (callback: RadarLocationUpdateCallback | null) => void;
124
129
  onClientLocationUpdated: (
@@ -128,6 +133,9 @@ export interface RadarNativeInterface {
128
133
  onLog: (callback: RadarLogUpdateCallback | null) => void;
129
134
  onEventsReceived: (callback: RadarEventUpdateCallback | null) => void;
130
135
  onTokenUpdated: (callback: RadarTokenUpdateCallback | null) => void;
136
+ onNewInAppMessage: (callback: RadarNewInAppMessageCallback | null) => void;
137
+ onInAppMessageDismissed: (callback: RadarInAppMessageDismissedCallback | null) => void;
138
+ onInAppMessageClicked: (callback: RadarInAppMessageClickedCallback | null) => void;
131
139
  getHost: () => Promise<string>;
132
140
  getPublishableKey: () => Promise<string>;
133
141
  }
@@ -431,6 +431,39 @@ export interface RadarTokenUpdateCallback {
431
431
  (token: Object): void;
432
432
  }
433
433
 
434
+ export interface RadarInAppMessage {
435
+ title: {
436
+ text: string;
437
+ color: string;
438
+ };
439
+ body: {
440
+ text: string;
441
+ color: string;
442
+ };
443
+ button?: {
444
+ text: string;
445
+ color: string;
446
+ backgroundColor: string;
447
+ deepLink?: string;
448
+ };
449
+ image?: {
450
+ name: string;
451
+ url: string;
452
+ };
453
+ }
454
+
455
+ export interface RadarNewInAppMessageCallback {
456
+ (inAppMessage: RadarInAppMessage): void;
457
+ }
458
+
459
+ export interface RadarInAppMessageDismissedCallback {
460
+ (inAppMessage: RadarInAppMessage): void;
461
+ }
462
+
463
+ export interface RadarInAppMessageClickedCallback {
464
+ (inAppMessage: RadarInAppMessage): void;
465
+ }
466
+
434
467
  export type RadarListenerCallback =
435
468
  | RadarEventUpdateCallback
436
469
  | RadarLocationUpdateCallback
@@ -30,6 +30,18 @@ export type TokenEmitter = {
30
30
  token: Object;
31
31
  };
32
32
 
33
+ export type NewInAppMessageEmitter = {
34
+ inAppMessage: Object;
35
+ };
36
+
37
+ export type InAppMessageDismissedEmitter = {
38
+ inAppMessage: Object;
39
+ };
40
+
41
+ export type InAppMessageClickedEmitter = {
42
+ inAppMessage: Object;
43
+ };
44
+
33
45
  export interface Spec extends TurboModule {
34
46
  initialize(publishableKey: string, fraud: boolean): void;
35
47
  requestPermissions(background: boolean): Promise<string>;
@@ -88,12 +100,16 @@ export interface Spec extends TurboModule {
88
100
  nativeSdkVersion(): Promise<string>;
89
101
  getHost(): Promise<string>;
90
102
  getPublishableKey(): Promise<string>;
103
+ showInAppMessage(inAppMessage: Object): void;
91
104
  readonly locationEmitter: EventEmitter<LocationEmitter>;
92
105
  readonly clientLocationEmitter: EventEmitter<ClientLocationEmitter>;
93
106
  readonly errorEmitter: EventEmitter<ErrorEmitter>;
94
107
  readonly logEmitter: EventEmitter<LogEmitter>;
95
108
  readonly eventsEmitter: EventEmitter<EventsEmitter>;
96
109
  readonly tokenEmitter: EventEmitter<TokenEmitter>;
110
+ readonly newInAppMessageEmitter: EventEmitter<NewInAppMessageEmitter>;
111
+ readonly inAppMessageDismissedEmitter: EventEmitter<InAppMessageDismissedEmitter>;
112
+ readonly inAppMessageClickedEmitter: EventEmitter<InAppMessageClickedEmitter>;
97
113
  }
98
114
 
99
115
  export default TurboModuleRegistry.getEnforcing<Spec>("RNRadar");
@@ -47,6 +47,10 @@ import type {
47
47
  RadarUser,
48
48
  Location,
49
49
  RadarEvent,
50
+ RadarNewInAppMessageCallback,
51
+ RadarInAppMessageDismissedCallback,
52
+ RadarInAppMessageClickedCallback,
53
+ RadarInAppMessage,
50
54
  } from "./@types/types";
51
55
  import { NativeEventEmitter, NativeModules } from "react-native";
52
56
  import { VERSION } from "./version";
@@ -56,6 +60,9 @@ import NativeRadarMod, {
56
60
  EventsEmitter,
57
61
  LocationEmitter,
58
62
  LogEmitter,
63
+ InAppMessageClickedEmitter,
64
+ InAppMessageDismissedEmitter,
65
+ NewInAppMessageEmitter,
59
66
  TokenEmitter,
60
67
  } from "./NativeRadar";
61
68
 
@@ -85,7 +92,10 @@ type Events =
85
92
  | "errorEmitter"
86
93
  | "logEmitter"
87
94
  | "eventsEmitter"
88
- | "tokenEmitter";
95
+ | "tokenEmitter"
96
+ | "newInAppMessageEmitter"
97
+ | "inAppMessageDismissedEmitter"
98
+ | "inAppMessageClickedEmitter";
89
99
 
90
100
  export function addListener<EventT extends Events>(
91
101
  event: EventT,
@@ -103,10 +113,17 @@ let errorUpdateSubscription: EventSubscription | null = null;
103
113
  let logUpdateSubscription: EventSubscription | null = null;
104
114
  let eventsUpdateSubscription: EventSubscription | null = null;
105
115
  let tokenUpdateSubscription: EventSubscription | null = null;
116
+ let newInAppMessageUpdateSubscription: EventSubscription | null = null;
117
+ let inAppMessageDismissedUpdateSubscription: EventSubscription | null = null;
118
+ let inAppMessageClickedUpdateSubscription: EventSubscription | null = null;
106
119
 
107
120
  const Radar: RadarNativeInterface = {
108
121
  initialize: (publishableKey: string, fraud?: boolean) => {
109
- return NativeRadar.initialize(publishableKey, !!fraud);
122
+ NativeRadar.initialize(publishableKey, !!fraud);
123
+ Radar.onNewInAppMessage((inAppMessage) => {
124
+ Radar.showInAppMessage(inAppMessage);
125
+ });
126
+ return;
110
127
  },
111
128
 
112
129
  trackOnce: async (options?: RadarTrackOnceOptions) => {
@@ -242,6 +259,64 @@ const Radar: RadarNativeInterface = {
242
259
  );
243
260
  },
244
261
 
262
+ onNewInAppMessage: (callback: RadarNewInAppMessageCallback | null) => {
263
+ if (newInAppMessageUpdateSubscription) {
264
+ newInAppMessageUpdateSubscription.remove();
265
+ newInAppMessageUpdateSubscription = null;
266
+ }
267
+
268
+ if (!callback) {
269
+ return;
270
+ }
271
+
272
+ newInAppMessageUpdateSubscription = addListener(
273
+ "newInAppMessageEmitter",
274
+ (event: NewInAppMessageEmitter) => {
275
+ callback(event.inAppMessage as RadarInAppMessage);
276
+ }
277
+ );
278
+ },
279
+
280
+ onInAppMessageDismissed: (callback: RadarInAppMessageDismissedCallback | null) => {
281
+ if (inAppMessageDismissedUpdateSubscription) {
282
+ inAppMessageDismissedUpdateSubscription.remove();
283
+ inAppMessageDismissedUpdateSubscription = null;
284
+ }
285
+
286
+ if (!callback) {
287
+ return;
288
+ }
289
+
290
+ inAppMessageDismissedUpdateSubscription = addListener(
291
+ "inAppMessageDismissedEmitter",
292
+ (event: InAppMessageDismissedEmitter) => {
293
+ callback(event.inAppMessage as RadarInAppMessage);
294
+ }
295
+ );
296
+ },
297
+
298
+ onInAppMessageClicked: (callback: RadarInAppMessageClickedCallback | null) => {
299
+ if (inAppMessageClickedUpdateSubscription) {
300
+ inAppMessageClickedUpdateSubscription.remove();
301
+ inAppMessageClickedUpdateSubscription = null;
302
+ }
303
+
304
+ if (!callback) {
305
+ return;
306
+ }
307
+
308
+ inAppMessageClickedUpdateSubscription = addListener(
309
+ "inAppMessageClickedEmitter",
310
+ (event: InAppMessageClickedEmitter) => {
311
+ callback(event.inAppMessage as RadarInAppMessage);
312
+ }
313
+ );
314
+ },
315
+
316
+ showInAppMessage: (inAppMessage: RadarInAppMessage) => {
317
+ return NativeRadar.showInAppMessage(inAppMessage);
318
+ },
319
+
245
320
  requestPermissions: (background: boolean) => {
246
321
  return NativeRadar.requestPermissions(
247
322
  background
package/src/version.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  // This file contains the version of the react-native-radar package
2
2
  // It should be updated to match the version in package.json
3
- export const VERSION = '3.23.0';
3
+ export const VERSION = '3.23.2';