react-native-pointr 0.0.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.
@@ -0,0 +1,466 @@
1
+ package com.pointr
2
+
3
+ import android.annotation.SuppressLint
4
+ import android.content.ComponentName
5
+ import android.content.Intent
6
+ import android.os.Parcel
7
+ import android.os.Parcelable
8
+ import android.util.Log
9
+ import com.facebook.react.bridge.Arguments
10
+ import com.facebook.react.bridge.Callback
11
+ import com.facebook.react.bridge.ReactApplicationContext
12
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
13
+ import com.facebook.react.bridge.ReactMethod
14
+ import com.facebook.react.bridge.WritableMap
15
+ import com.facebook.react.modules.core.DeviceEventManagerModule
16
+ import com.pointrlabs.core.management.Pointr
17
+ import com.pointrlabs.core.management.PositionManager
18
+ import com.pointrlabs.core.management.interfaces.PointrListener
19
+ import com.pointrlabs.core.management.models.Building
20
+ import com.pointrlabs.core.management.models.Level
21
+ import com.pointrlabs.core.management.models.PTRParams
22
+ import com.pointrlabs.core.management.models.PointrEnvironment
23
+ import com.pointrlabs.core.management.models.Site
24
+ import com.pointrlabs.core.map.models.events_listeners.MapEventsListener
25
+ import com.pointrlabs.core.map.views.PTRMapFragment
26
+ import com.pointrlabs.core.nativecore.wrappers.Plog.LogLevel
27
+ import com.pointrlabs.core.nativecore.wrappers.Plog.v
28
+ import com.pointrlabs.core.positioning.model.CalculatedLocation
29
+ import com.pointrlabs.core.positioning.model.PositioningTypes
30
+ import org.json.JSONObject
31
+ import kotlin.reflect.KMutableProperty1
32
+
33
+ @SuppressLint("LogNotTimber")
34
+ class PointrModule(reactContext: ReactApplicationContext) :
35
+ ReactContextBaseJavaModule(reactContext) {
36
+
37
+ init {
38
+ setPointrListeners()
39
+ }
40
+
41
+ private var listenerCount = 0
42
+
43
+ override fun getName(): String {
44
+ return NAME
45
+ }
46
+
47
+ @ReactMethod
48
+ fun addListener(eventName: String) {
49
+ // TODO as per documentation, this should get invoked when addListener is called
50
+ // on the JS side, but it does not get invoked
51
+ if (listenerCount == 0) {
52
+ // Set up any upstream listeners or background tasks as necessary
53
+ start { args -> v("Pointr started and listeners added") }
54
+ }
55
+ listenerCount += 1
56
+ }
57
+
58
+ @ReactMethod
59
+ fun removeListeners(count: Int) {
60
+ listenerCount -= count
61
+ if (listenerCount == 0) {
62
+ // Remove upstream listeners, stop unnecessary background tasks
63
+ removePointrListeners()
64
+ }
65
+ }
66
+
67
+ @ReactMethod
68
+ fun initialize(
69
+ licenceKey: String,
70
+ baseUrl: String,
71
+ clientId: String,
72
+ env: String,
73
+ logLevel: Int
74
+ ) {
75
+ initialize(
76
+ reactApplicationContext,
77
+ clientId,
78
+ baseUrl,
79
+ licenceKey,
80
+ env,
81
+ logLevel
82
+ )
83
+ }
84
+
85
+ @ReactMethod
86
+ fun start(callback: Callback?) {
87
+ Pointr.getPointr()?.let {
88
+ if (it.state == Pointr.State.RUNNING) {
89
+ setPointrListeners()
90
+ callback?.invoke(it.state.name)
91
+ } else {
92
+ onPointrStartEnded { endState ->
93
+ callback?.invoke(endState)
94
+ }
95
+ Thread {
96
+ it.start()
97
+ }.start()
98
+ }
99
+ }
100
+ }
101
+
102
+ @ReactMethod
103
+ fun stop() {
104
+ Pointr.getPointr()?.stop()
105
+ }
106
+
107
+ @ReactMethod
108
+ fun getCurrentLocation(callback: Callback) {
109
+ val pointr = Pointr.getPointr() ?: return callback.invoke(null)
110
+ if (pointr.state != Pointr.State.RUNNING) return callback.invoke(null)
111
+ val calculatedLocation =
112
+ pointr.positionManager?.currentCalculatedLocation ?: return callback.invoke(null)
113
+ callback.invoke(applyParamsForCalculatedLocation(calculatedLocation))
114
+ }
115
+
116
+ @ReactMethod
117
+ fun showSite(siteExternalId: String, animationType: Int, callback: Callback) {
118
+ val activity = currentActivity ?: run {
119
+ callback.invoke("Could not get current activity")
120
+ return
121
+ }
122
+
123
+ val intent = Intent(activity, PointrMapWidgetActivity::class.java)
124
+ intent.putExtra(mapEventsListenerKey, CustomMapEventsListener(reactApplicationContext))
125
+ intent.action = PointrMapWidgetActivity.SHOW_SITE
126
+ intent.putExtra(PointrMapWidgetActivity.siteExternalIdentifierKey, siteExternalId)
127
+ intent.putExtra(PointrMapWidgetActivity.animationTypeKey, animationType)
128
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
129
+ PointrMapWidgetActivity.callback = callback
130
+ activity.startActivity(intent)
131
+ }
132
+
133
+ @ReactMethod
134
+ fun showBuilding(
135
+ siteExternalId: String,
136
+ buildingExternalId: String,
137
+ animationType: Int,
138
+ callback: Callback
139
+ ) {
140
+ val activityContext =
141
+ currentActivity ?: return callback.invoke("Could not get current activity")
142
+ val intent = Intent(activityContext, PointrMapWidgetActivity::class.java)
143
+ intent.putExtra(mapEventsListenerKey, CustomMapEventsListener(reactApplicationContext))
144
+ intent.action = PointrMapWidgetActivity.SHOW_BUILDING
145
+ intent.putExtra(PointrMapWidgetActivity.siteExternalIdentifierKey, siteExternalId)
146
+ intent.putExtra(PointrMapWidgetActivity.buildingExternalIdentifierKey, buildingExternalId)
147
+ intent.putExtra(PointrMapWidgetActivity.animationTypeKey, animationType)
148
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
149
+ PointrMapWidgetActivity.callback = callback
150
+ activityContext.startActivity(intent)
151
+ }
152
+
153
+ @ReactMethod
154
+ fun showLevel(
155
+ siteExternalId: String,
156
+ buildingExternalId: String,
157
+ levelIndex: Int,
158
+ animationType: Int,
159
+ callback: Callback
160
+ ) {
161
+ val activityContext =
162
+ currentActivity ?: return callback.invoke("Could not get current activity")
163
+ val intent = Intent(activityContext, PointrMapWidgetActivity::class.java)
164
+ intent.putExtra(mapEventsListenerKey, CustomMapEventsListener(reactApplicationContext))
165
+ intent.action = PointrMapWidgetActivity.SHOW_LEVEL
166
+ intent.putExtra(PointrMapWidgetActivity.siteExternalIdentifierKey, siteExternalId)
167
+ intent.putExtra(PointrMapWidgetActivity.buildingExternalIdentifierKey, buildingExternalId)
168
+ intent.putExtra(PointrMapWidgetActivity.levelIndexKey, levelIndex)
169
+ intent.putExtra(PointrMapWidgetActivity.animationTypeKey, animationType)
170
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
171
+ PointrMapWidgetActivity.callback = callback
172
+ activityContext.startActivity(intent)
173
+ }
174
+
175
+ @ReactMethod
176
+ fun showPoiDetails(
177
+ siteExternalId: String,
178
+ poiExternalId: String,
179
+ animationType: Int,
180
+ callback: Callback
181
+ ) {
182
+ val activityContext =
183
+ currentActivity ?: return callback.invoke("Could not get current activity")
184
+ val intent = Intent(activityContext, PointrMapWidgetActivity::class.java)
185
+ intent.putExtra(mapEventsListenerKey, CustomMapEventsListener(reactApplicationContext))
186
+ intent.action = PointrMapWidgetActivity.SHOW_POI_DETAILS
187
+ intent.putExtra(PointrMapWidgetActivity.siteExternalIdentifierKey, siteExternalId)
188
+ intent.putExtra(PointrMapWidgetActivity.poiExternalIdentifierKey, poiExternalId)
189
+ intent.putExtra(PointrMapWidgetActivity.animationTypeKey, animationType)
190
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
191
+ PointrMapWidgetActivity.callback = callback
192
+ activityContext.startActivity(intent)
193
+ }
194
+
195
+ @ReactMethod
196
+ fun showPathFindingToPoi(
197
+ siteExternalId: String,
198
+ poiExternalId: String,
199
+ animationType: Int,
200
+ callback: Callback
201
+ ) {
202
+ val activityContext =
203
+ currentActivity ?: return callback.invoke("Could not get current activity")
204
+ val intent = Intent(activityContext, PointrMapWidgetActivity::class.java)
205
+ intent.putExtra(mapEventsListenerKey, CustomMapEventsListener(reactApplicationContext))
206
+ intent.action = PointrMapWidgetActivity.SHOW_PATHFINDING_TO_POI
207
+ intent.putExtra(PointrMapWidgetActivity.siteExternalIdentifierKey, siteExternalId)
208
+ intent.putExtra(PointrMapWidgetActivity.poiExternalIdentifierKey, poiExternalId)
209
+ intent.putExtra(PointrMapWidgetActivity.animationTypeKey, animationType)
210
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
211
+ PointrMapWidgetActivity.callback = callback
212
+ activityContext.startActivity(intent)
213
+ }
214
+
215
+ @ReactMethod
216
+ fun showPathFindingBetweenPOIs(
217
+ siteExternalId: String,
218
+ sourcePoiExternalId: String,
219
+ destinationPoiExternalId: String,
220
+ animationType: Int,
221
+ callback: Callback
222
+ ) {
223
+ val activityContext =
224
+ currentActivity ?: return callback.invoke("Could not get current activity")
225
+ val intent = Intent(activityContext, PointrMapWidgetActivity::class.java)
226
+ intent.putExtra(mapEventsListenerKey, CustomMapEventsListener(reactApplicationContext))
227
+ intent.action = PointrMapWidgetActivity.SHOW_PATHFINDING_BETWEEN_POIS
228
+ intent.putExtra(PointrMapWidgetActivity.siteExternalIdentifierKey, siteExternalId)
229
+ intent.putExtra(PointrMapWidgetActivity.sourcePoiExternalIdentifierKey, sourcePoiExternalId)
230
+ intent.putExtra(
231
+ PointrMapWidgetActivity.destinationPoiExternalIdentifierKey,
232
+ destinationPoiExternalId
233
+ )
234
+ intent.putExtra(PointrMapWidgetActivity.animationTypeKey, animationType)
235
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
236
+ PointrMapWidgetActivity.callback = callback
237
+ activityContext.startActivity(intent)
238
+ }
239
+
240
+ @ReactMethod
241
+ fun setPointrMapWidgetConfiguration(configurationString: String) {
242
+ try {
243
+ val jsonObject = JSONObject(configurationString)
244
+ setPointrMapWidgetConfiguration(jsonObject)
245
+ } catch (e: Exception) {
246
+ Log.e(name, "Unable to parse configuration!")
247
+ }
248
+ }
249
+
250
+ companion object {
251
+ const val NAME = "PTRNativePointrLibrary"
252
+
253
+ const val siteInternalIdentifierKey = "siteInternalIdentifier"
254
+ const val siteExternalIdentifierKey = "siteExternalIdentifier"
255
+ const val buildingInternalIdentifierKey = "buildingInternalIdentifier"
256
+ const val buildingExternalIdentifierKey = "buildingExternalIdentifier"
257
+ const val levelIndexKey = "levelIndex"
258
+ const val latitudeKey = "latitude"
259
+ const val longitudeKey = "longitude"
260
+ const val accuracyKey = "accuracy"
261
+ const val headingKey = "heading"
262
+ const val mapEventsListenerKey = "mapEventsListener"
263
+
264
+ const val OnPositionManagerCalculatedLocation = "OnPositionManagerCalculatedLocation"
265
+ const val OnBuildingClicked = "OnBuildingClicked"
266
+ const val OnSiteClicked = "OnSiteClicked"
267
+
268
+
269
+
270
+ fun sendEventToJs(
271
+ reactContext: ReactApplicationContext,
272
+ nameOfEvent: String,
273
+ params: WritableMap? = null
274
+ ) {
275
+ reactContext
276
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
277
+ .emit(nameOfEvent, params)
278
+ }
279
+ }
280
+
281
+
282
+ /**
283
+ * This class is where extra actions regarding Pointr are performed. It is always invoked from the
284
+ * actual entry point PointrLibraryModule.java. All of the apis are using external identifier
285
+ *
286
+ * This can be;
287
+ * - Showing a specific site
288
+ * - Showing a specific building
289
+ * - Showing a specific level
290
+ * - Showing a specific Poi
291
+ * - Pathfinding to a specific Poi
292
+ * - Getting current location
293
+ *
294
+ * We show an example of how to communicate from this class to the JS classes using an EventEmitter,
295
+ * for the PositionManager callback. Similarly in the App.js class there is an EventEmitter created
296
+ * which listens to this event.
297
+ */
298
+
299
+ private val positionManagerListener = object : PositionManager.Listener {
300
+ override fun onPositionManagerCalculatedLocation(p0: CalculatedLocation?) {
301
+ val calculatedLocation = p0 ?: return
302
+ val params = applyParamsForCalculatedLocation(calculatedLocation)
303
+ sendEventToJs(reactContext, OnPositionManagerCalculatedLocation, params)
304
+ }
305
+
306
+ override fun onPositionManagerDetectedPositionLevelChange(p0: Level) {}
307
+ override fun onPositionManagerPositionIsFading() {}
308
+ override fun onPositionManagerPositionIsLost() {}
309
+ override fun onPositionManagerPositioningServiceStateChangedTo(p0: PositioningTypes.PositioningServiceState?) {}
310
+ }
311
+
312
+ open class CustomMapEventsListener() : MapEventsListener, Parcelable {
313
+
314
+ private var reactContext: ReactApplicationContext? = null
315
+
316
+ constructor(reactContext: ReactApplicationContext) : this() {
317
+ this.reactContext = reactContext
318
+ }
319
+
320
+ constructor(parcel: Parcel) : this() {
321
+ }
322
+
323
+ // region [android.os.Parcelable]
324
+ override fun writeToParcel(parcel: Parcel, flags: Int) {
325
+
326
+ }
327
+
328
+ override fun describeContents(): Int {
329
+ return 0
330
+ }
331
+
332
+ companion object CREATOR : Parcelable.Creator<CustomMapEventsListener>,
333
+ MapEventsListener {
334
+
335
+ const val INTERNAL_ID = "internalIdentifier"
336
+ const val EXTERNAL_ID = "externalIdentifier"
337
+ const val TITLE = "title"
338
+
339
+ override fun createFromParcel(parcel: Parcel): CustomMapEventsListener {
340
+ return CustomMapEventsListener(parcel)
341
+ }
342
+
343
+ override fun newArray(size: Int): Array<CustomMapEventsListener?> {
344
+ return arrayOfNulls(size)
345
+ }
346
+ }
347
+ // endregion [android.os.Parcelable]
348
+
349
+ // region [com.pointrlabs.core.map.models.events_listeners.CustomMapEventsListener]
350
+ override fun mapDidReceiveTapOnBuilding(mapFragment: PTRMapFragment, building: Building) {
351
+ val params: WritableMap = Arguments.createMap()
352
+ params.putInt(INTERNAL_ID, building.internalIdentifier)
353
+ params.putString(EXTERNAL_ID, building.externalIdentifier)
354
+ params.putString(TITLE, building.title)
355
+ reactContext?.let {
356
+ sendEventToJs(it, OnBuildingClicked, params)
357
+ }
358
+ }
359
+
360
+ override fun mapDidReceiveTapOnSite(mapFragment: PTRMapFragment, site: Site) {
361
+ val params: WritableMap = Arguments.createMap()
362
+ params.putInt(INTERNAL_ID, site.internalIdentifier)
363
+ params.putString(EXTERNAL_ID, site.externalIdentifier)
364
+ params.putString(TITLE, site.title)
365
+ reactContext?.let {
366
+ sendEventToJs(it, OnSiteClicked, params)
367
+ }
368
+ }
369
+ // endregion [com.pointrlabs.core.map.models.events_listeners.CustomMapEventsListener]
370
+ }
371
+
372
+ private fun applyParamsForCalculatedLocation(calculatedLocation: CalculatedLocation): WritableMap {
373
+ val params: WritableMap = Arguments.createMap()
374
+ val site = calculatedLocation.site
375
+ val building = calculatedLocation.building
376
+ val level = calculatedLocation.level
377
+ val loc = calculatedLocation.location
378
+ site?.let {
379
+ params.putInt(siteInternalIdentifierKey, it.internalIdentifier)
380
+ params.putString(siteExternalIdentifierKey, it.externalIdentifier)
381
+ }
382
+ building?.let {
383
+ params.putInt(buildingInternalIdentifierKey, it.internalIdentifier)
384
+ params.putString(buildingExternalIdentifierKey, it.externalIdentifier)
385
+ }
386
+ level?.let {
387
+ params.putInt(levelIndexKey, it.index)
388
+ }
389
+ if (loc.lat != PositioningTypes.INVALID_FLOAT && loc.lon != PositioningTypes.INVALID_FLOAT) {
390
+ params.putDouble(latitudeKey, loc.lat)
391
+ params.putDouble(longitudeKey, loc.lon)
392
+ }
393
+ if (calculatedLocation.accuracy != PositioningTypes.INVALID_FLOAT) {
394
+ params.putDouble(accuracyKey, calculatedLocation.accuracy)
395
+ }
396
+ if (calculatedLocation.headingAccuracyClass == CalculatedLocation.HeadingAccuracyClass.HIGH) {
397
+ params.putDouble(headingKey, calculatedLocation.heading)
398
+ }
399
+ return params
400
+ }
401
+
402
+ fun initialize(
403
+ reactContext: ReactApplicationContext,
404
+ clientId: String,
405
+ baseUrl: String,
406
+ licenceKey: String,
407
+ env: String,
408
+ logLevel: Int
409
+ ) {
410
+ val ptrParams = PTRParams(clientId, licenceKey, baseUrl)
411
+ try {
412
+ val environment = PointrEnvironment.valueOf(env)
413
+ ptrParams.environment = environment
414
+ } catch (ex: IllegalArgumentException) {
415
+ Log.e(name, "Could not set environment of PTRParams for env: $env")
416
+ }
417
+ try {
418
+ val ptrLogLevel = LogLevel.values()[logLevel]
419
+ ptrParams.logLevel = ptrLogLevel
420
+ } catch (ex: IllegalArgumentException) {
421
+ Log.e(name, "Could not set log level of PTRParams for logLevel: $logLevel")
422
+ }
423
+ Pointr.with(reactContext, ptrParams)
424
+ }
425
+
426
+ private fun onPointrStartEnded(action: (String) -> Unit) {
427
+ val pointr = Pointr.getPointr() ?: return
428
+ pointr.addListener(object : PointrListener {
429
+ override fun onStateUpdated(p0: Pointr.State?) {
430
+ Log.v(name, "Pointr state updated: ${p0?.name}}")
431
+ val state = p0 ?: return
432
+ if (state.`val` > Pointr.State.OFF.`val` && state.`val` < Pointr.State.RUNNING.`val`) return
433
+ setPointrListeners()
434
+ action.invoke(state.name)
435
+ pointr.removeListener(this)
436
+ }
437
+ })
438
+ }
439
+
440
+ fun removePointrListeners() {
441
+ val pointr = Pointr.getPointr() ?: return
442
+ if (pointr.state != Pointr.State.RUNNING) return
443
+ pointr.positionManager?.removeListener(positionManagerListener)
444
+ }
445
+
446
+ private fun setPointrListeners() {
447
+ val pointr = Pointr.getPointr() ?: return
448
+ if (pointr.state != Pointr.State.RUNNING) return
449
+ pointr.positionManager?.addListener(positionManagerListener)
450
+ }
451
+
452
+ fun setPointrMapWidgetConfiguration(jsonObject: JSONObject) {
453
+ PointrMapWidgetActivity.mapWidgetConfiguration::class.members.forEach { kCallable ->
454
+ if (kCallable !is KMutableProperty1<*, *>) return@forEach
455
+ if (!jsonObject.has(kCallable.name)) return@forEach
456
+ try {
457
+ val value = if (kCallable.name == "isBuildingLevelSelectorEnabled")
458
+ jsonObject.getBoolean("isLevelSelectorEnabled")
459
+ else jsonObject.getBoolean(kCallable.name)
460
+ kCallable.setter.call(PointrMapWidgetActivity.mapWidgetConfiguration, value)
461
+ } catch (_: Exception) {
462
+ }
463
+ }
464
+ }
465
+
466
+ }
@@ -0,0 +1,17 @@
1
+ package com.pointr
2
+
3
+ import com.facebook.react.ReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.uimanager.ViewManager
7
+
8
+
9
+ class PointrPackage : ReactPackage {
10
+ override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
11
+ return listOf(PointrModule(reactContext))
12
+ }
13
+
14
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
15
+ return emptyList()
16
+ }
17
+ }
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+ android:layout_width="match_parent"
4
+ android:layout_height="match_parent"
5
+ android:id="@+id/pointr_map_widget_activity_layout"
6
+ xmlns:app="http://schemas.android.com/apk/res-auto">
7
+
8
+ <FrameLayout
9
+ android:id="@+id/fragment_container"
10
+ android:layout_width="0dp"
11
+ android:layout_height="0dp"
12
+ app:layout_constraintBottom_toBottomOf="parent"
13
+ app:layout_constraintEnd_toEndOf="parent"
14
+ app:layout_constraintStart_toStartOf="parent"
15
+ app:layout_constraintTop_toTopOf="parent"/>
16
+ </androidx.constraintlayout.widget.ConstraintLayout>
@@ -0,0 +1 @@
1
+ <resources></resources>
@@ -0,0 +1,19 @@
1
+ //
2
+ // PTRNativeLibrary.h
3
+ // pointrSample
4
+ //
5
+ // Created by Furkan Erdem Perşembe on 6.04.2020.
6
+ // Copyright © 2020 Pointr. All rights reserved.
7
+ //
8
+
9
+ #import <Foundation/Foundation.h>
10
+ #import <React/RCTBridgeModule.h>
11
+ #import <React/RCTEventEmitter.h>
12
+
13
+ NS_ASSUME_NONNULL_BEGIN
14
+
15
+ @interface PTRNativeLibrary : RCTEventEmitter
16
+
17
+ @end
18
+
19
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,150 @@
1
+ //
2
+ // PTRNativeLibrary.m
3
+ // pointrSample
4
+ //
5
+ // Created by Furkan Erdem Perşembe on 6.04.2020.
6
+ // Copyright © 2020 Pointr. All rights reserved.
7
+ //
8
+
9
+ #import "PTRNativeLibrary.h"
10
+
11
+ #import "react_native_pointr-Swift.h"
12
+ #import <React/RCTUtils.h>
13
+
14
+ @interface PTRNativeLibrary() <RCTBridgeModule, PTREventManagerDelegate>
15
+
16
+ @end
17
+
18
+ @implementation PTRNativeLibrary
19
+
20
+ bool hasListeners;
21
+
22
+ - (instancetype)init {
23
+ self = [super init];
24
+ PointrApp.sharedApp.eventManagerDelegate = self;
25
+ return self;
26
+ }
27
+
28
+ + (BOOL)requiresMainQueueSetup {
29
+ return NO;
30
+ }
31
+
32
+ RCT_EXPORT_MODULE(PTRNativePointrLibrary);
33
+
34
+ - (NSArray<NSString *> *)supportedEvents {
35
+ return @[@"OnPositionManagerCalculatedLocation", @"OnBuildingClicked", @"OnSiteClicked"];
36
+ }
37
+
38
+ - (dispatch_queue_t)methodQueue
39
+ {
40
+ return dispatch_get_main_queue();
41
+ }
42
+
43
+ // Will be called when this module's first listener is added.
44
+ -(void)startObserving {
45
+ hasListeners = YES;
46
+ }
47
+
48
+ // Will be called when this module's last listener is removed, or on dealloc.
49
+ -(void)stopObserving {
50
+ hasListeners = NO;
51
+ }
52
+
53
+ RCT_EXPORT_METHOD(initialize:(NSString *)licenseKey baseUrl:(NSString *)baseUrl clientIdentifier:(NSString *)clientIdentifier environment:(NSString *)environment logLevel:(int)logLevel) {
54
+ UIViewController *presentedViewController = RCTPresentedViewController();
55
+ [PointrApp.sharedApp initializeWithLicenseKey:licenseKey baseUrl:baseUrl clientIdentifier:clientIdentifier environment:environment logLevel:logLevel rootViewController:presentedViewController];
56
+ }
57
+
58
+ RCT_EXPORT_METHOD(start:(RCTResponseSenderBlock)callback) {
59
+ if (Pointr.shared.state == PointrStateRunning) {
60
+ callback(@[@"Pointr is already running"]);
61
+ } else {
62
+ [PointrApp.sharedApp startWithCompletion: ^(NSString *state) {
63
+ callback(@[state]);
64
+ }];
65
+ }
66
+ }
67
+
68
+ RCT_EXPORT_METHOD(stop) {
69
+ [PointrApp.sharedApp stop];
70
+ }
71
+
72
+ #pragma mark MapWidget
73
+
74
+ RCT_EXPORT_METHOD(showSite:(NSString *)siteExternalIdentifier animationType:(int)animationType callback:(RCTResponseSenderBlock)callback) {
75
+ [PointrApp.sharedApp showSiteWithSiteExternalIdentifier:siteExternalIdentifier animationType:animationType completion:^(NSString *error) {
76
+ callback(@[error]);
77
+ }];
78
+ }
79
+
80
+ RCT_EXPORT_METHOD(showBuilding:(NSString *)siteExternalIdentifier buildingExternalIdentifier: (NSString *)buildingExternalIdentifier animationType:(int)animationType callback:(RCTResponseSenderBlock)callback) {
81
+ [PointrApp.sharedApp showBuildingWithSiteExternalIdentifier:siteExternalIdentifier buildingExternalIdentifier:buildingExternalIdentifier animationType:animationType completion:^(NSString *error) {
82
+ callback(@[error]);
83
+ }];
84
+ }
85
+
86
+ RCT_EXPORT_METHOD(showLevel:(NSString *)siteExternalIdentifier buildingExternalIdentifier: (NSString *)buildingExternalIdentifier levelIndex:(int)levelIndex animationType:(int)animationType callback:(RCTResponseSenderBlock)callback) {
87
+ [PointrApp.sharedApp showLevelWithSiteExternalIdentifier:siteExternalIdentifier buildingExternalIdentifier:buildingExternalIdentifier levelIndex:levelIndex animationType:animationType completion:^(NSString *error) {
88
+ callback(@[error]);
89
+ }];
90
+ }
91
+
92
+ RCT_EXPORT_METHOD(showPoiDetails:(NSString *)siteExternalIdentifier poiExternalIdentifier: (NSString *)poiExternalIdentifier animationType:(int)animationType callback:(RCTResponseSenderBlock)callback) {
93
+ [PointrApp.sharedApp showPoiDetailsWithSiteExternalIdentifier:siteExternalIdentifier poiExternalIdentifier:poiExternalIdentifier animationType:animationType completion:^(NSString *error) {
94
+ callback(@[error]);
95
+ }];
96
+ }
97
+
98
+ RCT_EXPORT_METHOD(showPathFindingToPoi:(NSString *)siteExternalIdentifier poiExternalIdentifier: (NSString *)poiExternalIdentifier animationType:(int)animationType callback:(RCTResponseSenderBlock)callback) {
99
+ [PointrApp.sharedApp showPathFindingToPoiWithSiteExternalIdentifier:siteExternalIdentifier poiExternalIdentifier:poiExternalIdentifier animationType:animationType completion:^(NSString *error) {
100
+ callback(@[error]);
101
+ }];
102
+ }
103
+
104
+ RCT_EXPORT_METHOD(showPathFindingBetweenPOIs:(NSString *)siteExternalIdentifier sourcePoiExternalIdentifier: (NSString *)sourcePoiExternalIdentifier destinationPoiExternalIdentifier: (NSString *)destinationPoiExternalIdentifier animationType:(int)animationType callback:(RCTResponseSenderBlock)callback) {
105
+ [PointrApp.sharedApp showPathFindingBetweenPOIsWithSiteExternalIdentifier:siteExternalIdentifier sourcePoiExternalIdentifier:sourcePoiExternalIdentifier destinationPoiExternalIdentifier:destinationPoiExternalIdentifier animationType:animationType completion:^(NSString *error) {
106
+ if (error) {
107
+ callback(@[error]);
108
+ return;
109
+ }
110
+ callback(@[]);
111
+ }];
112
+ }
113
+
114
+ RCT_EXPORT_METHOD(getCurrentLocation:(RCTResponseSenderBlock)callback) {
115
+ [PointrApp.sharedApp getCurrentLocationWithCompletion:^(NSDictionary *location, NSString *error) {
116
+ if (error != nil) {
117
+ callback(@[error]);
118
+ } else {
119
+ if ([location count] > 0 && [[location objectForKey:@"latitude"] integerValue] != -999999) {
120
+ callback(@[location]);
121
+ } else {
122
+ callback(@[@"There is no location"]);
123
+ }
124
+ }
125
+ }];
126
+ }
127
+
128
+ RCT_EXPORT_METHOD(setPointrMapWidgetConfiguration:(NSString *)string) {
129
+ [PointrApp.sharedApp setPointrMapWidgetConfigurationWithString:string];
130
+ }
131
+
132
+ #pragma mark Event Manager Delegate
133
+
134
+ - (void)onPositionManagerCalculatedLocationWithLocation:(NSDictionary<NSString *,id> * _Nonnull)location {
135
+ if (!hasListeners) return;
136
+ [self sendEventWithName:@"OnPositionManagerCalculatedLocation" body:location];
137
+ }
138
+
139
+ - (void)onBuildingClicked:(NSDictionary<NSString *,id> * _Nonnull)building {
140
+ if (!hasListeners) return;
141
+ [self sendEventWithName:@"OnBuildingClicked" body:building];
142
+ }
143
+
144
+
145
+ - (void)onSiteClicked:(NSDictionary<NSString *,id> * _Nonnull)site {
146
+ if (!hasListeners) return;
147
+ [self sendEventWithName:@"OnSiteClicked" body:site];
148
+ }
149
+
150
+ @end