react-native-pointr 8.14.0 → 8.15.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,281 @@
1
+ #import "PTRMapWidgetContainerView.h"
2
+ #import "react_native_pointr-Swift.h"
3
+
4
+ NSString * const kLayerStaticPath = @"static-path";
5
+
6
+ @implementation PTRMapWidgetContainerView
7
+
8
+ - (void) ptrMapWidgetDidEndLoadingWithParameters:(NSDictionary *)parameters {
9
+ if (self.onMapWidgetDidEndLoading) {
10
+ self.onMapWidgetDidEndLoading(parameters);
11
+ }
12
+ }
13
+
14
+ -(nonnull PTRMapWidgetViewController *) getMapWidget {
15
+ if ([self waitForPointrState] == PointrStateRunning) {
16
+ [self waitForConfiguration];
17
+ } else {
18
+ NSLog(@"Pointr is not running");
19
+ }
20
+ NSLog(@"initializing map widget");
21
+ PTRMapWidgetConfiguration *config = [PointrApp.sharedApp getMapWidgetConfiguration];
22
+ PTRMapwidgetExitButtonConfiguration *exitButtonConfiguration = [[PTRMapwidgetExitButtonConfiguration alloc] initWithPreferredPosition:PTRMapwidgetExitButtonPositionTopRight visibility:PTRMapwidgetExitButtonVisibilityNotVisible];
23
+ config.exitButtonConfiguration = exitButtonConfiguration;
24
+ _mapWidget = [[PTRMapWidgetViewController alloc] initWithConfiguration:config];
25
+ return self.mapWidget;
26
+ }
27
+
28
+ -(void) present:(PTRMapWidgetViewController *) mapWidget {
29
+ [self addSubview: mapWidget.view];
30
+ mapWidget.view.translatesAutoresizingMaskIntoConstraints = NO;
31
+ [NSLayoutConstraint activateConstraints:@[
32
+ [mapWidget.view.leadingAnchor constraintEqualToAnchor:self.leadingAnchor],
33
+ [mapWidget.view.trailingAnchor constraintEqualToAnchor:self.trailingAnchor],
34
+ [mapWidget.view.topAnchor constraintEqualToAnchor:self.topAnchor],
35
+ [mapWidget.view.bottomAnchor constraintEqualToAnchor:self.bottomAnchor],
36
+ ]];
37
+ }
38
+
39
+ -(void) showStaticPath:(NSString *) siteExternalIdentifier fromPoiExternalIdentifier:(NSString *) fromPoiExternalIdentifier toPoiExternalIdentifier:(NSString *) toPoiExternalIdentifier {
40
+ [self waitForPointrState];
41
+ [self waitForConfiguration];
42
+ NSMutableDictionary *ptrCommand = [NSMutableDictionary dictionaryWithObjectsAndKeys:
43
+ @"staticPath", @"command",
44
+ siteExternalIdentifier, @"siteExternalIdentifier",
45
+ fromPoiExternalIdentifier, @"fromPoiExternalIdentifier",
46
+ toPoiExternalIdentifier, @"toPoiExternalIdentifier",
47
+ nil];
48
+ PTRSite *site = [self getSite: siteExternalIdentifier];
49
+ if (!site) {
50
+ ptrCommand[@"error"] = @"Site not found";
51
+ [self ptrMapWidgetDidEndLoadingWithParameters: ptrCommand];
52
+ NSLog(@"no site found");
53
+ return;
54
+ }
55
+ PTRPoi *fromPoi = [self getPoi:site poiExternalIdentifier: fromPoiExternalIdentifier];
56
+ if (!fromPoi) {
57
+ ptrCommand[@"error"] = @"Source poi not found";
58
+ [self ptrMapWidgetDidEndLoadingWithParameters: ptrCommand];
59
+ NSLog(@"Source poi not found");
60
+ return;
61
+ }
62
+ PTRPoi *toPoi = [self getPoi:site poiExternalIdentifier: toPoiExternalIdentifier];
63
+ if (!toPoi) {
64
+ ptrCommand[@"error"] = @"Target poi not found";
65
+ [self ptrMapWidgetDidEndLoadingWithParameters: ptrCommand];
66
+ NSLog(@"Destination poi not found");
67
+ return;
68
+ }
69
+ [self waitForPath: site];
70
+ id<PTRPathManagerInterface> pathManager = Pointr.shared.pathManager;
71
+ if (!pathManager) {
72
+ ptrCommand[@"error"] = @"Path manager not found";
73
+ [self ptrMapWidgetDidEndLoadingWithParameters: ptrCommand];
74
+ NSLog(@"Path manager not found");
75
+ return;
76
+ }
77
+ PTRPath *path = [pathManager calculatePathFromLocation:fromPoi toNearestLocationInArray: @[toPoi]];
78
+ if (!path) {
79
+ ptrCommand[@"error"] = @"Path not found";
80
+ [self ptrMapWidgetDidEndLoadingWithParameters: ptrCommand];
81
+ NSLog(@"Path not found");
82
+ return;
83
+ }
84
+ dispatch_async(dispatch_get_main_queue(), ^{
85
+ PTRMapWidgetViewController *mapWidget = [self getMapWidget];
86
+ PTRLevel *level = fromPoi.location.level;
87
+ if (!level) {
88
+ [mapWidget showSite:site animationType:PTRMapAnimationTypeStandard completion:^(PTRMapWidgetError * _Nullable error) {
89
+ if (error) {
90
+ ptrCommand[@"error"] = error ? error.errorCode : @"";
91
+ [self ptrMapWidgetDidEndLoadingWithParameters: ptrCommand];
92
+ NSLog(@"Error showing site: %@", error.errorCode);
93
+ return;
94
+ }
95
+ [self setStaticPath:mapWidget.mapViewController fromPoi: fromPoi toPoi:toPoi path:path];
96
+ ptrCommand[@"error"] = @"";
97
+ [self ptrMapWidgetDidEndLoadingWithParameters: ptrCommand];
98
+ NSLog(@"ready");
99
+ }];
100
+ } else {
101
+ [mapWidget showLevel:level animationType:PTRMapAnimationTypeStandard completion:^(PTRMapWidgetError * _Nullable error) {
102
+ if (error) {
103
+ ptrCommand[@"error"] = error ? error.errorCode : @"";
104
+ [self ptrMapWidgetDidEndLoadingWithParameters: ptrCommand];
105
+ NSLog(@"Error showing level: %@", error.errorCode);
106
+ return;
107
+ }
108
+ [self setStaticPath:mapWidget.mapViewController fromPoi: fromPoi toPoi:toPoi path:path];
109
+ ptrCommand[@"error"] = @"";
110
+ [self ptrMapWidgetDidEndLoadingWithParameters: ptrCommand];
111
+ NSLog(@"ready");
112
+ }];
113
+ }
114
+ [self present: mapWidget];
115
+ });
116
+ }
117
+
118
+ -(void) setStaticPath:(PTRMapViewController *) map fromPoi:(PTRPoi *) fromPoi toPoi:(PTRPoi *) toPoi path:(PTRPath *) path {
119
+ PTRMapSymbolLayer *layer = [[PTRMapSymbolLayer alloc] initWithIdentifier: kLayerStaticPath];
120
+ [map addLayer: layer];
121
+ [map addFeatures:@[fromPoi, toPoi] toLayer:layer.identifier];
122
+ [map zoomToCoordinate:fromPoi.location.coordinate];
123
+ map.currentPath = path;
124
+ }
125
+
126
+ -(void) waitForPath:(nonnull PTRSite *) site {
127
+ NSLog(@"waiting for path to be ready");
128
+ id<PTRPathManagerInterface> pathManager = Pointr.shared.pathManager;
129
+ if (!pathManager) return;
130
+ self.site = site;
131
+ self.semaphore = dispatch_semaphore_create(0);
132
+ [pathManager addListener:self];
133
+ if (![pathManager isReadyForSite:site]) {
134
+ // Define a timeout of 5 seconds
135
+ dispatch_time_t timeout = dispatch_walltime(NULL, 5 * NSEC_PER_SEC);
136
+ if (dispatch_semaphore_wait(self.semaphore, timeout) != 0) {
137
+ NSLog(@"Timeout waiting for pathmanager");
138
+ }
139
+ }
140
+ [pathManager removeListener:self];
141
+ }
142
+
143
+ - (void)onPathManagerReadyForSite:(nonnull PTRSite *)site {
144
+ if (site.internalIdentifier != self.site.internalIdentifier) return;
145
+
146
+ // Signal the semaphore to unblock the thread
147
+ NSLog(@"path became ready.");
148
+ dispatch_semaphore_signal(self.semaphore);
149
+ }
150
+
151
+
152
+ -(nullable PTRPoi *) getPoi:(nonnull PTRSite *) site poiExternalIdentifier:(NSString *) poiExternalIdentifier {
153
+ id<PTRPoiManagerInterface> poiManager = Pointr.shared.poiManager;
154
+ if (!poiManager) return nil;
155
+ if (![poiManager hasContentForSite:site]) {
156
+ [self waitForPois: site];
157
+ }
158
+ PTRPoi *poi = [poiManager poisForSite:site withExternalIdentifier:poiExternalIdentifier];
159
+ if (!poi) {
160
+ return [poiManager poisForSite:site withIdentifier:poiExternalIdentifier];
161
+ }
162
+ return poi;
163
+ }
164
+
165
+ -(void) waitForPois:(nonnull PTRSite *) site {
166
+ NSLog(@"waiting for data to be ready");
167
+ id<PTRDataManagerInterface> dataManager = Pointr.shared.dataManager;
168
+ if (!dataManager) return;
169
+ self.site = site;
170
+ self.semaphore = dispatch_semaphore_create(0);
171
+ [dataManager addListener:self];
172
+ [dataManager loadDataForSite:site.internalIdentifier];
173
+ if (![dataManager isContentReadyForSite:site.internalIdentifier]) {
174
+ // Define a timeout of 5 seconds
175
+ dispatch_time_t timeout = dispatch_walltime(NULL, 5 * NSEC_PER_SEC);
176
+ // Wait for the semaphore to be signaled or timeout
177
+ if (dispatch_semaphore_wait(self.semaphore, timeout) != 0) {
178
+ NSLog(@"Timeout waiting for datamanager");
179
+ }
180
+ }
181
+ [dataManager removeListener:self];
182
+ }
183
+
184
+ - (void)onDataManagerCompleteAllForSite:(nonnull PTRSite *)site
185
+ isSuccessful:(BOOL)isSuccessful
186
+ dataFromOnline:(BOOL)isOnlineData
187
+ errorMessages:(nonnull NSDictionary<NSNumber *, NSString *> *)errorMessages {
188
+ if (!isOnlineData) return;
189
+ if (site.internalIdentifier != self.site.internalIdentifier) return;
190
+
191
+ // Signal the semaphore to unblock the thread
192
+ NSLog(@"data became ready.");
193
+ dispatch_semaphore_signal(self.semaphore);
194
+ }
195
+
196
+ -(nullable PTRSite *) getSite:(NSString *) siteExternalIdentifier {
197
+ id<PTRSiteManagerInterface> siteManager = Pointr.shared.siteManager;
198
+ if(!siteManager) return nil;
199
+ if(siteManager.sites.count == 0) {
200
+ [self waitForSites];
201
+ }
202
+ return [siteManager siteWithExternalIdentifier:siteExternalIdentifier];
203
+ }
204
+
205
+ -(void) waitForSites {
206
+
207
+ NSLog(@"waiting for sites");
208
+ self.semaphore = dispatch_semaphore_create(0);
209
+ [Pointr.shared.siteManager addListener:self];
210
+ if (![self isConfigurationReady]) {
211
+ // Define a timeout of 5 seconds
212
+ dispatch_time_t timeout = dispatch_walltime(NULL, 5 * NSEC_PER_SEC);
213
+ // Wait for the semaphore to be signaled or timeout
214
+ if (dispatch_semaphore_wait(self.semaphore, timeout) != 0) {
215
+ NSLog(@"Timeout waiting for configuration");
216
+ }
217
+ }
218
+ [Pointr.shared.siteManager removeListener:self];
219
+ }
220
+
221
+ -(void) onSiteManagerDataChanged {
222
+ // Signal the semaphore to unblock the thread
223
+ NSLog(@"sites became ready.");
224
+ dispatch_semaphore_signal(self.semaphore);
225
+ }
226
+
227
+ -(void) waitForConfiguration {
228
+ NSLog(@"waiting for configuration");
229
+ self.semaphore = dispatch_semaphore_create(0);
230
+ id<PTRConfigurationManagerInterface> configurationManager = Pointr.shared.configurationManager;
231
+ if (!configurationManager) {
232
+ NSLog(@"configuration manager is nil");
233
+ return;
234
+ }
235
+ [configurationManager addListener:self];
236
+ if (![self isConfigurationReady]) {
237
+ // Define a timeout of 5 seconds
238
+ dispatch_time_t timeout = dispatch_walltime(NULL, 5 * NSEC_PER_SEC);
239
+ // Wait for the semaphore to be signaled or timeout
240
+ if (dispatch_semaphore_wait(self.semaphore, timeout) != 0) {
241
+ NSLog(@"Timeout waiting for configuration");
242
+ }
243
+ }
244
+ [configurationManager removeListener:self];
245
+ }
246
+
247
+ -(BOOL) isConfigurationReady {
248
+ NSString *styleUrl = Pointr.shared.configurationManager.globalConfiguration.sdkConfiguration.styleJsonUrl;
249
+ NSLog(@"Style: %@", styleUrl);
250
+ if (!styleUrl || styleUrl.length == 0) {
251
+ NSString *styleUrlWithContent = Pointr.shared.configurationManager.globalConfiguration.sdkConfiguration.styleJsonUrlWithContent;
252
+ NSLog(@"Style with content: %@", styleUrlWithContent);
253
+ return styleUrlWithContent && styleUrlWithContent.length != 0;
254
+ }
255
+ return YES;
256
+ }
257
+
258
+ -(void) onConfigurationManagerChangedConfiguration {
259
+ // Signal the semaphore to unblock the thread
260
+ NSLog(@"configuration became ready.");
261
+ dispatch_semaphore_signal(self.semaphore);
262
+ }
263
+
264
+
265
+ - (PointrState) waitForPointrState {
266
+ NSLog(@"waiting for pointr to run");
267
+ PointrState state1 = [Pointr shared].state;
268
+ if (state1 == PointrStateRunning || state1 < PointrStateOff) {
269
+ return [Pointr shared].state;
270
+ }
271
+ dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
272
+ [[Pointr shared] startWithParams:PointrApp.params onStateChanged:^(PointrState state) {
273
+ if (state == PointrStateRunning || state < PointrStateOff) {
274
+ dispatch_semaphore_signal(semaphore);
275
+ }
276
+ }];
277
+ dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
278
+ return [Pointr shared].state;
279
+ }
280
+
281
+ @end
@@ -0,0 +1,256 @@
1
+ #import <React/RCTViewManager.h>
2
+ #import <React/RCTUIManager.h>
3
+ #import <PointrKit/PointrKit.h>
4
+ #import "PTRMapWidgetContainerView.h"
5
+
6
+ @interface PTRMapWidgetManager: RCTViewManager
7
+ @end
8
+
9
+ @implementation PTRMapWidgetManager
10
+
11
+ RCT_EXPORT_MODULE(PTRMapWidget)
12
+
13
+ RCT_EXPORT_VIEW_PROPERTY(onMapWidgetDidEndLoading, RCTBubblingEventBlock)
14
+
15
+ - (UIView *)view {
16
+ PTRMapWidgetContainerView *view = [[PTRMapWidgetContainerView alloc] init];
17
+ return view;
18
+ }
19
+
20
+ RCT_EXPORT_METHOD(site:(nonnull NSNumber*) reactTag siteExternalIdentifier:(NSString*) siteExternalIdentifier) {
21
+ [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
22
+ UIView *view = viewRegistry[reactTag];
23
+ if (!view || ![view isKindOfClass:[PTRMapWidgetContainerView class]]) {
24
+ RCTLogError(@"Cannot find PTRMapWidgetContainerView with tag #%@", reactTag);
25
+ return;
26
+ }
27
+ NSLog(@"found PTRMapWidgetContainerView");
28
+ PTRMapWidgetContainerView *ptrMapWidgetContainerView = (PTRMapWidgetContainerView *)view;
29
+ dispatch_async(dispatch_get_main_queue(), ^{
30
+ PTRMapWidgetViewController *mapWidget = [ptrMapWidgetContainerView getMapWidget];
31
+ NSLog(@"calling show site method of mapWidget");
32
+ [mapWidget showSiteWithSiteExternalIdentifier:siteExternalIdentifier animationType:PTRMapAnimationTypeNone completion: ^(PTRMapWidgetError * _Nullable error) {
33
+ NSDictionary *ptrCommand = @{
34
+ @"command": @"site",
35
+ @"siteExternalIdentifier": siteExternalIdentifier,
36
+ @"error": error ? error.errorCode : @""
37
+ };
38
+ [ptrMapWidgetContainerView ptrMapWidgetDidEndLoadingWithParameters: ptrCommand];
39
+ if (error) {
40
+ NSLog(@"Error showing site: %@", error.errorCode);
41
+ return;
42
+ }
43
+ NSLog(@"ready");
44
+ }];
45
+ [ptrMapWidgetContainerView present:mapWidget];
46
+ });
47
+ }];
48
+ }
49
+
50
+ RCT_EXPORT_METHOD(building:(nonnull NSNumber*) reactTag siteExternalIdentifier:(NSString*) siteExternalIdentifier buildingExternalIdentifier:(NSString*) buildingExternalIdentifier) {
51
+ [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
52
+ UIView *view = viewRegistry[reactTag];
53
+ if (!view || ![view isKindOfClass:[PTRMapWidgetContainerView class]]) {
54
+ RCTLogError(@"Cannot find PTRMapWidgetContainerView with tag #%@", reactTag);
55
+ return;
56
+ }
57
+ NSLog(@"found PTRMapWidgetContainerView");
58
+ PTRMapWidgetContainerView *ptrMapWidgetContainerView = (PTRMapWidgetContainerView *)view;
59
+ dispatch_async(dispatch_get_main_queue(), ^{
60
+ PTRMapWidgetViewController *mapWidget = [ptrMapWidgetContainerView getMapWidget];
61
+ NSLog(@"calling show building method of mapWidget");
62
+ [mapWidget showBuildingWithSiteExternalIdentifier:siteExternalIdentifier buildingExternalIdentifier:buildingExternalIdentifier animationType:PTRMapAnimationTypeNone completion: ^(PTRMapWidgetError * _Nullable error) {
63
+ NSDictionary *ptrCommand = @{
64
+ @"command": @"building",
65
+ @"siteExternalIdentifier": siteExternalIdentifier,
66
+ @"buildingExternalIdentifier": buildingExternalIdentifier,
67
+ @"error": error ? error.errorCode : @""
68
+ };
69
+ [ptrMapWidgetContainerView ptrMapWidgetDidEndLoadingWithParameters: ptrCommand];
70
+ }];
71
+ [ptrMapWidgetContainerView present:mapWidget];
72
+ });
73
+ }];
74
+ }
75
+
76
+ RCT_EXPORT_METHOD(level:(nonnull NSNumber*) reactTag siteExternalIdentifier:(NSString*) siteExternalIdentifier buildingExternalIdentifier:(NSString*) buildingExternalIdentifier levelIndex:(NSInteger) levelIndex) {
77
+ [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
78
+ UIView *view = viewRegistry[reactTag];
79
+ if (!view || ![view isKindOfClass:[PTRMapWidgetContainerView class]]) {
80
+ RCTLogError(@"Cannot find PTRMapWidgetContainerView with tag #%@", reactTag);
81
+ return;
82
+ }
83
+ NSLog(@"found PTRMapWidgetContainerView");
84
+ PTRMapWidgetContainerView *ptrMapWidgetContainerView = (PTRMapWidgetContainerView *)view;
85
+ dispatch_async(dispatch_get_main_queue(), ^{
86
+ PTRMapWidgetViewController *mapWidget = [ptrMapWidgetContainerView getMapWidget];
87
+ NSLog(@"calling show level method of mapWidget");
88
+ [mapWidget showLevelWithSiteExternalIdentifier:siteExternalIdentifier buildingExternalIdentifier:buildingExternalIdentifier levelIndex: levelIndex animationType:PTRMapAnimationTypeNone completion: ^(PTRMapWidgetError * _Nullable error) {
89
+ NSDictionary *ptrCommand = @{
90
+ @"command": @"level",
91
+ @"siteExternalIdentifier": siteExternalIdentifier,
92
+ @"buildingExternalIdentifier": buildingExternalIdentifier,
93
+ @"levelIndex": [NSNumber numberWithInteger: levelIndex],
94
+ @"error": error ? error.errorCode : @""
95
+ };
96
+ [ptrMapWidgetContainerView ptrMapWidgetDidEndLoadingWithParameters: ptrCommand];
97
+ }];
98
+ [ptrMapWidgetContainerView present:mapWidget];
99
+ });
100
+ }];
101
+ }
102
+
103
+ RCT_EXPORT_METHOD(poi:(nonnull NSNumber*) reactTag siteExternalIdentifier:(NSString*) siteExternalIdentifier poiExternalIdentifier:(NSString*) poiExternalIdentifier) {
104
+ [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
105
+ UIView *view = viewRegistry[reactTag];
106
+ if (!view || ![view isKindOfClass:[PTRMapWidgetContainerView class]]) {
107
+ RCTLogError(@"Cannot find PTRMapWidgetContainerView with tag #%@", reactTag);
108
+ return;
109
+ }
110
+ NSLog(@"found PTRMapWidgetContainerView");
111
+ PTRMapWidgetContainerView *ptrMapWidgetContainerView = (PTRMapWidgetContainerView *)view;
112
+ dispatch_async(dispatch_get_main_queue(), ^{
113
+ PTRMapWidgetViewController *mapWidget = [ptrMapWidgetContainerView getMapWidget];
114
+ NSLog(@"calling show poi method of mapWidget");
115
+ [mapWidget showPoiDetailsWithSiteExternalIdentifier: siteExternalIdentifier poiExternalIdentifier: poiExternalIdentifier animationType:PTRMapAnimationTypeNone completion: ^(PTRMapWidgetError * _Nullable error) {
116
+ NSDictionary *ptrCommand = @{
117
+ @"command": @"poi",
118
+ @"siteExternalIdentifier": siteExternalIdentifier,
119
+ @"poiExternalIdentifier": poiExternalIdentifier,
120
+ @"error": error ? error.errorCode : @""
121
+ };
122
+ [ptrMapWidgetContainerView ptrMapWidgetDidEndLoadingWithParameters: ptrCommand];
123
+ }];
124
+ [ptrMapWidgetContainerView present:mapWidget];
125
+ });
126
+ }];
127
+ }
128
+
129
+ RCT_EXPORT_METHOD(path:(nonnull NSNumber*) reactTag siteExternalIdentifier:(NSString*) siteExternalIdentifier toPoiExternalIdentifier:(NSString*) toPoiExternalIdentifier) {
130
+ [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
131
+ UIView *view = viewRegistry[reactTag];
132
+ if (!view || ![view isKindOfClass:[PTRMapWidgetContainerView class]]) {
133
+ RCTLogError(@"Cannot find PTRMapWidgetContainerView with tag #%@", reactTag);
134
+ return;
135
+ }
136
+ NSLog(@"found PTRMapWidgetContainerView");
137
+ PTRMapWidgetContainerView *ptrMapWidgetContainerView = (PTRMapWidgetContainerView *)view;
138
+ dispatch_async(dispatch_get_main_queue(), ^{
139
+ PTRMapWidgetViewController *mapWidget = [ptrMapWidgetContainerView getMapWidget];
140
+ NSLog(@"calling show path method of mapWidget");
141
+ [mapWidget showPathFindingWithSiteExternalIdentifier: siteExternalIdentifier poiExternalIdentifier:toPoiExternalIdentifier animationType:PTRMapAnimationTypeNone completion: ^(PTRMapWidgetError * _Nullable error) {
142
+ NSDictionary *ptrCommand = @{
143
+ @"command": @"path",
144
+ @"siteExternalIdentifier": siteExternalIdentifier,
145
+ @"poiExternalIdentifier": toPoiExternalIdentifier,
146
+ @"error": error ? error.errorCode : @""
147
+ };
148
+ [ptrMapWidgetContainerView ptrMapWidgetDidEndLoadingWithParameters: ptrCommand];
149
+ }];
150
+ [ptrMapWidgetContainerView present:mapWidget];
151
+ });
152
+ }];
153
+ }
154
+
155
+ RCT_EXPORT_METHOD(staticPath:(nonnull NSNumber*) reactTag siteExternalIdentifier:(NSString*) siteExternalIdentifier fromPoiExternalIdentifier:(NSString*) fromPoiExternalIdentifier toPoiExternalIdentifier:(NSString*) toPoiExternalIdentifier) {
156
+ [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
157
+ UIView *view = viewRegistry[reactTag];
158
+ if (!view || ![view isKindOfClass:[PTRMapWidgetContainerView class]]) {
159
+ RCTLogError(@"Cannot find PTRMapWidgetContainerView with tag #%@", reactTag);
160
+ return;
161
+ }
162
+ NSLog(@"found PTRMapWidgetContainerView");
163
+ PTRMapWidgetContainerView *ptrMapWidgetContainerView = (PTRMapWidgetContainerView *)view;
164
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
165
+ [ptrMapWidgetContainerView showStaticPath: siteExternalIdentifier fromPoiExternalIdentifier: fromPoiExternalIdentifier toPoiExternalIdentifier: toPoiExternalIdentifier];
166
+ });
167
+ }];
168
+ }
169
+
170
+ RCT_EXPORT_METHOD(markMyCarForLevel:(nonnull NSNumber*) reactTag siteExternalIdentifier:(nonnull NSString*) siteExternalIdentifier buildingExternalIdentifier:(nonnull NSString*) buildingExternalIdentifier levelIndex:(NSInteger) levelIndex shouldShowPopup:(BOOL) shouldShowPopup animationType:(NSInteger) animationType) {
171
+ [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
172
+ UIView *view = viewRegistry[reactTag];
173
+ if (!view || ![view isKindOfClass:[PTRMapWidgetContainerView class]]) {
174
+ RCTLogError(@"Cannot find PTRMapWidgetContainerView with tag #%@", reactTag);
175
+ return;
176
+ }
177
+ NSLog(@"found PTRMapWidgetContainerView");
178
+ PTRMapWidgetContainerView *ptrMapWidgetContainerView = (PTRMapWidgetContainerView *)view;
179
+ dispatch_async(dispatch_get_main_queue(), ^{
180
+ PTRMapWidgetViewController *mapWidget = [ptrMapWidgetContainerView getMapWidget];
181
+ NSLog(@"calling show mark my car method of mapWidget");
182
+ if (levelIndex == [PTRPositioningTypes invalidInteger]) {
183
+ NSLog(@"Level index cannot be invalid");
184
+ return;
185
+ }
186
+ [mapWidget showMarkMyCarDetailsWithSiteExternalIdentifier:siteExternalIdentifier buildingExternalIdentifier:buildingExternalIdentifier levelIndex:levelIndex showPopup:shouldShowPopup animationType:(PTRMapAnimationType)animationType completion:^(PTRMapWidgetError * _Nullable error) {
187
+ NSDictionary *ptrCommand = @{
188
+ @"command": @"markMyCarForLevel",
189
+ @"siteExternalIdentifier": siteExternalIdentifier,
190
+ @"buildingExternalIdentifier": buildingExternalIdentifier,
191
+ @"levelIndex": [NSNumber numberWithInteger: levelIndex],
192
+ @"shouldShowPopup": @(shouldShowPopup),
193
+ @"animationType": @(animationType),
194
+ @"error": error ? error.errorCode : @""
195
+ };
196
+ [ptrMapWidgetContainerView ptrMapWidgetDidEndLoadingWithParameters: ptrCommand];
197
+ }];
198
+ [ptrMapWidgetContainerView present:mapWidget];
199
+ });
200
+ }];
201
+ }
202
+
203
+ RCT_EXPORT_METHOD(markMyCarForSite:(nonnull NSNumber*) reactTag siteExternalIdentifier:(nonnull NSString*) siteExternalIdentifier shouldShowPopup:(BOOL) shouldShowPopup animationType:(NSInteger) animationType) {
204
+ [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
205
+ UIView *view = viewRegistry[reactTag];
206
+ if (!view || ![view isKindOfClass:[PTRMapWidgetContainerView class]]) {
207
+ RCTLogError(@"Cannot find PTRMapWidgetContainerView with tag #%@", reactTag);
208
+ return;
209
+ }
210
+ NSLog(@"found PTRMapWidgetContainerView");
211
+ PTRMapWidgetContainerView *ptrMapWidgetContainerView = (PTRMapWidgetContainerView *)view;
212
+ dispatch_async(dispatch_get_main_queue(), ^{
213
+ PTRMapWidgetViewController *mapWidget = [ptrMapWidgetContainerView getMapWidget];
214
+ NSLog(@"calling show mark my car method of mapWidget");
215
+ [mapWidget showMarkMyCarDetailsWithSiteExternalIdentifier:siteExternalIdentifier showPopup:shouldShowPopup animationType: (PTRMapAnimationType) animationType completion:^(PTRMapWidgetError * _Nullable error) {
216
+ NSDictionary *ptrCommand = @{
217
+ @"command": @"markMyCarForSite",
218
+ @"siteExternalIdentifier": siteExternalIdentifier,
219
+ @"shouldShowPopup": @(shouldShowPopup),
220
+ @"animationType": @(animationType),
221
+ @"error": error ? error.errorCode : @""
222
+ };
223
+ [ptrMapWidgetContainerView ptrMapWidgetDidEndLoadingWithParameters: ptrCommand];
224
+ }];
225
+ [ptrMapWidgetContainerView present:mapWidget];
226
+ });
227
+ }];
228
+ }
229
+
230
+ RCT_EXPORT_METHOD(myCarForSite:(nonnull NSNumber*) reactTag siteExternalIdentifier:(nonnull NSString*) siteExternalIdentifier animationType:(NSInteger) animationType) {
231
+ [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
232
+ UIView *view = viewRegistry[reactTag];
233
+ if (!view || ![view isKindOfClass:[PTRMapWidgetContainerView class]]) {
234
+ RCTLogError(@"Cannot find PTRMapWidgetContainerView with tag #%@", reactTag);
235
+ return;
236
+ }
237
+ NSLog(@"found PTRMapWidgetContainerView");
238
+ PTRMapWidgetContainerView *ptrMapWidgetContainerView = (PTRMapWidgetContainerView *)view;
239
+ dispatch_async(dispatch_get_main_queue(), ^{
240
+ PTRMapWidgetViewController *mapWidget = [ptrMapWidgetContainerView getMapWidget];
241
+ NSLog(@"calling show mark my car method of mapWidget");
242
+ [mapWidget showMyCarDetailsWithSiteExternalIdentifier: siteExternalIdentifier animationType: (PTRMapAnimationType) animationType completion:^(PTRMapWidgetError * _Nullable error) {
243
+ NSDictionary *ptrCommand = @{
244
+ @"command": @"myCarForSite",
245
+ @"siteExternalIdentifier": siteExternalIdentifier,
246
+ @"animationType": @(animationType),
247
+ @"error": error ? error.errorCode : @""
248
+ };
249
+ [ptrMapWidgetContainerView ptrMapWidgetDidEndLoadingWithParameters: ptrCommand];
250
+ }];
251
+ [ptrMapWidgetContainerView present:mapWidget];
252
+ });
253
+ }];
254
+ }
255
+
256
+ @end
@@ -1,11 +1,3 @@
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
1
  #import <Foundation/Foundation.h>
10
2
  #import <React/RCTBridgeModule.h>
11
3
  #import <React/RCTEventEmitter.h>
@@ -1,11 +1,3 @@
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
1
  #import "PTRNativeLibrary.h"
10
2
 
11
3
  #import "react_native_pointr-Swift.h"
@@ -50,6 +42,10 @@ RCT_EXPORT_MODULE(PTRNativePointrLibrary);
50
42
  hasListeners = NO;
51
43
  }
52
44
 
45
+ RCT_EXPORT_METHOD(shouldRequestPermissionsAtStartup:(BOOL) shouldRequestPermissionsAtStartup) {
46
+ PointrApp.shouldRequestPermissionsAtStartup = shouldRequestPermissionsAtStartup;
47
+ }
48
+
53
49
  RCT_EXPORT_METHOD(initialize:(NSString *)licenseKey baseUrl:(NSString *)baseUrl clientIdentifier:(NSString *)clientIdentifier environment:(NSString *)environment logLevel:(int)logLevel) {
54
50
  UIViewController *presentedViewController = RCTPresentedViewController();
55
51
  [PointrApp.sharedApp initializeWithLicenseKey:licenseKey baseUrl:baseUrl clientIdentifier:clientIdentifier environment:environment logLevel:logLevel rootViewController:presentedViewController];
@@ -129,6 +125,19 @@ RCT_EXPORT_METHOD(setPointrMapWidgetConfiguration:(NSString *)string) {
129
125
  [PointrApp.sharedApp setPointrMapWidgetConfigurationWithString:string];
130
126
  }
131
127
 
128
+ RCT_EXPORT_METHOD(requestPermissions) {
129
+ [PointrApp.sharedApp requestPermissions];
130
+ }
131
+
132
+ RCT_EXPORT_METHOD(isMyCarMarked:(RCTResponseSenderBlock)callback) {
133
+ PTRFeature *feature = [Pointr.shared getMyCarFeature];
134
+ if (feature == nil) {
135
+ callback(@[@"No saved location"]);
136
+ return;
137
+ }
138
+ callback(@[]);
139
+ }
140
+
132
141
  #pragma mark Event Manager Delegate
133
142
 
134
143
  - (void)onPositionManagerCalculatedLocationWithLocation:(NSDictionary<NSString *,id> * _Nonnull)location {