react-native-radar 4.33.0 → 4.34.0
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/android/src/newarch/java/com/radar/RadarModule.kt +33 -2
- package/android/src/oldarch/java/com/radar/RadarModule.java +10 -2
- package/dist/@types/RadarNativeInterface.d.ts +1 -0
- package/dist/NativeRadar.d.ts +1 -0
- package/dist/helpers.d.ts +1 -0
- package/dist/helpers.js +3 -1
- package/dist/index.native.js +3 -0
- package/dist/ui/map.jsx +32 -4
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/ios/RNRadar.h +3 -2
- package/ios/RNRadar.mm +22 -2
- package/package.json +1 -1
- package/src/@types/RadarNativeInterface.ts +1 -0
- package/src/NativeRadar.ts +1 -0
- package/src/helpers.js +5 -1
- package/src/index.native.ts +3 -0
- package/src/ui/map.jsx +32 -4
- package/src/version.ts +1 -1
|
@@ -40,9 +40,12 @@ import org.json.JSONObject
|
|
|
40
40
|
@ReactModule(name = RadarModule.NAME)
|
|
41
41
|
class RadarModule(reactContext: ReactApplicationContext) :
|
|
42
42
|
NativeRadarSpec(reactContext), PermissionListener {
|
|
43
|
+
@Volatile
|
|
44
|
+
private var isInvalidated = false
|
|
43
45
|
|
|
44
46
|
private val radarReceiver = object : RadarReceiver() {
|
|
45
47
|
override fun onEventsReceived(context: Context, events: Array<RadarEvent>, user: RadarUser?) {
|
|
48
|
+
if (isInvalidated) return
|
|
46
49
|
val eventBlob = Arguments.createMap().apply {
|
|
47
50
|
var eventsArray = Arguments.createArray()
|
|
48
51
|
for (event in events) {
|
|
@@ -57,6 +60,7 @@ class RadarModule(reactContext: ReactApplicationContext) :
|
|
|
57
60
|
}
|
|
58
61
|
|
|
59
62
|
override fun onLocationUpdated(context: Context, location: Location, user: RadarUser) {
|
|
63
|
+
if (isInvalidated) return
|
|
60
64
|
val eventBlob = Arguments.createMap().apply {
|
|
61
65
|
putString("location", Radar.jsonForLocation(location).toString())
|
|
62
66
|
putString("user", user.toJson().toString())
|
|
@@ -65,6 +69,7 @@ class RadarModule(reactContext: ReactApplicationContext) :
|
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
override fun onClientLocationUpdated(context: Context, location: Location, stopped: Boolean, source: Radar.RadarLocationSource) {
|
|
72
|
+
if (isInvalidated) return
|
|
68
73
|
val eventBlob = Arguments.createMap().apply {
|
|
69
74
|
putString("location", Radar.jsonForLocation(location).toString())
|
|
70
75
|
putBoolean("stopped", stopped)
|
|
@@ -74,6 +79,7 @@ class RadarModule(reactContext: ReactApplicationContext) :
|
|
|
74
79
|
}
|
|
75
80
|
|
|
76
81
|
override fun onError(context: Context, status: Radar.RadarStatus) {
|
|
82
|
+
if (isInvalidated) return
|
|
77
83
|
val eventBlob = Arguments.createMap().apply {
|
|
78
84
|
putString("status", status.toString())
|
|
79
85
|
}
|
|
@@ -81,6 +87,7 @@ class RadarModule(reactContext: ReactApplicationContext) :
|
|
|
81
87
|
}
|
|
82
88
|
|
|
83
89
|
override fun onLog(context: Context, message: String) {
|
|
90
|
+
if (isInvalidated) return
|
|
84
91
|
val eventBlob = Arguments.createMap().apply {
|
|
85
92
|
putString("message", message)
|
|
86
93
|
}
|
|
@@ -90,6 +97,7 @@ class RadarModule(reactContext: ReactApplicationContext) :
|
|
|
90
97
|
|
|
91
98
|
private val radarInAppMessageReceiver = object : RadarInAppMessageReceiver {
|
|
92
99
|
override fun onNewInAppMessage(message: RadarInAppMessage) {
|
|
100
|
+
if (isInvalidated) return
|
|
93
101
|
try {
|
|
94
102
|
val eventBlob = Arguments.createMap().apply {
|
|
95
103
|
putMap("inAppMessage", RadarUtils.mapForJson(JSONObject(message.toJson())))
|
|
@@ -101,6 +109,7 @@ class RadarModule(reactContext: ReactApplicationContext) :
|
|
|
101
109
|
}
|
|
102
110
|
|
|
103
111
|
override fun onInAppMessageDismissed(message: RadarInAppMessage) {
|
|
112
|
+
if (isInvalidated) return
|
|
104
113
|
try {
|
|
105
114
|
val eventBlob = Arguments.createMap().apply {
|
|
106
115
|
putMap("inAppMessage", RadarUtils.mapForJson(JSONObject(message.toJson())))
|
|
@@ -112,6 +121,7 @@ class RadarModule(reactContext: ReactApplicationContext) :
|
|
|
112
121
|
}
|
|
113
122
|
|
|
114
123
|
override fun onInAppMessageButtonClicked(message: RadarInAppMessage) {
|
|
124
|
+
if (isInvalidated) return
|
|
115
125
|
try {
|
|
116
126
|
val eventBlob = Arguments.createMap().apply {
|
|
117
127
|
putMap("inAppMessage", RadarUtils.mapForJson(JSONObject(message.toJson())))
|
|
@@ -125,6 +135,7 @@ class RadarModule(reactContext: ReactApplicationContext) :
|
|
|
125
135
|
|
|
126
136
|
private val radarVerifiedReceiver = object : RadarVerifiedReceiver() {
|
|
127
137
|
override fun onTokenUpdated(context: Context, token: RadarVerifiedLocationToken) {
|
|
138
|
+
if (isInvalidated) return
|
|
128
139
|
val eventBlob = Arguments.createMap().apply {
|
|
129
140
|
putString("token", token.toJson().toString())
|
|
130
141
|
}
|
|
@@ -140,10 +151,26 @@ class RadarModule(reactContext: ReactApplicationContext) :
|
|
|
140
151
|
return NAME
|
|
141
152
|
}
|
|
142
153
|
|
|
154
|
+
override fun invalidate() {
|
|
155
|
+
isInvalidated = true
|
|
156
|
+
|
|
157
|
+
// Detach from the process-level Radar singleton so this stale module
|
|
158
|
+
// instance stops receiving callbacks after its JS runtime is gone.
|
|
159
|
+
Radar.setReceiver(null)
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
Radar.setVerifiedReceiver(null)
|
|
163
|
+
} catch (e: Exception) {
|
|
164
|
+
Log.e(TAG, "Error detaching verified receiver", e)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
super.invalidate()
|
|
168
|
+
}
|
|
169
|
+
|
|
143
170
|
override fun initialize(publishableKey: String, fraud: Boolean, options: ReadableMap?): Unit {
|
|
144
171
|
val editor = reactApplicationContext.getSharedPreferences("RadarSDK", Context.MODE_PRIVATE).edit()
|
|
145
172
|
editor.putString("x_platform_sdk_type", "ReactNative")
|
|
146
|
-
editor.putString("x_platform_sdk_version", "4.
|
|
173
|
+
editor.putString("x_platform_sdk_version", "4.34.0")
|
|
147
174
|
editor.apply()
|
|
148
175
|
|
|
149
176
|
Radar.initialize(reactApplicationContext, publishableKey, radarReceiver, Radar.RadarLocationServicesProvider.GOOGLE, fraud, null, radarInAppMessageReceiver, currentActivity)
|
|
@@ -155,7 +182,7 @@ class RadarModule(reactContext: ReactApplicationContext) :
|
|
|
155
182
|
override fun initializeWithAuthToken(authToken: String, fraud: Boolean, options: ReadableMap?): Unit {
|
|
156
183
|
val editor = reactApplicationContext.getSharedPreferences("RadarSDK", Context.MODE_PRIVATE).edit()
|
|
157
184
|
editor.putString("x_platform_sdk_type", "ReactNative")
|
|
158
|
-
editor.putString("x_platform_sdk_version", "4.
|
|
185
|
+
editor.putString("x_platform_sdk_version", "4.34.0")
|
|
159
186
|
editor.apply()
|
|
160
187
|
|
|
161
188
|
val initOptions = io.radar.sdk.RadarInitializeOptions.builder()
|
|
@@ -456,6 +483,10 @@ class RadarModule(reactContext: ReactApplicationContext) :
|
|
|
456
483
|
radarModuleImpl.getPublishableKey(promise)
|
|
457
484
|
}
|
|
458
485
|
|
|
486
|
+
override fun getMobileOrigin(promise: Promise): Unit {
|
|
487
|
+
promise.resolve(reactApplicationContext.packageName)
|
|
488
|
+
}
|
|
489
|
+
|
|
459
490
|
override fun showInAppMessage(inAppMessage: ReadableMap): Unit {
|
|
460
491
|
radarModuleImpl.showInAppMessage(inAppMessage)
|
|
461
492
|
}
|
|
@@ -102,7 +102,7 @@ public class RadarModule extends ReactContextBaseJavaModule implements Permissio
|
|
|
102
102
|
this.fraud = fraud;
|
|
103
103
|
SharedPreferences.Editor editor = getReactApplicationContext().getSharedPreferences("RadarSDK", Context.MODE_PRIVATE).edit();
|
|
104
104
|
editor.putString("x_platform_sdk_type", "ReactNative");
|
|
105
|
-
editor.putString("x_platform_sdk_version", "4.
|
|
105
|
+
editor.putString("x_platform_sdk_version", "4.34.0");
|
|
106
106
|
editor.apply();
|
|
107
107
|
Radar.initialize(getReactApplicationContext(), publishableKey, receiver, Radar.RadarLocationServicesProvider.GOOGLE, fraud, null, inAppMessageReceiver, getCurrentActivity());
|
|
108
108
|
if (fraud) {
|
|
@@ -115,7 +115,7 @@ public class RadarModule extends ReactContextBaseJavaModule implements Permissio
|
|
|
115
115
|
this.fraud = fraud;
|
|
116
116
|
SharedPreferences.Editor editor = getReactApplicationContext().getSharedPreferences("RadarSDK", Context.MODE_PRIVATE).edit();
|
|
117
117
|
editor.putString("x_platform_sdk_type", "ReactNative");
|
|
118
|
-
editor.putString("x_platform_sdk_version", "4.
|
|
118
|
+
editor.putString("x_platform_sdk_version", "4.34.0");
|
|
119
119
|
editor.apply();
|
|
120
120
|
|
|
121
121
|
io.radar.sdk.RadarInitializeOptions.Builder builder = io.radar.sdk.RadarInitializeOptions.builder()
|
|
@@ -474,6 +474,14 @@ public class RadarModule extends ReactContextBaseJavaModule implements Permissio
|
|
|
474
474
|
radarModuleImpl.getPublishableKey(promise);
|
|
475
475
|
}
|
|
476
476
|
|
|
477
|
+
@ReactMethod
|
|
478
|
+
public void getMobileOrigin(final Promise promise) {
|
|
479
|
+
if (promise == null) {
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
promise.resolve(getReactApplicationContext().getPackageName());
|
|
483
|
+
}
|
|
484
|
+
|
|
477
485
|
@ReactMethod
|
|
478
486
|
public void showInAppMessage(ReadableMap inAppMessageMap) {
|
|
479
487
|
radarModuleImpl.showInAppMessage(inAppMessageMap);
|
package/dist/NativeRadar.d.ts
CHANGED
|
@@ -92,6 +92,7 @@ export interface Spec extends TurboModule {
|
|
|
92
92
|
nativeSdkVersion(): Promise<string>;
|
|
93
93
|
getHost(): Promise<string>;
|
|
94
94
|
getPublishableKey(): Promise<string>;
|
|
95
|
+
getMobileOrigin(): Promise<string>;
|
|
95
96
|
showInAppMessage(inAppMessage: Object): void;
|
|
96
97
|
setPushNotificationToken(token: string): void;
|
|
97
98
|
isInitialized(): Promise<boolean>;
|
package/dist/helpers.d.ts
CHANGED
package/dist/helpers.js
CHANGED
|
@@ -3,9 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getPublishableKey = exports.getHost = void 0;
|
|
6
|
+
exports.getMobileOrigin = exports.getPublishableKey = exports.getHost = void 0;
|
|
7
7
|
const index_native_1 = __importDefault(require("./index.native"));
|
|
8
8
|
const getHost = () => (index_native_1.default.getHost());
|
|
9
9
|
exports.getHost = getHost;
|
|
10
10
|
const getPublishableKey = () => (index_native_1.default.getPublishableKey());
|
|
11
11
|
exports.getPublishableKey = getPublishableKey;
|
|
12
|
+
const getMobileOrigin = () => (index_native_1.default.getMobileOrigin());
|
|
13
|
+
exports.getMobileOrigin = getMobileOrigin;
|
package/dist/index.native.js
CHANGED
|
@@ -388,6 +388,9 @@ const Radar = {
|
|
|
388
388
|
getPublishableKey: function () {
|
|
389
389
|
return NativeRadar.getPublishableKey();
|
|
390
390
|
},
|
|
391
|
+
getMobileOrigin: function () {
|
|
392
|
+
return NativeRadar.getMobileOrigin();
|
|
393
|
+
},
|
|
391
394
|
isInitialized: function () {
|
|
392
395
|
return NativeRadar.isInitialized();
|
|
393
396
|
},
|
package/dist/ui/map.jsx
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
import React, { useState, useEffect } from 'react';
|
|
2
2
|
import { View, Image } from 'react-native';
|
|
3
3
|
import Radar from '../index.native';
|
|
4
|
-
import { getHost, getPublishableKey } from '../helpers';
|
|
4
|
+
import { getHost, getPublishableKey, getMobileOrigin } from '../helpers';
|
|
5
5
|
import styles from './styles';
|
|
6
6
|
|
|
7
7
|
let MapLibreGL;
|
|
8
8
|
let MapLibreMap;
|
|
9
9
|
let GeoJSONSource;
|
|
10
10
|
let Layer;
|
|
11
|
+
let TransformRequestManager;
|
|
11
12
|
try {
|
|
12
13
|
MapLibreGL = require('@maplibre/maplibre-react-native');
|
|
13
14
|
MapLibreMap = MapLibreGL.Map;
|
|
14
15
|
GeoJSONSource = MapLibreGL.GeoJSONSource;
|
|
15
16
|
Layer = MapLibreGL.Layer;
|
|
17
|
+
TransformRequestManager = MapLibreGL.TransformRequestManager;
|
|
16
18
|
} catch (e) {
|
|
17
19
|
MapLibreGL = null;
|
|
18
20
|
MapLibreMap = null;
|
|
19
21
|
GeoJSONSource = null;
|
|
20
22
|
Layer = null;
|
|
23
|
+
TransformRequestManager = null;
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
const DEFAULT_STYLE = 'radar-default-v1';
|
|
@@ -49,10 +52,35 @@ const RadarMap = ({ mapOptions, children }) => {
|
|
|
49
52
|
const [userLocation, setUserLocation] = useState(null);
|
|
50
53
|
|
|
51
54
|
useEffect(() => {
|
|
52
|
-
|
|
55
|
+
const setup = async () => {
|
|
56
|
+
const host = await getHost();
|
|
57
|
+
|
|
58
|
+
if (TransformRequestManager) {
|
|
59
|
+
try {
|
|
60
|
+
const mobileOrigin = await getMobileOrigin();
|
|
61
|
+
if (mobileOrigin) {
|
|
62
|
+
const mapHostPattern = `${host
|
|
63
|
+
.replace(/^https?:\/\//, '')
|
|
64
|
+
.replace(/\./g, '\\.')}/maps/`;
|
|
65
|
+
TransformRequestManager.addHeader({
|
|
66
|
+
id: 'radar-mobile-origin',
|
|
67
|
+
name: 'X-Radar-Mobile-Origin',
|
|
68
|
+
value: mobileOrigin,
|
|
69
|
+
match: mapHostPattern,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
} catch (err) {
|
|
73
|
+
// eslint-disable-next-line no-console
|
|
74
|
+
console.warn(`Radar SDK: Failed to set mobile origin header: ${err}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const result = await createStyleURL(mapOptions?.mapStyle || DEFAULT_STYLE);
|
|
53
79
|
setStyleURL(result);
|
|
54
|
-
}
|
|
55
|
-
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
setup();
|
|
83
|
+
}, [mapOptions?.mapStyle]);
|
|
56
84
|
|
|
57
85
|
useEffect(() => {
|
|
58
86
|
Radar.getLocation().then((result) => {
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "4.
|
|
1
|
+
export declare const VERSION = "4.34.0";
|
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 = '4.
|
|
6
|
+
exports.VERSION = '4.34.0';
|
package/ios/RNRadar.h
CHANGED
|
@@ -6,11 +6,12 @@
|
|
|
6
6
|
|
|
7
7
|
#import <RadarSDK/RadarSDK.h>
|
|
8
8
|
#import <React/RCTBridgeModule.h>
|
|
9
|
+
#import <React/RCTInvalidating.h>
|
|
9
10
|
|
|
10
11
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
11
|
-
@interface RNRadar : NativeRadarSpecBase <NativeRadarSpec, RadarDelegate, CLLocationManagerDelegate, RadarVerifiedDelegate, RadarInAppMessageProtocol>
|
|
12
|
+
@interface RNRadar : NativeRadarSpecBase <NativeRadarSpec, RadarDelegate, CLLocationManagerDelegate, RadarVerifiedDelegate, RadarInAppMessageProtocol, RCTInvalidating>
|
|
12
13
|
#else
|
|
13
|
-
@interface RNRadar : RCTEventEmitter <RCTBridgeModule, RadarDelegate, CLLocationManagerDelegate, RadarVerifiedDelegate, RadarInAppMessageProtocol>
|
|
14
|
+
@interface RNRadar : RCTEventEmitter <RCTBridgeModule, RadarDelegate, CLLocationManagerDelegate, RadarVerifiedDelegate, RadarInAppMessageProtocol, RCTInvalidating>
|
|
14
15
|
#endif
|
|
15
16
|
|
|
16
17
|
@end
|
package/ios/RNRadar.mm
CHANGED
|
@@ -55,6 +55,22 @@ RCT_EXPORT_MODULE()
|
|
|
55
55
|
hasListeners = NO;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
- (void)invalidate {
|
|
59
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
60
|
+
jsEventEmitterReady = NO;
|
|
61
|
+
#endif
|
|
62
|
+
hasListeners = NO;
|
|
63
|
+
|
|
64
|
+
// Detach from the process-level Radar singleton so a stale module
|
|
65
|
+
// instance doesn't continue to receive events.
|
|
66
|
+
[Radar setDelegate:nil];
|
|
67
|
+
[Radar setVerifiedDelegate:nil];
|
|
68
|
+
[Radar setInAppMessageDelegate:nil];
|
|
69
|
+
|
|
70
|
+
locationManager.delegate = nil;
|
|
71
|
+
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
72
|
+
}
|
|
73
|
+
|
|
58
74
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
59
75
|
- (void)setEventEmitterCallback:(EventEmitterCallbackWrapper *)eventEmitterCallbackWrapper {
|
|
60
76
|
[super setEventEmitterCallback:eventEmitterCallbackWrapper];
|
|
@@ -217,7 +233,7 @@ RCT_EXPORT_MODULE()
|
|
|
217
233
|
RCT_EXPORT_METHOD(initialize:(NSString *)publishableKey fraud:(BOOL)fraud options:(NSDictionary *)options) {
|
|
218
234
|
_publishableKey = publishableKey;
|
|
219
235
|
[[NSUserDefaults standardUserDefaults] setObject:@"ReactNative" forKey:@"radar-xPlatformSDKType"];
|
|
220
|
-
[[NSUserDefaults standardUserDefaults] setObject:@"4.
|
|
236
|
+
[[NSUserDefaults standardUserDefaults] setObject:@"4.34.0" forKey:@"radar-xPlatformSDKVersion"];
|
|
221
237
|
|
|
222
238
|
RadarInitializeOptions *radarOptions = [[RadarInitializeOptions alloc] init];
|
|
223
239
|
if (options != nil) {
|
|
@@ -240,7 +256,7 @@ RCT_EXPORT_METHOD(initialize:(NSString *)publishableKey fraud:(BOOL)fraud option
|
|
|
240
256
|
RCT_EXPORT_METHOD(initializeWithAuthToken:(NSString *)authToken fraud:(BOOL)fraud options:(NSDictionary *)options) {
|
|
241
257
|
_publishableKey = nil;
|
|
242
258
|
[[NSUserDefaults standardUserDefaults] setObject:@"ReactNative" forKey:@"radar-xPlatformSDKType"];
|
|
243
|
-
[[NSUserDefaults standardUserDefaults] setObject:@"4.
|
|
259
|
+
[[NSUserDefaults standardUserDefaults] setObject:@"4.34.0" forKey:@"radar-xPlatformSDKVersion"];
|
|
244
260
|
RadarInitializeOptions *radarOptions = [[RadarInitializeOptions alloc] init];
|
|
245
261
|
if (options != nil) {
|
|
246
262
|
id silentPushValue = options[@"silentPush"];
|
|
@@ -335,6 +351,10 @@ RCT_EXPORT_METHOD(getPublishableKey:(RCTPromiseResolveBlock)resolve reject:(RCTP
|
|
|
335
351
|
resolve(_publishableKey);
|
|
336
352
|
}
|
|
337
353
|
|
|
354
|
+
RCT_EXPORT_METHOD(getMobileOrigin:(RCTPromiseResolveBlock) resolve reject:(RCTPromiseRejectBlock)reject) {
|
|
355
|
+
resolve([[NSBundle mainBundle] bundleIdentifier]);
|
|
356
|
+
}
|
|
357
|
+
|
|
338
358
|
RCT_EXPORT_METHOD(getPermissionsStatus:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
|
|
339
359
|
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
|
|
340
360
|
NSString *statusStr;
|
package/package.json
CHANGED
package/src/NativeRadar.ts
CHANGED
|
@@ -103,6 +103,7 @@ export interface Spec extends TurboModule {
|
|
|
103
103
|
nativeSdkVersion(): Promise<string>;
|
|
104
104
|
getHost(): Promise<string>;
|
|
105
105
|
getPublishableKey(): Promise<string>;
|
|
106
|
+
getMobileOrigin(): Promise<string>;
|
|
106
107
|
showInAppMessage(inAppMessage: Object): void;
|
|
107
108
|
setPushNotificationToken(token: string): void;
|
|
108
109
|
isInitialized(): Promise<boolean>;
|
package/src/helpers.js
CHANGED
package/src/index.native.ts
CHANGED
|
@@ -570,6 +570,9 @@ const Radar: RadarNativeInterface = {
|
|
|
570
570
|
getPublishableKey: function (): Promise<string> {
|
|
571
571
|
return NativeRadar.getPublishableKey();
|
|
572
572
|
},
|
|
573
|
+
getMobileOrigin: function (): Promise<string> {
|
|
574
|
+
return NativeRadar.getMobileOrigin();
|
|
575
|
+
},
|
|
573
576
|
isInitialized: function (): Promise<boolean> {
|
|
574
577
|
return NativeRadar.isInitialized();
|
|
575
578
|
},
|
package/src/ui/map.jsx
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
import React, { useState, useEffect } from 'react';
|
|
2
2
|
import { View, Image } from 'react-native';
|
|
3
3
|
import Radar from '../index.native';
|
|
4
|
-
import { getHost, getPublishableKey } from '../helpers';
|
|
4
|
+
import { getHost, getPublishableKey, getMobileOrigin } from '../helpers';
|
|
5
5
|
import styles from './styles';
|
|
6
6
|
|
|
7
7
|
let MapLibreGL;
|
|
8
8
|
let MapLibreMap;
|
|
9
9
|
let GeoJSONSource;
|
|
10
10
|
let Layer;
|
|
11
|
+
let TransformRequestManager;
|
|
11
12
|
try {
|
|
12
13
|
MapLibreGL = require('@maplibre/maplibre-react-native');
|
|
13
14
|
MapLibreMap = MapLibreGL.Map;
|
|
14
15
|
GeoJSONSource = MapLibreGL.GeoJSONSource;
|
|
15
16
|
Layer = MapLibreGL.Layer;
|
|
17
|
+
TransformRequestManager = MapLibreGL.TransformRequestManager;
|
|
16
18
|
} catch (e) {
|
|
17
19
|
MapLibreGL = null;
|
|
18
20
|
MapLibreMap = null;
|
|
19
21
|
GeoJSONSource = null;
|
|
20
22
|
Layer = null;
|
|
23
|
+
TransformRequestManager = null;
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
const DEFAULT_STYLE = 'radar-default-v1';
|
|
@@ -49,10 +52,35 @@ const RadarMap = ({ mapOptions, children }) => {
|
|
|
49
52
|
const [userLocation, setUserLocation] = useState(null);
|
|
50
53
|
|
|
51
54
|
useEffect(() => {
|
|
52
|
-
|
|
55
|
+
const setup = async () => {
|
|
56
|
+
const host = await getHost();
|
|
57
|
+
|
|
58
|
+
if (TransformRequestManager) {
|
|
59
|
+
try {
|
|
60
|
+
const mobileOrigin = await getMobileOrigin();
|
|
61
|
+
if (mobileOrigin) {
|
|
62
|
+
const mapHostPattern = `${host
|
|
63
|
+
.replace(/^https?:\/\//, '')
|
|
64
|
+
.replace(/\./g, '\\.')}/maps/`;
|
|
65
|
+
TransformRequestManager.addHeader({
|
|
66
|
+
id: 'radar-mobile-origin',
|
|
67
|
+
name: 'X-Radar-Mobile-Origin',
|
|
68
|
+
value: mobileOrigin,
|
|
69
|
+
match: mapHostPattern,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
} catch (err) {
|
|
73
|
+
// eslint-disable-next-line no-console
|
|
74
|
+
console.warn(`Radar SDK: Failed to set mobile origin header: ${err}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const result = await createStyleURL(mapOptions?.mapStyle || DEFAULT_STYLE);
|
|
53
79
|
setStyleURL(result);
|
|
54
|
-
}
|
|
55
|
-
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
setup();
|
|
83
|
+
}, [mapOptions?.mapStyle]);
|
|
56
84
|
|
|
57
85
|
useEffect(() => {
|
|
58
86
|
Radar.getLocation().then((result) => {
|
package/src/version.ts
CHANGED