@maplibre/maplibre-react-native 10.0.0-alpha.20 → 10.0.0-alpha.21
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
|
@@ -6,6 +6,10 @@ PR Title ([#123](link to my pr))
|
|
|
6
6
|
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
+
## 10.0.0-alpha.21
|
|
10
|
+
|
|
11
|
+
fix: Call requestProgress when getting pack status on IOS + example improvement [#445](https://github.com/maplibre/maplibre-react-native/pull/445)
|
|
12
|
+
|
|
9
13
|
## 10.0.0-alpha.20
|
|
10
14
|
|
|
11
15
|
fix: fix style expressions, revert changes to scripts/autogenHelpers/globals.js ([#466](https://github.com/maplibre/maplibre-react-native/pull/466))
|
|
@@ -48,12 +48,12 @@ NSString *const RCT_MAPBOX_OFFLINE_CALLBACK_ERROR = @"MapboOfflineRegionError";
|
|
|
48
48
|
packRequestQueue = [NSMutableArray new];
|
|
49
49
|
eventThrottle = 300;
|
|
50
50
|
lastPackState = -1;
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
|
|
53
53
|
[defaultCenter addObserver:self selector:@selector(offlinePackProgressDidChange:) name:MLNOfflinePackProgressChangedNotification object:nil];
|
|
54
54
|
[defaultCenter addObserver:self selector:@selector(offlinePackDidReceiveError:) name:MLNOfflinePackErrorNotification object:nil];
|
|
55
55
|
[defaultCenter addObserver:self selector:@selector(offlinePackDidReceiveMaxAllowedMapboxTiles:) name:MLNOfflinePackMaximumMapboxTilesReachedNotification object:nil];
|
|
56
|
-
|
|
56
|
+
|
|
57
57
|
[[MLNOfflineStorage sharedOfflineStorage] addObserver:self forKeyPath:@"packs" options:NSKeyValueObservingOptionInitial context:NULL];
|
|
58
58
|
}
|
|
59
59
|
return self;
|
|
@@ -72,15 +72,21 @@ NSString *const RCT_MAPBOX_OFFLINE_CALLBACK_ERROR = @"MapboOfflineRegionError";
|
|
|
72
72
|
|
|
73
73
|
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
|
|
74
74
|
{
|
|
75
|
+
if ([keyPath isEqualToString:@"state"] && [object isKindOfClass:[MLNOfflinePack class]]) {
|
|
76
|
+
MLNOfflinePack* pack = (MLNOfflinePack*)object;
|
|
77
|
+
[self observerStateForPack:pack context:context];
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
75
81
|
if (packRequestQueue.count == 0) {
|
|
76
82
|
return;
|
|
77
83
|
}
|
|
78
|
-
|
|
84
|
+
|
|
79
85
|
NSArray<MLNOfflinePack *> *packs = [[MLNOfflineStorage sharedOfflineStorage] packs];
|
|
80
86
|
if (packs == nil) {
|
|
81
87
|
return;
|
|
82
88
|
}
|
|
83
|
-
|
|
89
|
+
|
|
84
90
|
while (packRequestQueue.count > 0) {
|
|
85
91
|
RCTPromiseResolveBlock resolve = [packRequestQueue objectAtIndex:0];
|
|
86
92
|
resolve([self _convertPacksToJson:packs]);
|
|
@@ -94,13 +100,13 @@ RCT_EXPORT_METHOD(createPack:(NSDictionary *)options
|
|
|
94
100
|
{
|
|
95
101
|
NSString *styleURL = options[@"styleURL"];
|
|
96
102
|
MLNCoordinateBounds bounds = [RCTMLNUtils fromFeatureCollection:options[@"bounds"]];
|
|
97
|
-
|
|
103
|
+
|
|
98
104
|
id<MLNOfflineRegion> offlineRegion = [[MLNTilePyramidOfflineRegion alloc] initWithStyleURL:[NSURL URLWithString:styleURL]
|
|
99
105
|
bounds:bounds
|
|
100
106
|
fromZoomLevel:[options[@"minZoom"] doubleValue]
|
|
101
107
|
toZoomLevel:[options[@"maxZoom"] doubleValue]];
|
|
102
108
|
NSData *context = [self _archiveMetadata:options[@"metadata"]];
|
|
103
|
-
|
|
109
|
+
|
|
104
110
|
[[MLNOfflineStorage sharedOfflineStorage] addPackForRegion:offlineRegion
|
|
105
111
|
withContext:context
|
|
106
112
|
completionHandler:^(MLNOfflinePack *pack, NSError *error) {
|
|
@@ -129,7 +135,7 @@ RCT_EXPORT_METHOD(mergeOfflineRegions:(NSString *)path
|
|
|
129
135
|
return reject(@"asset_does_not_exist", [NSString stringWithFormat:@"The given assetName, %@, can't be found in the app's bundle.", path], nil);
|
|
130
136
|
}
|
|
131
137
|
}
|
|
132
|
-
|
|
138
|
+
|
|
133
139
|
[[MLNOfflineStorage sharedOfflineStorage] addContentsOfFile:absolutePath withCompletionHandler:^(NSURL *fileURL, NSArray<MLNOfflinePack *> *packs, NSError *error) {
|
|
134
140
|
if (error != nil) {
|
|
135
141
|
reject(@"mergeOfflineRegions", error.description, error);
|
|
@@ -143,7 +149,7 @@ RCT_EXPORT_METHOD(getPacks:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseR
|
|
|
143
149
|
{
|
|
144
150
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
145
151
|
NSArray<MLNOfflinePack *> *packs = [[MLNOfflineStorage sharedOfflineStorage] packs];
|
|
146
|
-
|
|
152
|
+
|
|
147
153
|
if (packs == nil) {
|
|
148
154
|
// packs have not loaded yet
|
|
149
155
|
[self->packRequestQueue addObject:resolve];
|
|
@@ -187,7 +193,7 @@ RCT_EXPORT_METHOD(setMaximumAmbientCacheSize:(NSUInteger)cacheSize
|
|
|
187
193
|
}
|
|
188
194
|
resolve(nil);
|
|
189
195
|
}];
|
|
190
|
-
|
|
196
|
+
|
|
191
197
|
}
|
|
192
198
|
|
|
193
199
|
RCT_EXPORT_METHOD(resetDatabase:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
@@ -199,7 +205,7 @@ RCT_EXPORT_METHOD(resetDatabase:(RCTPromiseResolveBlock)resolve rejecter:(RCTPro
|
|
|
199
205
|
}
|
|
200
206
|
resolve(nil);
|
|
201
207
|
}];
|
|
202
|
-
|
|
208
|
+
|
|
203
209
|
}
|
|
204
210
|
|
|
205
211
|
RCT_EXPORT_METHOD(getPackStatus:(NSString *)name
|
|
@@ -207,14 +213,29 @@ RCT_EXPORT_METHOD(getPackStatus:(NSString *)name
|
|
|
207
213
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
208
214
|
{
|
|
209
215
|
MLNOfflinePack *pack = [self _getPackFromName:name];
|
|
210
|
-
|
|
216
|
+
|
|
211
217
|
if (pack == nil) {
|
|
212
218
|
resolve(nil);
|
|
213
219
|
NSLog(@"getPackStatus - Unknown offline region");
|
|
214
220
|
return;
|
|
215
221
|
}
|
|
216
|
-
|
|
217
|
-
|
|
222
|
+
|
|
223
|
+
if (pack.state == MLNOfflinePackStateUnknown) {
|
|
224
|
+
[pack addObserver:self forKeyPath:@"state" options:NSKeyValueObservingOptionNew context:(__bridge_retained void*)resolve];
|
|
225
|
+
[pack requestProgress];
|
|
226
|
+
} else {
|
|
227
|
+
resolve([self _makeRegionStatusPayload:name pack:pack]);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
-(void)observerStateForPack:(MLNOfflinePack*)pack context:(nullable void*) context {
|
|
232
|
+
RCTPromiseResolveBlock resolve = (__bridge_transfer RCTPromiseResolveBlock)context;
|
|
233
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
234
|
+
NSDictionary* metadata = [self _unarchiveMetadata:pack];
|
|
235
|
+
NSString* name = metadata[@"name"];
|
|
236
|
+
resolve([self _makeRegionStatusPayload:name pack:pack]);
|
|
237
|
+
});
|
|
238
|
+
[pack removeObserver:self forKeyPath:@"state" context:context];
|
|
218
239
|
}
|
|
219
240
|
|
|
220
241
|
RCT_EXPORT_METHOD(invalidatePack:(NSString *)name
|
|
@@ -241,7 +262,7 @@ RCT_EXPORT_METHOD(deletePack:(NSString *)name
|
|
|
241
262
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
242
263
|
{
|
|
243
264
|
MLNOfflinePack *pack = [self _getPackFromName:name];
|
|
244
|
-
|
|
265
|
+
|
|
245
266
|
if (pack == nil) {
|
|
246
267
|
resolve(nil);
|
|
247
268
|
return;
|
|
@@ -265,17 +286,17 @@ RCT_EXPORT_METHOD(pausePackDownload:(NSString *)name
|
|
|
265
286
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
266
287
|
{
|
|
267
288
|
MLNOfflinePack *pack = [self _getPackFromName:name];
|
|
268
|
-
|
|
289
|
+
|
|
269
290
|
if (pack == nil) {
|
|
270
291
|
reject(@"pausePackDownload", @"Unknown offline region", nil);
|
|
271
292
|
return;
|
|
272
293
|
}
|
|
273
|
-
|
|
294
|
+
|
|
274
295
|
if (pack.state == MLNOfflinePackStateInactive || pack.state == MLNOfflinePackStateComplete) {
|
|
275
296
|
resolve(nil);
|
|
276
297
|
return;
|
|
277
298
|
}
|
|
278
|
-
|
|
299
|
+
|
|
279
300
|
[pack suspend];
|
|
280
301
|
resolve(nil);
|
|
281
302
|
}
|
|
@@ -285,17 +306,17 @@ RCT_EXPORT_METHOD(resumePackDownload:(NSString *)name
|
|
|
285
306
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
286
307
|
{
|
|
287
308
|
MLNOfflinePack *pack = [self _getPackFromName:name];
|
|
288
|
-
|
|
309
|
+
|
|
289
310
|
if (pack == nil) {
|
|
290
311
|
reject(@"resumePack", @"Unknown offline region", nil);
|
|
291
312
|
return;
|
|
292
313
|
}
|
|
293
|
-
|
|
314
|
+
|
|
294
315
|
if (pack.state == MLNOfflinePackStateActive || pack.state == MLNOfflinePackStateComplete) {
|
|
295
316
|
resolve(nil);
|
|
296
317
|
return;
|
|
297
318
|
}
|
|
298
|
-
|
|
319
|
+
|
|
299
320
|
[pack resume];
|
|
300
321
|
resolve(nil);
|
|
301
322
|
}
|
|
@@ -313,18 +334,18 @@ RCT_EXPORT_METHOD(setProgressEventThrottle:(nonnull NSNumber *)throttleValue)
|
|
|
313
334
|
- (void)offlinePackProgressDidChange:(NSNotification *)notification
|
|
314
335
|
{
|
|
315
336
|
MLNOfflinePack *pack = notification.object;
|
|
316
|
-
|
|
337
|
+
|
|
317
338
|
if (pack.state == MLNOfflinePackStateInvalid) {
|
|
318
339
|
return; // Avoid invalid offline pack exception
|
|
319
340
|
}
|
|
320
|
-
|
|
341
|
+
|
|
321
342
|
if ([self _shouldSendProgressEvent:[self _getCurrentTimestamp] pack:pack]) {
|
|
322
343
|
NSDictionary *metadata = [self _unarchiveMetadata:pack];
|
|
323
344
|
RCTMLNEvent *event = [self _makeProgressEvent:metadata[@"name"] pack:pack];
|
|
324
345
|
[self _sendEvent:RCT_MAPBOX_OFFLINE_CALLBACK_PROGRESS event:event];
|
|
325
346
|
lastPackTimestamp = [self _getCurrentTimestamp];
|
|
326
347
|
}
|
|
327
|
-
|
|
348
|
+
|
|
328
349
|
lastPackState = pack.state;
|
|
329
350
|
}
|
|
330
351
|
|
|
@@ -335,7 +356,7 @@ RCT_EXPORT_METHOD(setProgressEventThrottle:(nonnull NSNumber *)throttleValue)
|
|
|
335
356
|
return; // Avoid invalid offline pack exception
|
|
336
357
|
}
|
|
337
358
|
NSDictionary *metadata = [self _unarchiveMetadata:pack];
|
|
338
|
-
|
|
359
|
+
|
|
339
360
|
NSString *name = metadata[@"name"];
|
|
340
361
|
if (name != nil) {
|
|
341
362
|
NSError *error = notification.userInfo[MLNOfflinePackUserInfoKeyError];
|
|
@@ -350,7 +371,7 @@ RCT_EXPORT_METHOD(setProgressEventThrottle:(nonnull NSNumber *)throttleValue)
|
|
|
350
371
|
{
|
|
351
372
|
MLNOfflinePack *pack = notification.object;
|
|
352
373
|
NSDictionary *metadata = [self _unarchiveMetadata:pack];
|
|
353
|
-
|
|
374
|
+
|
|
354
375
|
NSString *name = metadata[@"name"];
|
|
355
376
|
if (name != nil) {
|
|
356
377
|
RCTMLNEvent *event = [self _makeErrorEvent:name
|
|
@@ -386,11 +407,11 @@ RCT_EXPORT_METHOD(setProgressEventThrottle:(nonnull NSNumber *)throttleValue)
|
|
|
386
407
|
if ([data isKindOfClass:[NSDictionary class]]) {
|
|
387
408
|
return data;
|
|
388
409
|
}
|
|
389
|
-
|
|
410
|
+
|
|
390
411
|
if (data == nil) {
|
|
391
412
|
return @{};
|
|
392
413
|
}
|
|
393
|
-
|
|
414
|
+
|
|
394
415
|
return [NSJSONSerialization JSONObjectWithData:[data dataUsingEncoding:NSUTF8StringEncoding]
|
|
395
416
|
options:NSJSONReadingMutableContainers
|
|
396
417
|
error:nil];
|
|
@@ -406,7 +427,7 @@ RCT_EXPORT_METHOD(setProgressEventThrottle:(nonnull NSNumber *)throttleValue)
|
|
|
406
427
|
if(expectedResources == 0) {
|
|
407
428
|
progressPercentage = 0;
|
|
408
429
|
}
|
|
409
|
-
|
|
430
|
+
|
|
410
431
|
return @{
|
|
411
432
|
@"state": @(pack.state),
|
|
412
433
|
@"name": name,
|
|
@@ -433,15 +454,15 @@ RCT_EXPORT_METHOD(setProgressEventThrottle:(nonnull NSNumber *)throttleValue)
|
|
|
433
454
|
- (NSArray<NSDictionary *> *)_convertPacksToJson:(NSArray<MLNOfflinePack *> *)packs
|
|
434
455
|
{
|
|
435
456
|
NSMutableArray<NSDictionary *> *jsonPacks = [NSMutableArray new];
|
|
436
|
-
|
|
457
|
+
|
|
437
458
|
if (packs == nil) {
|
|
438
459
|
return jsonPacks;
|
|
439
460
|
}
|
|
440
|
-
|
|
461
|
+
|
|
441
462
|
for (MLNOfflinePack *pack in packs) {
|
|
442
463
|
[jsonPacks addObject:[self _convertPackToDict:pack]];
|
|
443
464
|
}
|
|
444
|
-
|
|
465
|
+
|
|
445
466
|
return jsonPacks;
|
|
446
467
|
}
|
|
447
468
|
|
|
@@ -452,12 +473,12 @@ RCT_EXPORT_METHOD(setProgressEventThrottle:(nonnull NSNumber *)throttleValue)
|
|
|
452
473
|
if (region == nil) {
|
|
453
474
|
return nil;
|
|
454
475
|
}
|
|
455
|
-
|
|
476
|
+
|
|
456
477
|
NSArray *jsonBounds = @[
|
|
457
478
|
@[@(region.bounds.ne.longitude), @(region.bounds.ne.latitude)],
|
|
458
479
|
@[@(region.bounds.sw.longitude), @(region.bounds.sw.latitude)]
|
|
459
480
|
];
|
|
460
|
-
|
|
481
|
+
|
|
461
482
|
// format metadata
|
|
462
483
|
NSDictionary *metadata = [self _unarchiveMetadata:pack];
|
|
463
484
|
NSData *jsonMetadata = [NSJSONSerialization dataWithJSONObject:metadata
|
|
@@ -472,19 +493,19 @@ RCT_EXPORT_METHOD(setProgressEventThrottle:(nonnull NSNumber *)throttleValue)
|
|
|
472
493
|
- (MLNOfflinePack *)_getPackFromName:(NSString *)name
|
|
473
494
|
{
|
|
474
495
|
NSArray<MLNOfflinePack *> *packs = [[MLNOfflineStorage sharedOfflineStorage] packs];
|
|
475
|
-
|
|
496
|
+
|
|
476
497
|
if (packs == nil) {
|
|
477
498
|
return nil;
|
|
478
499
|
}
|
|
479
|
-
|
|
500
|
+
|
|
480
501
|
for (MLNOfflinePack *pack in packs) {
|
|
481
502
|
NSDictionary *metadata = [self _unarchiveMetadata:pack];
|
|
482
|
-
|
|
503
|
+
|
|
483
504
|
if ([name isEqualToString:metadata[@"name"]]) {
|
|
484
505
|
return pack;
|
|
485
506
|
}
|
|
486
507
|
}
|
|
487
|
-
|
|
508
|
+
|
|
488
509
|
return nil;
|
|
489
510
|
}
|
|
490
511
|
|
|
@@ -501,15 +522,15 @@ RCT_EXPORT_METHOD(setProgressEventThrottle:(nonnull NSNumber *)throttleValue)
|
|
|
501
522
|
if (lastPackState == -1) {
|
|
502
523
|
return YES;
|
|
503
524
|
}
|
|
504
|
-
|
|
525
|
+
|
|
505
526
|
if (lastPackState != currentPack.state) {
|
|
506
527
|
return YES;
|
|
507
528
|
}
|
|
508
|
-
|
|
529
|
+
|
|
509
530
|
if (currentTimestamp - lastPackTimestamp > eventThrottle) {
|
|
510
531
|
return YES;
|
|
511
532
|
}
|
|
512
|
-
|
|
533
|
+
|
|
513
534
|
return NO;
|
|
514
535
|
}
|
|
515
536
|
|
package/javascript/Maplibre.ts
CHANGED
|
@@ -40,6 +40,12 @@ export {
|
|
|
40
40
|
type Location,
|
|
41
41
|
} from "./modules/location/locationManager";
|
|
42
42
|
export { default as offlineManager } from "./modules/offline/offlineManager";
|
|
43
|
+
export type {
|
|
44
|
+
OfflineProgressStatus,
|
|
45
|
+
OfflinePackError,
|
|
46
|
+
} from "./modules/offline/offlineManager";
|
|
47
|
+
export type { OfflinePackStatus } from "./modules/offline/OfflinePack";
|
|
48
|
+
export { default as OfflinePack } from "./modules/offline/OfflinePack";
|
|
43
49
|
export { default as OfflineCreatePackOptions } from "./modules/offline/OfflineCreatePackOptions";
|
|
44
50
|
export { default as snapshotManager } from "./modules/snapshot/snapshotManager";
|
|
45
51
|
export type { SnapshotInputOptions } from "./modules/snapshot/SnapshotOptions";
|
package/package.json
CHANGED
package/tsconfig.json
CHANGED