@situm/react-native 3.9.2 → 3.10.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.
Files changed (57) hide show
  1. package/android/src/main/java/com/situm/plugin/PluginHelper.java +91 -69
  2. package/android/src/main/java/com/situm/plugin/SitumMapper.java +6 -6
  3. package/android/src/main/java/com/situm/plugin/SitumPlugin.java +9 -2
  4. package/android/src/main/java/com/situm/plugin/SitumPluginImpl.java +10 -0
  5. package/android/src/main/java/com/situm/plugin/utils/ReactNativeUtils.java +284 -0
  6. package/ios/SitumLocationWrapper.m +4 -0
  7. package/ios/SitumPlugin.m +43 -27
  8. package/lib/commonjs/sdk/index.js +67 -20
  9. package/lib/commonjs/sdk/index.js.map +1 -1
  10. package/lib/commonjs/sdk/nativeInterface.js.map +1 -1
  11. package/lib/commonjs/sdk/types/constants.js +9 -4
  12. package/lib/commonjs/sdk/types/constants.js.map +1 -1
  13. package/lib/commonjs/sdk/types/index.js +1 -0
  14. package/lib/commonjs/sdk/types/index.js.map +1 -1
  15. package/lib/commonjs/wayfinding/components/MapView.js +21 -4
  16. package/lib/commonjs/wayfinding/components/MapView.js.map +1 -1
  17. package/lib/commonjs/wayfinding/hooks/index.js +25 -9
  18. package/lib/commonjs/wayfinding/hooks/index.js.map +1 -1
  19. package/lib/commonjs/wayfinding/utils/mapper.js +9 -1
  20. package/lib/commonjs/wayfinding/utils/mapper.js.map +1 -1
  21. package/lib/module/sdk/index.js +67 -20
  22. package/lib/module/sdk/index.js.map +1 -1
  23. package/lib/module/sdk/nativeInterface.js.map +1 -1
  24. package/lib/module/sdk/types/constants.js +9 -4
  25. package/lib/module/sdk/types/constants.js.map +1 -1
  26. package/lib/module/sdk/types/index.js +1 -0
  27. package/lib/module/sdk/types/index.js.map +1 -1
  28. package/lib/module/wayfinding/components/MapView.js +21 -4
  29. package/lib/module/wayfinding/components/MapView.js.map +1 -1
  30. package/lib/module/wayfinding/hooks/index.js +25 -9
  31. package/lib/module/wayfinding/hooks/index.js.map +1 -1
  32. package/lib/module/wayfinding/utils/mapper.js +9 -1
  33. package/lib/module/wayfinding/utils/mapper.js.map +1 -1
  34. package/lib/typescript/src/sdk/index.d.ts +36 -4
  35. package/lib/typescript/src/sdk/index.d.ts.map +1 -1
  36. package/lib/typescript/src/sdk/nativeInterface.d.ts +1 -0
  37. package/lib/typescript/src/sdk/nativeInterface.d.ts.map +1 -1
  38. package/lib/typescript/src/sdk/types/constants.d.ts +9 -4
  39. package/lib/typescript/src/sdk/types/constants.d.ts.map +1 -1
  40. package/lib/typescript/src/sdk/types/index.d.ts +2 -0
  41. package/lib/typescript/src/sdk/types/index.d.ts.map +1 -1
  42. package/lib/typescript/src/wayfinding/components/MapView.d.ts.map +1 -1
  43. package/lib/typescript/src/wayfinding/hooks/index.d.ts.map +1 -1
  44. package/lib/typescript/src/wayfinding/types/index.d.ts +18 -2
  45. package/lib/typescript/src/wayfinding/types/index.d.ts.map +1 -1
  46. package/lib/typescript/src/wayfinding/utils/mapper.d.ts +3 -1
  47. package/lib/typescript/src/wayfinding/utils/mapper.d.ts.map +1 -1
  48. package/package.json +2 -2
  49. package/src/sdk/index.ts +84 -23
  50. package/src/sdk/nativeInterface.ts +1 -0
  51. package/src/sdk/types/constants.ts +9 -4
  52. package/src/sdk/types/index.ts +2 -0
  53. package/src/wayfinding/components/MapView.tsx +31 -5
  54. package/src/wayfinding/hooks/index.ts +50 -10
  55. package/src/wayfinding/types/index.ts +21 -2
  56. package/src/wayfinding/utils/mapper.ts +11 -2
  57. package/android/src/main/java/com/situm/plugin/utils/ReactNativeJson.java +0 -122
@@ -12,7 +12,7 @@ import com.facebook.react.bridge.ReadableArray;
12
12
  import com.facebook.react.bridge.ReadableMap;
13
13
  import com.facebook.react.bridge.WritableMap;
14
14
  import com.facebook.react.modules.core.DeviceEventManagerModule;
15
- import com.situm.plugin.utils.ReactNativeJson;
15
+ import com.situm.plugin.utils.ReactNativeUtils;
16
16
 
17
17
  import org.json.JSONArray;
18
18
  import org.json.JSONException;
@@ -56,20 +56,28 @@ import es.situm.sdk.realtime.RealTimeRequest;
56
56
  import es.situm.sdk.utils.Handler;
57
57
  import es.situm.sdk.v1.SitumEvent;
58
58
  import es.situm.sdk.location.GeofenceListener;
59
+ import es.situm.sdk.navigation.ExternalNavigation;
59
60
 
60
61
  import static com.situm.plugin.SitumPlugin.EVENT_LOCATION_CHANGED;
61
62
  import static com.situm.plugin.SitumPlugin.EVENT_LOCATION_ERROR;
62
63
  import static com.situm.plugin.SitumPlugin.EVENT_LOCATION_STATUS_CHANGED;
63
64
  import static com.situm.plugin.SitumPlugin.EVENT_LOCATION_STOPPED;
65
+ import static com.situm.plugin.SitumPlugin.EVENT_NAVIGATION_START;
66
+ import static com.situm.plugin.SitumPlugin.EVENT_NAVIGATION_PROGRESS;
67
+ import static com.situm.plugin.SitumPlugin.EVENT_NAVIGATION_DESTINATION_REACHED;
68
+ import static com.situm.plugin.SitumPlugin.EVENT_NAVIGATION_FINISHED;
69
+ import static com.situm.plugin.SitumPlugin.EVENT_NAVIGATION_OUTSIDE_ROUTE;
70
+ import static com.situm.plugin.SitumPlugin.EVENT_NAVIGATION_CANCELLATION;
64
71
  import static com.situm.plugin.SitumPlugin.EVENT_NAVIGATION_ERROR;
65
- import static com.situm.plugin.SitumPlugin.EVENT_NAVIGATION_UPDATE;
66
72
  import static com.situm.plugin.SitumPlugin.EVENT_REALTIME_ERROR;
67
73
  import static com.situm.plugin.SitumPlugin.EVENT_REALTIME_UPDATE;
68
74
  import static com.situm.plugin.SitumPlugin.EVENT_ENTER_GEOFENCES;
69
75
  import static com.situm.plugin.SitumPlugin.EVENT_EXIT_GEOFENCES;
70
- import static com.situm.plugin.utils.ReactNativeJson.convertJsonToArray;
71
- import static com.situm.plugin.utils.ReactNativeJson.convertJsonToMap;
72
- import static com.situm.plugin.utils.ReactNativeJson.convertMapToJson;
76
+ import static com.situm.plugin.utils.ReactNativeUtils.convertJsonToArray;
77
+ import static com.situm.plugin.utils.ReactNativeUtils.convertJsonToMap;
78
+ import static com.situm.plugin.utils.ReactNativeUtils.convertMapToJson;
79
+ import static com.situm.plugin.utils.ReactNativeUtils.convertReadableMapToMap;
80
+ import static com.situm.plugin.utils.ReactNativeUtils.convertMapToReadableMap;
73
81
 
74
82
  public class PluginHelper {
75
83
 
@@ -132,10 +140,6 @@ public class PluginHelper {
132
140
  return nmInstance;
133
141
  }
134
142
 
135
- public void setNavigationManager(NavigationManager navigationManager) {
136
- nmInstance = navigationManager;
137
- }
138
-
139
143
  public void fetchBuildings(Callback success, Callback error) {
140
144
  try {
141
145
  getCommunicationManagerInstance().fetchBuildings(new Handler<Collection<Building>>() {
@@ -175,7 +179,7 @@ public class PluginHelper {
175
179
  // building, floors, events, indoorPois, outdoorPois, ¿geofences? ¿Paths?
176
180
  public void fetchTilesFromBuilding(ReadableMap buildingMap, Callback success, Callback error) {
177
181
  try {
178
- JSONObject jsonBuilding = ReactNativeJson.convertMapToJson(buildingMap);
182
+ JSONObject jsonBuilding = ReactNativeUtils.convertMapToJson(buildingMap);
179
183
  Building building = SitumMapper.buildingJsonObjectToBuilding(jsonBuilding);
180
184
 
181
185
  getCommunicationManagerInstance().fetchTilesFromBuilding(building.getIdentifier(), new Handler<String>() {
@@ -187,7 +191,7 @@ public class PluginHelper {
187
191
  JSONObject jsonObject = new JSONObject();
188
192
  jsonObject.put("results", url);
189
193
 
190
- invokeCallback(success, ReactNativeJson.convertJsonToMap(jsonObject));
194
+ invokeCallback(success, ReactNativeUtils.convertJsonToMap(jsonObject));
191
195
  } catch (JSONException e) {
192
196
  invokeCallback(error, e.getMessage());
193
197
  }
@@ -209,7 +213,7 @@ public class PluginHelper {
209
213
  // building, floors, events, indoorPois, outdoorPois, ¿geofences? ¿Paths?
210
214
  public void fetchBuildingInfo(ReadableMap buildingMap, Callback success, Callback error) {
211
215
  try {
212
- JSONObject jsonBuilding = ReactNativeJson.convertMapToJson(buildingMap);
216
+ JSONObject jsonBuilding = ReactNativeUtils.convertMapToJson(buildingMap);
213
217
  Building building = SitumMapper.buildingJsonObjectToBuilding(jsonBuilding);
214
218
 
215
219
  getCommunicationManagerInstance().fetchBuildingInfo(building, new Handler<BuildingInfo>() {
@@ -222,7 +226,7 @@ public class PluginHelper {
222
226
  // parse ? This needs to
223
227
  // be on sdk
224
228
 
225
- invokeCallback(success, ReactNativeJson.convertJsonToMap(jsonObject));
229
+ invokeCallback(success, ReactNativeUtils.convertJsonToMap(jsonObject));
226
230
  } catch (JSONException e) {
227
231
  invokeCallback(error, e.getMessage());
228
232
  }
@@ -243,7 +247,7 @@ public class PluginHelper {
243
247
 
244
248
  public void fetchFloorsFromBuilding(ReadableMap buildingMap, Callback success, Callback error) {
245
249
  try {
246
- JSONObject jsonBuilding = ReactNativeJson.convertMapToJson(buildingMap);
250
+ JSONObject jsonBuilding = ReactNativeUtils.convertMapToJson(buildingMap);
247
251
  Building building = SitumMapper.buildingJsonObjectToBuilding(jsonBuilding);
248
252
 
249
253
  getCommunicationManagerInstance().fetchFloorsFromBuilding(building, new Handler<Collection<Floor>>() {
@@ -281,7 +285,7 @@ public class PluginHelper {
281
285
 
282
286
  public void fetchMapFromFloor(ReadableMap buildingMap, Callback success, Callback error) {
283
287
  try {
284
- JSONObject jsonFloor = ReactNativeJson.convertMapToJson(buildingMap);
288
+ JSONObject jsonFloor = ReactNativeUtils.convertMapToJson(buildingMap);
285
289
  Floor floor = SitumMapper.floorJsonObjectToFloor(jsonFloor);
286
290
 
287
291
  getCommunicationManagerInstance().fetchMapFromFloor(floor, new Handler<Bitmap>() {
@@ -309,7 +313,7 @@ public class PluginHelper {
309
313
 
310
314
  public void fetchGeofencesFromBuilding(ReadableMap buildingMap, Callback success, Callback error) {
311
315
  try {
312
- JSONObject jsonBuilding = ReactNativeJson.convertMapToJson(buildingMap);
316
+ JSONObject jsonBuilding = ReactNativeUtils.convertMapToJson(buildingMap);
313
317
  Building building = SitumMapper.buildingJsonObjectToBuilding(jsonBuilding);
314
318
 
315
319
  getCommunicationManagerInstance().fetchGeofencesFromBuilding(building, new Handler<List<Geofence>>() {
@@ -355,7 +359,7 @@ public class PluginHelper {
355
359
  SitumSdk.locationManager().removeLocationListener(locationListener);
356
360
  }
357
361
 
358
- JSONObject jsonRequst = ReactNativeJson.convertMapToJson(locationRequestMap);
362
+ JSONObject jsonRequst = ReactNativeUtils.convertMapToJson(locationRequestMap);
359
363
  LocationRequest.Builder locationBuilder = new LocationRequest.Builder();
360
364
  SitumMapper.locationRequestJSONObjectToLocationRequest(jsonRequst, locationBuilder);
361
365
  LocationRequest locationRequest = locationBuilder.build();
@@ -632,58 +636,7 @@ public class PluginHelper {
632
636
 
633
637
  navigationRequest = builder.build();
634
638
 
635
- // 2.2) Build Navigation Callback
636
- navigationListener = new NavigationListener() {
637
- public void onProgress(NavigationProgress progress) {
638
- Log.d(TAG, "On progress received: " + progress);
639
- try {
640
- JSONObject jsonProgress = SitumMapper.navigationProgressToJsonObject(progress, context);
641
- try {
642
- jsonProgress.put("type", "progress");
643
- } catch (JSONException e) {
644
- Log.e(TAG, "error inserting type in navigation progress");
645
- }
646
- eventEmitter.emit(EVENT_NAVIGATION_UPDATE, convertJsonToMap(jsonProgress));
647
-
648
- } catch (Exception e) {
649
- Log.d(TAG, "On Error parsing progress: " + progress);
650
- eventEmitter.emit(EVENT_NAVIGATION_ERROR, e.getMessage());
651
- }
652
- }
653
-
654
- ;
655
-
656
- public void onDestinationReached() {
657
- Log.d(TAG, "On destination reached: ");
658
- JSONObject jsonResult = new JSONObject();
659
- try {
660
- jsonResult.put("type", "destinationReached");
661
- jsonResult.put("message", "Destination reached");
662
- eventEmitter.emit(EVENT_NAVIGATION_UPDATE, convertJsonToMap(jsonResult));
663
- } catch (JSONException e) {
664
- Log.e(TAG, "error inserting type in destination reached");
665
- }
666
-
667
- }
668
-
669
- ;
670
-
671
- public void onUserOutsideRoute() {
672
- Log.d(TAG, "On user outside route: ");
673
- JSONObject jsonResult = new JSONObject();
674
- try {
675
- jsonResult.put("type", "userOutsideRoute");
676
- jsonResult.put("message", "User outside route");
677
- eventEmitter.emit(EVENT_NAVIGATION_UPDATE, convertJsonToMap(jsonResult));
678
-
679
- } catch (JSONException e) {
680
- Log.e(TAG, "error inserting type in user outside route");
681
- }
682
-
683
- }
684
- };
685
-
686
- getNavigationManagerInstance().requestNavigationUpdates(navigationRequest, navigationListener);
639
+ getNavigationManagerInstance().requestNavigationUpdates(navigationRequest);
687
640
 
688
641
  }
689
642
 
@@ -707,6 +660,18 @@ public class PluginHelper {
707
660
  }
708
661
  }
709
662
 
663
+ public void updateNavigationState(ReadableMap payload) {
664
+ try {
665
+ Map<String, Object> externalNavigationMap = convertReadableMapToMap(payload);
666
+
667
+ getNavigationManagerInstance().updateNavigationState(
668
+ ExternalNavigation.fromMap(externalNavigationMap)
669
+ );
670
+ } catch (Exception e) {
671
+ e.printStackTrace();
672
+ }
673
+ }
674
+
710
675
  public void removeNavigationUpdates(Callback callback) {
711
676
  Log.i(TAG, "Remove navigation updates");
712
677
  boolean success = getNavigationManagerInstance().removeUpdates();
@@ -991,4 +956,61 @@ public class PluginHelper {
991
956
  };
992
957
  SitumSdk.locationManager().setGeofenceListener(geofenceListener);
993
958
  }
959
+
960
+ public void onSdkInitialized(
961
+ DeviceEventManagerModule.RCTDeviceEventEmitter eventEmitter,
962
+ Context context
963
+ ) {
964
+ navigationListener = _buildNavigationListener(eventEmitter, context);
965
+ SitumSdk.navigationManager().addNavigationListener(navigationListener);
966
+ }
967
+
968
+ private NavigationListener _buildNavigationListener(
969
+ DeviceEventManagerModule.RCTDeviceEventEmitter eventEmitter,
970
+ Context context
971
+ ) {
972
+ return new NavigationListener() {
973
+ public void onStart(Route route) {
974
+ Log.d(TAG, "NavigationListener.onStart() called with: "+ route);
975
+ try {
976
+ eventEmitter.emit(EVENT_NAVIGATION_START, convertMapToReadableMap(route.toMap()));
977
+ } catch (Exception e) {
978
+ Log.e(TAG, "error building onStart() hybrid message with native Route: "+ route);
979
+ eventEmitter.emit(EVENT_NAVIGATION_ERROR, e.getMessage());
980
+ }
981
+ }
982
+
983
+ public void onProgress(NavigationProgress progress) {
984
+ Log.d(TAG, "NavigationListener.onProgress() called with: " + progress);
985
+ try {
986
+ eventEmitter.emit(EVENT_NAVIGATION_PROGRESS, convertMapToReadableMap(progress.toMap()));
987
+ } catch (Exception e) {
988
+ Log.e(TAG, "error building onProgress() hybrid message with native NavigationProgress: " + progress);
989
+ eventEmitter.emit(EVENT_NAVIGATION_ERROR, e.getMessage());
990
+ }
991
+ }
992
+
993
+ public void onDestinationReached(Route route) {
994
+ Log.d(TAG, "NavigationListener.onDestinationReached() called with: " + route);
995
+ try {
996
+ eventEmitter.emit(EVENT_NAVIGATION_DESTINATION_REACHED, convertMapToReadableMap(route.toMap()));
997
+ eventEmitter.emit(EVENT_NAVIGATION_FINISHED, convertMapToReadableMap(route.toMap()));
998
+ } catch (Exception e) {
999
+ Log.e(TAG, "error building onDestinationReached() hybrid message with native Route: "+ route);
1000
+ eventEmitter.emit(EVENT_NAVIGATION_ERROR, e.getMessage());
1001
+ }
1002
+ }
1003
+
1004
+ public void onUserOutsideRoute() {
1005
+ Log.d(TAG, "NavigationListener.onUserOutsideRoute() called.");
1006
+ eventEmitter.emit(EVENT_NAVIGATION_OUTSIDE_ROUTE, Arguments.createMap());
1007
+ }
1008
+
1009
+ public void onCancellation() {
1010
+ Log.d(TAG, "NavigationListener.onCancellation() called.");
1011
+ eventEmitter.emit(EVENT_NAVIGATION_CANCELLATION, Arguments.createMap());
1012
+ eventEmitter.emit(EVENT_NAVIGATION_FINISHED, Arguments.createMap());
1013
+ }
1014
+ };
1015
+ }
994
1016
  }
@@ -1120,17 +1120,17 @@ class SitumMapper {
1120
1120
  if (joOptions != null) {
1121
1121
 
1122
1122
  if (joOptions.has(SitumMapper.INCLUDED_TAGS) && joOptions.get(SitumMapper.INCLUDED_TAGS) != null) {
1123
- includedTags = new ArrayList<String>();
1124
- JSONArray jsonArray = joOptions.getJSONArray(SitumMapper.INCLUDED_TAGS);
1125
- for (int i=0;i<jsonArray.length();i++) {
1123
+ includedTags = new ArrayList<String>();
1124
+ JSONArray jsonArray = joOptions.getJSONArray(SitumMapper.INCLUDED_TAGS);
1125
+ for (int i=0;i<jsonArray.length();i++) {
1126
1126
  includedTags.add(jsonArray.get(i).toString());
1127
1127
  }
1128
1128
  }
1129
1129
 
1130
1130
  if (joOptions.has(SitumMapper.EXCLUDED_TAGS) && joOptions.get(SitumMapper.EXCLUDED_TAGS) != null) {
1131
- excludedTags = new ArrayList<String>();
1132
- JSONArray jsonArray = joOptions.getJSONArray(SitumMapper.EXCLUDED_TAGS);
1133
- for (int i=0;i<jsonArray.length();i++) {
1131
+ excludedTags = new ArrayList<String>();
1132
+ JSONArray jsonArray = joOptions.getJSONArray(SitumMapper.EXCLUDED_TAGS);
1133
+ for (int i=0;i<jsonArray.length();i++) {
1134
1134
  excludedTags.add(jsonArray.get(i).toString());
1135
1135
  }
1136
1136
  }
@@ -10,8 +10,13 @@ public interface SitumPlugin {
10
10
  String EVENT_LOCATION_STATUS_CHANGED = "statusChanged";
11
11
  String EVENT_LOCATION_STOPPED = "locationStopped";
12
12
 
13
- String EVENT_NAVIGATION_UPDATE = "navigationUpdated";
14
- String EVENT_NAVIGATION_ERROR = "navigationError";
13
+ String EVENT_NAVIGATION_START = "onNavigationStart";
14
+ String EVENT_NAVIGATION_PROGRESS = "onNavigationProgress";
15
+ String EVENT_NAVIGATION_FINISHED = "onNavigationFinished";
16
+ String EVENT_NAVIGATION_DESTINATION_REACHED = "onNavigationDestinationReached";
17
+ String EVENT_NAVIGATION_OUTSIDE_ROUTE = "onUserOutsideRoute";
18
+ String EVENT_NAVIGATION_CANCELLATION = "onNavigationCancellation";
19
+ String EVENT_NAVIGATION_ERROR = "onNavigationError";
15
20
 
16
21
  String EVENT_REALTIME_ERROR = "realtimeError";
17
22
  String EVENT_REALTIME_UPDATE = "realtimeUpdated";
@@ -65,6 +70,8 @@ public interface SitumPlugin {
65
70
 
66
71
  void updateNavigationWithLocation(ReadableMap map, Callback success, Callback error);
67
72
 
73
+ void updateNavigationState(ReadableMap map);
74
+
68
75
  void removeNavigationUpdates(Callback callback);
69
76
 
70
77
  void requestRealTimeUpdates(ReadableMap map);
@@ -53,6 +53,10 @@ public class SitumPluginImpl extends ReactContextBaseJavaModule implements Situm
53
53
  @ReactMethod
54
54
  public void initSitumSDK() {
55
55
  SitumSdk.init(reactContext);
56
+ getPluginInstance().onSdkInitialized(
57
+ getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class),
58
+ getReactApplicationContext()
59
+ );
56
60
  }
57
61
 
58
62
  // Required for rn built in EventEmitter Calls.
@@ -240,6 +244,12 @@ public class SitumPluginImpl extends ReactContextBaseJavaModule implements Situm
240
244
  getPluginInstance().updateNavigationWithLocation(map, success, error);
241
245
  }
242
246
 
247
+ @Override
248
+ @ReactMethod
249
+ public void updateNavigationState(ReadableMap map) {
250
+ getPluginInstance().updateNavigationState(map);
251
+ }
252
+
243
253
  @Override
244
254
  @ReactMethod
245
255
  public void removeNavigationUpdates(Callback callback) {
@@ -0,0 +1,284 @@
1
+ package com.situm.plugin.utils;
2
+
3
+ import com.facebook.react.bridge.Arguments;
4
+ import com.facebook.react.bridge.ReadableArray;
5
+ import com.facebook.react.bridge.ReadableMap;
6
+ import com.facebook.react.bridge.ReadableMapKeySetIterator;
7
+ import com.facebook.react.bridge.WritableArray;
8
+ import com.facebook.react.bridge.WritableMap;
9
+ import com.facebook.react.bridge.WritableNativeArray;
10
+ import com.facebook.react.bridge.WritableNativeMap;
11
+
12
+ import org.json.JSONArray;
13
+ import org.json.JSONException;
14
+ import org.json.JSONObject;
15
+
16
+ import java.util.Iterator;
17
+ import java.util.Map;
18
+ import java.util.HashMap;
19
+ import java.util.List;
20
+ import java.util.ArrayList;
21
+
22
+ public class ReactNativeUtils {
23
+ public static WritableMap convertJsonToMap(JSONObject jsonObject) throws JSONException {
24
+ WritableMap map = new WritableNativeMap();
25
+
26
+ Iterator<String> iterator = jsonObject.keys();
27
+ while (iterator.hasNext()) {
28
+ String key = iterator.next();
29
+ Object value = jsonObject.get(key);
30
+ if (value instanceof JSONObject) {
31
+ map.putMap(key, convertJsonToMap((JSONObject) value));
32
+ } else if (value instanceof JSONArray) {
33
+ map.putArray(key, convertJsonToArray((JSONArray) value));
34
+ } else if (value instanceof Boolean) {
35
+ map.putBoolean(key, (Boolean) value);
36
+ } else if (value instanceof Integer) {
37
+ map.putInt(key, (Integer) value);
38
+ } else if (value instanceof Double) {
39
+ map.putDouble(key, (Double) value);
40
+ } else if (value instanceof String) {
41
+ map.putString(key, (String) value);
42
+ } else {
43
+ map.putString(key, value.toString());
44
+ }
45
+ }
46
+ return map;
47
+ }
48
+
49
+ public static WritableArray convertJsonToArray(JSONArray jsonArray) throws JSONException {
50
+ WritableArray array = new WritableNativeArray();
51
+
52
+ for (int i = 0; i < jsonArray.length(); i++) {
53
+ Object value = jsonArray.get(i);
54
+ if (value instanceof JSONObject) {
55
+ array.pushMap(convertJsonToMap((JSONObject) value));
56
+ } else if (value instanceof JSONArray) {
57
+ array.pushArray(convertJsonToArray((JSONArray) value));
58
+ } else if (value instanceof Boolean) {
59
+ array.pushBoolean((Boolean) value);
60
+ } else if (value instanceof Integer) {
61
+ array.pushInt((Integer) value);
62
+ } else if (value instanceof Double) {
63
+ array.pushDouble((Double) value);
64
+ } else if (value instanceof String) {
65
+ array.pushString((String) value);
66
+ } else {
67
+ array.pushString(value.toString());
68
+ }
69
+ }
70
+ return array;
71
+ }
72
+
73
+ public static JSONObject convertMapToJson(ReadableMap readableMap) throws JSONException {
74
+ JSONObject object = new JSONObject();
75
+ ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
76
+ while (iterator.hasNextKey()) {
77
+ String key = iterator.nextKey();
78
+ switch (readableMap.getType(key)) {
79
+ case Null:
80
+ object.put(key, JSONObject.NULL);
81
+ break;
82
+ case Boolean:
83
+ object.put(key, readableMap.getBoolean(key));
84
+ break;
85
+ case Number:
86
+ // Check if the number is an integer or a double
87
+ double tmpValue = readableMap.getDouble(key);
88
+ if (tmpValue == Math.rint(tmpValue)) {
89
+ object.put(key, readableMap.getInt(key));
90
+ } else {
91
+ object.put(key, tmpValue);
92
+ }
93
+ object.put(key, readableMap.getDouble(key));
94
+ break;
95
+ case String:
96
+ object.put(key, readableMap.getString(key));
97
+ break;
98
+ case Map:
99
+ object.put(key, convertMapToJson(readableMap.getMap(key)));
100
+ break;
101
+ case Array:
102
+ object.put(key, convertArrayToJson(readableMap.getArray(key)));
103
+ break;
104
+ }
105
+ }
106
+ return object;
107
+ }
108
+
109
+ public static JSONArray convertArrayToJson(ReadableArray readableArray) throws JSONException {
110
+ JSONArray array = new JSONArray();
111
+ for (int i = 0; i < readableArray.size(); i++) {
112
+ switch (readableArray.getType(i)) {
113
+ case Null:
114
+ break;
115
+ case Boolean:
116
+ array.put(readableArray.getBoolean(i));
117
+ break;
118
+ case Number:
119
+ array.put(readableArray.getDouble(i));
120
+ break;
121
+ case String:
122
+ array.put(readableArray.getString(i));
123
+ break;
124
+ case Map:
125
+ array.put(convertMapToJson(readableArray.getMap(i)));
126
+ break;
127
+ case Array:
128
+ array.put(convertArrayToJson(readableArray.getArray(i)));
129
+ break;
130
+ }
131
+ }
132
+ return array;
133
+ }
134
+
135
+ public static Map<String, Object> convertReadableMapToMap(ReadableMap readableMap) {
136
+ Map<String, Object> map = new HashMap<>();
137
+
138
+ ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
139
+ while (iterator.hasNextKey()) {
140
+ String key = iterator.nextKey();
141
+
142
+ switch (readableMap.getType(key)) {
143
+ case Null:
144
+ map.put(key, null);
145
+ break;
146
+ case Boolean:
147
+ map.put(key, readableMap.getBoolean(key));
148
+ break;
149
+ case Number:
150
+ // Check if the number is an integer or a double
151
+ double tmpValue = readableMap.getDouble(key);
152
+ if (tmpValue == Math.rint(tmpValue)) {
153
+ map.put(key, readableMap.getInt(key));
154
+ } else {
155
+ map.put(key, tmpValue);
156
+ }
157
+ break;
158
+ case String:
159
+ map.put(key, readableMap.getString(key));
160
+ break;
161
+ case Map:
162
+ map.put(key, convertReadableMapToMap(readableMap.getMap(key)));
163
+ break;
164
+ case Array:
165
+ map.put(key, convertReadableArrayToList(readableMap.getArray(key)));
166
+ break;
167
+ }
168
+ }
169
+
170
+ return map;
171
+ }
172
+
173
+ private static List<Object> convertReadableArrayToList(ReadableArray readableArray) {
174
+ List<Object> list = new ArrayList<>();
175
+
176
+ for (int i = 0; i < readableArray.size(); i++) {
177
+
178
+ switch (readableArray.getType(i)) {
179
+ case Null:
180
+ list.add(null);
181
+ break;
182
+ case Boolean:
183
+ list.add(readableArray.getBoolean(i));
184
+ break;
185
+ case Number:
186
+ // Check if the number is an integer or a double
187
+ double tmpValue = readableArray.getDouble(i);
188
+ if (tmpValue == Math.rint(tmpValue)) {
189
+ list.add(readableArray.getInt(i));
190
+ } else {
191
+ list.add(tmpValue);
192
+ }
193
+ break;
194
+ case String:
195
+ list.add(readableArray.getString(i));
196
+ break;
197
+ case Map:
198
+ list.add(convertReadableMapToMap(readableArray.getMap(i)));
199
+ break;
200
+ case Array:
201
+ list.add(convertReadableArrayToList(readableArray.getArray(i)));
202
+ break;
203
+ }
204
+ }
205
+
206
+ return list;
207
+ }
208
+
209
+ public static ReadableMap convertMapToReadableMap(Map<String, Object> map) {
210
+ WritableMap writableMap = Arguments.createMap();
211
+
212
+ for (Map.Entry<String, Object> entry : map.entrySet()) {
213
+ String key = entry.getKey();
214
+ Object value = entry.getValue();
215
+
216
+ if (value == null) {
217
+ writableMap.putNull(key);
218
+ } else if (value instanceof String) {
219
+ writableMap.putString(key, (String) value);
220
+ } else if (value instanceof Integer) {
221
+ writableMap.putInt(key, (Integer) value);
222
+ } else if (value instanceof Double) {
223
+ writableMap.putDouble(key, (Double) value);
224
+ } else if (value instanceof Float) {
225
+ writableMap.putDouble(key, ((Float) value).doubleValue());
226
+ } else if (value instanceof Long) {
227
+ Long longValue = (Long) value;
228
+ if (longValue <= Integer.MAX_VALUE && longValue >= Integer.MIN_VALUE) {
229
+ writableMap.putInt(key, longValue.intValue());
230
+ } else {
231
+ writableMap.putDouble(key, longValue.doubleValue());
232
+ }
233
+ } else if (value instanceof Boolean) {
234
+ writableMap.putBoolean(key, (Boolean) value);
235
+ } else if (value instanceof Map) {
236
+ writableMap.putMap(key, convertMapToReadableMap((Map<String, Object>) value));
237
+ } else if (value instanceof List) {
238
+ writableMap.putArray(key, convertListToWritableArray((List<Object>) value));
239
+ } else {
240
+ // Handle other types if necessary
241
+ throw new IllegalArgumentException("Unsupported value type for key: " + key);
242
+ }
243
+ }
244
+
245
+ return writableMap;
246
+ }
247
+
248
+ private static WritableArray convertListToWritableArray(List<Object> list) {
249
+ WritableArray writableArray = Arguments.createArray();
250
+
251
+ for (Object value : list) {
252
+ if (value == null) {
253
+ writableArray.pushNull();
254
+ } else if (value instanceof String) {
255
+ writableArray.pushString((String) value);
256
+ } else if (value instanceof Integer) {
257
+ writableArray.pushInt((Integer) value);
258
+ } else if (value instanceof Double) {
259
+ writableArray.pushDouble((Double) value);
260
+ } else if (value instanceof Float) {
261
+ writableArray.pushDouble(((Float) value).doubleValue());
262
+ } else if (value instanceof Long) {
263
+ Long longValue = (Long) value;
264
+ if (longValue <= Integer.MAX_VALUE && longValue >= Integer.MIN_VALUE) {
265
+ writableArray.pushInt(longValue.intValue());
266
+ } else {
267
+ writableArray.pushDouble(longValue.doubleValue());
268
+ }
269
+ } else if (value instanceof Boolean) {
270
+ writableArray.pushBoolean((Boolean) value);
271
+ } else if (value instanceof Map) {
272
+ writableArray.pushMap(convertMapToReadableMap((Map<String, Object>) value));
273
+ } else if (value instanceof List) {
274
+ writableArray.pushArray(convertListToWritableArray((List<Object>) value));
275
+ } else {
276
+ // Handle other types if necessary
277
+ throw new IllegalArgumentException("Unsupported value type in list");
278
+ }
279
+ }
280
+
281
+ return writableArray;
282
+ }
283
+
284
+ }
@@ -999,6 +999,10 @@ static SitumLocationWrapper *singletonSitumLocationWrapperObj;
999
999
  [jo setObject:stepsJsonArray.lastObject forKey:@"lastStep"];
1000
1000
  [jo setObject:pointsJsonArray forKey:@"nodes"];
1001
1001
 
1002
+ if (route.poiTo == nil) return jo;
1003
+
1004
+ [jo setObject:[route.poiTo toDictionary] forKey:@"poiTo"];
1005
+
1002
1006
  return jo.copy;
1003
1007
  }
1004
1008