react-native-steerpath-smart-map 1.23.2 → 1.24.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/CHANGELOG.md CHANGED
@@ -15,6 +15,10 @@ This package is built on top of Steerpath's Smart SDK, and most of releases are
15
15
  - [iOS](https://s3-eu-west-1.amazonaws.com/steerpath/ios/releases/smart-sdk-changelog/index.html)
16
16
  - [Web](https://s3-eu-west-1.amazonaws.com/steerpath-web-sdk/documentation/smart/latest/index.html)
17
17
 
18
+ ## [1.24.0] - 2023-06-29
19
+
20
+ - Added SmartLocationManager to listen for user location updates
21
+
18
22
  ## [1.23.2] - 2023-06-26
19
23
 
20
24
  - Bump iOS Smart SDK version to 1.17.2
@@ -24,4 +24,6 @@ public class RNEventKeys {
24
24
  public static final String NAVIGATION_PREVIEW_APPEARED = "onNavigationPreviewAppeared";
25
25
  public static final String NAVIGATION_DESTINATION_REACHED = "onNavigationDestinationReached";
26
26
  public static final String ON_BACK_PRESSED = "onBackPressed";
27
+
28
+ public static final String ON_LOCATION_CHANGED = "locationChanged";
27
29
  }
@@ -0,0 +1,77 @@
1
+ package com.steerpath.rnsmartmap;
2
+
3
+ import static com.steerpath.rnsmartmap.RNEventKeys.ON_LOCATION_CHANGED;
4
+
5
+ import android.util.Log;
6
+
7
+ import androidx.annotation.NonNull;
8
+
9
+ import com.facebook.react.bridge.ReactApplicationContext;
10
+ import com.facebook.react.bridge.ReactContext;
11
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
12
+ import com.facebook.react.bridge.ReactMethod;
13
+ import com.facebook.react.bridge.WritableMap;
14
+ import com.facebook.react.bridge.WritableNativeMap;
15
+ import com.facebook.react.modules.core.DeviceEventManagerModule;
16
+ import com.steerpath.smart.SmartLocationManager;
17
+ import com.steerpath.smart.listeners.SmartLocationListener;
18
+
19
+ import javax.annotation.Nonnull;
20
+ import javax.annotation.Nullable;
21
+
22
+ public class RNSmartLocationManager extends ReactContextBaseJavaModule implements SmartLocationListener{
23
+
24
+ private final ReactApplicationContext appContext;
25
+ private int listenerCount = 0;
26
+
27
+ public RNSmartLocationManager(@Nonnull ReactApplicationContext reactContext) {
28
+ super(reactContext);
29
+ this.appContext = reactContext;
30
+ }
31
+
32
+ @NonNull
33
+ @Override
34
+ public String getName() {
35
+ return "RNSmartLocationManager";
36
+ }
37
+
38
+ @ReactMethod
39
+ public void addListener(String eventName) {
40
+ Log.d("LocationManager", "add listener");
41
+ if (listenerCount == 0) {
42
+ SmartLocationManager.addLocationListener(this);
43
+ }
44
+ listenerCount++;
45
+ }
46
+
47
+ @ReactMethod
48
+ public void removeListeners(Integer count) {
49
+ Log.d("LocationManager", "remove listener");
50
+ listenerCount -= count;
51
+ if (listenerCount == 0) {
52
+ SmartLocationManager.removeLocationListener(this);
53
+ }
54
+ }
55
+
56
+ @Override
57
+ public void onLocationChanged(double latitude, double longitude, @Nullable String buildingRef, int floorIndex) {
58
+ WritableNativeMap map = new WritableNativeMap();
59
+ map.putDouble("latitude", latitude);
60
+ map.putDouble("longitude", longitude);
61
+ if (buildingRef == null) {
62
+ map.putNull("buildingRef");
63
+ } else {
64
+ map.putString("buildingRef", buildingRef);
65
+ }
66
+ map.putInt("floorIndex", floorIndex);
67
+ sendEvent(appContext, ON_LOCATION_CHANGED, map);
68
+ }
69
+
70
+ private void sendEvent(ReactContext reactContext,
71
+ String eventName,
72
+ @Nullable WritableMap params) {
73
+ reactContext
74
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
75
+ .emit(eventName, params);
76
+ }
77
+ }
@@ -32,6 +32,7 @@ public class RNSmartMapPackage implements ReactPackage {
32
32
  modules.add(new RNSmartMapManager(reactContext));
33
33
  modules.add(new RNSmartGeofenceManager(reactContext));
34
34
  modules.add(new RNSmartMapModule(reactContext));
35
+ modules.add(new RNSmartLocationManager(reactContext));
35
36
  return modules;
36
37
  }
37
38
  }
package/dist/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export * from './SmartGeofenceManager';
2
2
  export * from './SmartMapManager';
3
3
  export * from './SmartMapView';
4
4
  export * from './SmartMapViewProps';
5
+ export * from './SmartLocationManager';
package/dist/index.js CHANGED
@@ -2,3 +2,4 @@ export * from './SmartGeofenceManager';
2
2
  export * from './SmartMapManager';
3
3
  export * from './SmartMapView';
4
4
  export * from './SmartMapViewProps';
5
+ export * from './SmartLocationManager';
@@ -0,0 +1,22 @@
1
+ //
2
+ // RNSmartLocationManager.h
3
+ // SteerpathSmartMapSdk
4
+ //
5
+ // Created by Roope Vilo on 24.5.2023.
6
+ // Copyright © 2023 Facebook. All rights reserved.
7
+ //
8
+
9
+ #ifndef RNSmartLocationManager_h
10
+ #define RNSmartLocationManager_h
11
+
12
+ #import <React/RCTBridgeModule.h>
13
+ #import <React/RCTEventEmitter.h>
14
+
15
+ @import SteerpathSmartSDK;
16
+
17
+ @interface RNSmartLocationManager : RCTEventEmitter<RCTBridgeModule, SPSmartLocationManagerDelegate>
18
+
19
+ @end
20
+
21
+
22
+ #endif /* RNSmartLocationManager_h */
@@ -0,0 +1,39 @@
1
+ //
2
+ // RNSmartLocationManager.m
3
+ // SteerpathSmartMapSdk
4
+ //
5
+ // Created by Roope Vilo on 24.5.2023.
6
+ // Copyright © 2023 Facebook. All rights reserved.
7
+ //
8
+
9
+ #import "RNSmartLocationManager.h"
10
+
11
+ @implementation RNSmartLocationManager {
12
+ bool hasListeners;
13
+ }
14
+
15
+ RCT_EXPORT_MODULE(RNSmartLocationManager);
16
+
17
+ - (NSArray<NSString *> *)supportedEvents
18
+ {
19
+ return @[@"locationChanged"];
20
+ }
21
+
22
+ // Start listening location updates. Starts positioning unless map has started it already.
23
+ -(void)startObserving {
24
+ hasListeners = YES;
25
+ [[SPSmartLocationManager sharedInstance] addDelegate:self];
26
+ }
27
+
28
+ -(void)stopObserving {
29
+ hasListeners = NO;
30
+ [[SPSmartLocationManager sharedInstance] removeDelegate:self];
31
+ }
32
+
33
+ -(void)spSmartLocationManager:(SPSmartLocationManager *)manager onLocationChanged:(double)latitude longitude:(double)longitude buildingRef:(nullable NSString *)buildingRef floorIndex:(NSInteger)floorIndex {
34
+ if (hasListeners) {
35
+ [self sendEventWithName:@"locationChanged" body:@{@"latitude": [NSNumber numberWithDouble:latitude], @"longitude": [NSNumber numberWithDouble:longitude], @"buildingRef": buildingRef ?: [NSNull null], @"floorIndex": [NSNumber numberWithInteger:floorIndex]}];
36
+ }
37
+ }
38
+
39
+ @end
@@ -7,9 +7,9 @@
7
7
  objects = {
8
8
 
9
9
  /* Begin PBXBuildFile section */
10
+ 5171A8442A1E2F1C0027411B /* RNSmartLocationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 5171A8432A1E2F1C0027411B /* RNSmartLocationManager.m */; };
10
11
  54311E118E4B5D3209B3CD9A /* libPods-SteerpathSmartMapSdk.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B9B946A14D696A939BC22047 /* libPods-SteerpathSmartMapSdk.a */; };
11
12
  B66B217922FAFF6B00E05A0B /* RNSmartMapView.m in Sources */ = {isa = PBXBuildFile; fileRef = B66B217822FAFF6B00E05A0B /* RNSmartMapView.m */; };
12
- B66B217C22FB07F400E05A0B /* RNSmartMapEventManager.m in Sources */ = {isa = PBXBuildFile; fileRef = B66B217B22FB07F400E05A0B /* RNSmartMapEventManager.m */; };
13
13
  B66F820D22F4358C00B6516F /* RNSmartMapManager.m in Sources */ = {isa = PBXBuildFile; fileRef = B66F820322F4358C00B6516F /* RNSmartMapManager.m */; };
14
14
  B66F820E22F4358C00B6516F /* RNSmartMapViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = B66F820622F4358C00B6516F /* RNSmartMapViewManager.m */; };
15
15
  B66F820F22F4358C00B6516F /* RCTConvert+SmartMapView.m in Sources */ = {isa = PBXBuildFile; fileRef = B66F820822F4358C00B6516F /* RCTConvert+SmartMapView.m */; };
@@ -31,11 +31,11 @@
31
31
  /* Begin PBXFileReference section */
32
32
  134814201AA4EA6300B7C361 /* libSteerpathSmartMapSdk.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libSteerpathSmartMapSdk.a; sourceTree = BUILT_PRODUCTS_DIR; };
33
33
  34CDFE83ADF1872D87ECE4E0 /* Pods-SteerpathSmartMapSdk.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SteerpathSmartMapSdk.release.xcconfig"; path = "Target Support Files/Pods-SteerpathSmartMapSdk/Pods-SteerpathSmartMapSdk.release.xcconfig"; sourceTree = "<group>"; };
34
+ 5171A8432A1E2F1C0027411B /* RNSmartLocationManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNSmartLocationManager.m; sourceTree = "<group>"; };
35
+ 5171A8452A1E2F440027411B /* RNSmartLocationManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNSmartLocationManager.h; sourceTree = "<group>"; };
34
36
  9B3178C37E533A845BD4D634 /* Pods-SteerpathSmartMapSdk.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SteerpathSmartMapSdk.debug.xcconfig"; path = "Target Support Files/Pods-SteerpathSmartMapSdk/Pods-SteerpathSmartMapSdk.debug.xcconfig"; sourceTree = "<group>"; };
35
37
  B66B217722FAFF6B00E05A0B /* RNSmartMapView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNSmartMapView.h; sourceTree = "<group>"; };
36
38
  B66B217822FAFF6B00E05A0B /* RNSmartMapView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNSmartMapView.m; sourceTree = "<group>"; };
37
- B66B217A22FB07F400E05A0B /* RNSmartMapEventManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNSmartMapEventManager.h; sourceTree = "<group>"; };
38
- B66B217B22FB07F400E05A0B /* RNSmartMapEventManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNSmartMapEventManager.m; sourceTree = "<group>"; };
39
39
  B66F820322F4358C00B6516F /* RNSmartMapManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSmartMapManager.m; sourceTree = "<group>"; };
40
40
  B66F820422F4358C00B6516F /* RCTConvert+SmartMapView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RCTConvert+SmartMapView.h"; sourceTree = "<group>"; };
41
41
  B66F820522F4358C00B6516F /* RNSmartMapViewManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSmartMapViewManager.h; sourceTree = "<group>"; };
@@ -70,8 +70,8 @@
70
70
  58B511D21A9E6C8500147676 = {
71
71
  isa = PBXGroup;
72
72
  children = (
73
- B66B217A22FB07F400E05A0B /* RNSmartMapEventManager.h */,
74
- B66B217B22FB07F400E05A0B /* RNSmartMapEventManager.m */,
73
+ 5171A8452A1E2F440027411B /* RNSmartLocationManager.h */,
74
+ 5171A8432A1E2F1C0027411B /* RNSmartLocationManager.m */,
75
75
  B66B217722FAFF6B00E05A0B /* RNSmartMapView.h */,
76
76
  B66B217822FAFF6B00E05A0B /* RNSmartMapView.m */,
77
77
  B66F820422F4358C00B6516F /* RCTConvert+SmartMapView.h */,
@@ -193,7 +193,7 @@
193
193
  B66F820D22F4358C00B6516F /* RNSmartMapManager.m in Sources */,
194
194
  B66F821022F4358C00B6516F /* RNSmartGeofenceManager.m in Sources */,
195
195
  B66B217922FAFF6B00E05A0B /* RNSmartMapView.m in Sources */,
196
- B66B217C22FB07F400E05A0B /* RNSmartMapEventManager.m in Sources */,
196
+ 5171A8442A1E2F1C0027411B /* RNSmartLocationManager.m in Sources */,
197
197
  );
198
198
  runOnlyForDeploymentPostprocessing = 0;
199
199
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-steerpath-smart-map",
3
3
  "title": "React Native Steerpath Smart Map",
4
- "version": "1.23.2",
4
+ "version": "1.24.0",
5
5
  "description": "Steerpath SmartMapView for React Native",
6
6
  "main": "dist/index.js",
7
7
  "scripts": {
@@ -0,0 +1,34 @@
1
+ import { NativeModules, NativeEventEmitter, EmitterSubscription } from "react-native";
2
+
3
+ const RNSmartLocationManager = NativeModules.RNSmartLocationManager;
4
+
5
+ const smartLocationManagerEmitter = new NativeEventEmitter(
6
+ RNSmartLocationManager
7
+ );
8
+
9
+ function createSmartLocationManager() {
10
+ let eventListenerRegistered = false;
11
+ let eventListener: EmitterSubscription;
12
+
13
+ return {
14
+ addLocationChangedListener(
15
+ listener: (
16
+ data: { latitude: number, longitude: number, buildingRef: string | null, floorIndex: number }
17
+ ) => void
18
+ ) {
19
+ if (!eventListenerRegistered) {
20
+ eventListenerRegistered = true;
21
+ eventListener = smartLocationManagerEmitter.addListener('locationChanged', (payload) => {
22
+ listener(payload);
23
+ })
24
+ }
25
+ },
26
+ removeLocationChangedListener() {
27
+ eventListenerRegistered = false;
28
+ eventListener.remove();
29
+ }
30
+ };
31
+ }
32
+
33
+ export const SmartLocationManager = createSmartLocationManager();
34
+
@@ -0,0 +1,4 @@
1
+ export const SmartLocationManager = {
2
+ addListener(){},
3
+ removeListener(){},
4
+ }
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './SmartGeofenceManager'
2
2
  export * from './SmartMapManager'
3
3
  export * from './SmartMapView'
4
- export * from './SmartMapViewProps'
4
+ export * from './SmartMapViewProps'
5
+ export * from './SmartLocationManager'