Skip to content

Commit

Permalink
Expose native resetDatabase function (rnmapbox#566)
Browse files Browse the repository at this point in the history
* expose native resetDatabase function

* adding documentation for adding resetDatabase function
  • Loading branch information
entranOA authored and kristfal committed Dec 20, 2019
1 parent be07d5e commit ef7391c
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,23 @@ public void onError(String error) {
});
}

@ReactMethod
public void resetDatabase(final Promise promise) {
activateFileSource();
final OfflineManager offlineManager = OfflineManager.getInstance(mReactContext);
offlineManager.resetDatabase(new OfflineManager.FileSourceCallback() {
@Override
public void onSuccess() {
promise.resolve(null);
}

@Override
public void onError(String error) {
promise.reject("resetDatabase", error);
}
});
}

@ReactMethod
public void getPackStatus(final String name, final Promise promise) {
activateFileSource();
Expand Down
16 changes: 16 additions & 0 deletions docs/OfflineManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ await MapboxGL.offlineManager.deletePack('packName')
```


#### resetDatabase()

Deletes the existing database, which includes both the ambient cache and offline packs, then reinitializes it.

##### arguments
| Name | Type | Required | Description |
| ---- | :--: | :------: | :----------: |




```javascript
await MapboxGL.offlineManager.resetDatabase();
```


#### getPacks()

Retrieves all the current offline packs that are stored in the database.
Expand Down
14 changes: 14 additions & 0 deletions docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -5162,6 +5162,20 @@
}
}
},
{
"name": "resetDatabase",
"description": "Deletes the existing database, which includes both the ambient cache and offline packs, then reinitializes it.",
"params": [],
"examples": [
"await MapboxGL.offlineManager.resetDatabase();"
],
"returns": {
"description": "",
"type": {
"name": "void"
}
}
},
{
"name": "getPacks",
"description": "Retrieves all the current offline packs that are stored in the database.",
Expand Down
12 changes: 12 additions & 0 deletions ios/RCTMGL/MGLOfflineModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
});
}

RCT_EXPORT_METHOD(resetDatabase:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
[[MGLOfflineStorage sharedOfflineStorage] resetDatabaseWithCompletionHandler:^(NSError *error) {
if (error != nil) {
reject(@"resetDatabase", error.description, error);
return;
}
resolve(nil);
}];

}

RCT_EXPORT_METHOD(getPackStatus:(NSString *)name
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
Expand Down
13 changes: 13 additions & 0 deletions javascript/modules/offline/offlineManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ class OfflineManager {
}
}

/**
* Deletes the existing database, which includes both the ambient cache and offline packs, then reinitializes it.
*
* @example
* await MapboxGL.offlineManager.resetDatabase();
*
* @return {void}
*/
async resetDatabase() {
await this._initialize();
await MapboxGLOfflineManager.resetDatabase();
}

/**
* Retrieves all the current offline packs that are stored in the database.
*
Expand Down

0 comments on commit ef7391c

Please sign in to comment.