Skip to content

Implement hardResetDatabase method - #2

Open
orca-nazar wants to merge 9 commits into
mainfrom
provide-offline-manager-reinit
Open

orca-nazar wants to merge 9 commits into
mainfrom
provide-offline-manager-reinit

Conversation

@orca-nazar

@orca-nazar orca-nazar commented Dec 16, 2025 •

Copy link
Copy Markdown

Description

Added hardResetDatabase that includes 2 steps:

  1. deletion database from file system;
  2. offline region manager reinitialization to use new dataPath to database .mapbox_custom. To force Mapbox recreate a new database in a new folder. Otherwise, recreation doesn't work

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements the hardResetDatabase method to provide a comprehensive reset of the Mapbox offline database. The implementation handles platform differences: iOS deletes both .mapbox/map_data and .mapbox_custom directories and reinitializes the OfflineRegionManager with a fresh custom directory, while Android simply deletes the .mapbox/map_data directory and relies on the C++ manager to auto-recreate the database.

  • Adds hardResetDatabase() method across TypeScript, iOS, and Android implementations
  • Updates iOS MapView and OfflineRegionManager initialization to support custom data path resolution
  • Implements platform-specific cleanup strategies (iOS: full reset with reinitialization, Android: directory deletion only)

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/modules/offline/offlineManagerLegacy.ts Adds hardResetDatabase() method with detailed documentation explaining platform differences
ios/RNMBX/RNMBXMapView.swift Adds data path resolution logic to prefer .mapbox_custom directories over default .mapbox/map_data
ios/RNMBX/Offline/RNMBXOfflineModuleLegacy.swift Implements hardResetDatabase() and reinitOfflineRegionManager() with custom data path resolution; updates offlineRegionManager lazy property to support custom paths
ios/RNMBX/Offline/RNMBXOfflineModuleLegacy.m Exposes hardResetDatabase method to React Native bridge
android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXOfflineModuleLegacy.kt Implements hardResetDatabase() to delete .mapbox/map_data directory on a background thread

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ios/RNMBX/RNMBXMapView.swift Resolved
@borovac

borovac commented Dec 17, 2025 •

Copy link
Copy Markdown
Member

cleanest setup:

  • offlineManager api accepts resource path as optional argument, same with mapview
  • hard reset can be performed with ts
  • flow: unmount mapview -> unmount offlinemanager -> hard reset in ts -> remount offlinemanager -> remount mapview

i think you might have mentioned that above flow doesn't work.

looking at the code, don't see why this is not possible. i'd use the same approach on both platforms.

@orca-nazar

orca-nazar commented Dec 17, 2025 •

Copy link
Copy Markdown
Author

@orca-hydromancer

cleanest setup:

  • offlineManager api accepts resource path as optional argument, same with mapview
  • hard reset can be performed with ts
  • flow: unmount mapview -> unmount offlinemanager -> hard reset in ts -> remount offlinemanager -> remount mapview

i think you might have mentioned that above flow doesn't work.

looking at the code, don't see why this is not possible. i'd use the same approach on both platforms.

Almost the same approach was tested on iOS, but it doesn’t work. “Almost” because there is no way to unmount the offline manager on the Swift side (unless you’ve found a workaround?).

We also thought this approach would work well on Android. Partially, yes: I ran several test iterations in debug with different offline data sizes (0.1–2.5 GB), and initially tested small sizes in production. No issues were noticed.

However, after testing the deletion of a 2.5 GB dataset in production, the simpler approach failed. It turned out that this approach is not reliable for larger databases.

To summarize, iOS and Android now follow the same hard reset flow, which is robust and validated for databases up to 2.5 GB.

We will run one more iteration with a 4.5 GB database, as one user attempted to update/delete approximately that amount of data.

@orca-nazar

Copy link
Copy Markdown
Author

Test result 1. Deleting ~4.6GB on iOS passed
https://drive.google.com/file/d/1gOIgAZq0YJRqhTW7BPDwI0Q0xgtvnAQ6/view?usp=sharing

@borovac

borovac commented Dec 17, 2025

Copy link
Copy Markdown
Member

“Almost” because there is no way to unmount the offline manager on the Swift side (unless you’ve found a workaround?).

offlineRegionManager = nil doesn't do the trick?

@borovac

borovac commented Dec 17, 2025

Copy link
Copy Markdown
Member

“Almost” because there is no way to unmount the offline manager on the Swift side (unless you’ve found a workaround?).

offlineRegionManager = nil doesn't do the trick?

alternative

unmount map view -> reinint offline manager -> destroy old db -> mount map view

@borovac

borovac commented Dec 17, 2025

Copy link
Copy Markdown
Member

To summarize, iOS and Android now follow the same hard reset flow, which is robust and validated for databases up to 2.5 GB.

good work. i'm happy with this. i just felt it could be cleaner.

@orca-nazar

Copy link
Copy Markdown
Author

No need anymore. Hard reset could be done fully from JS side by usign this flow

unmount map view -> destroy old db -> mount map view

@orca-nazar orca-nazar closed this Dec 19, 2025
@orca-nazar

orca-nazar commented Jul 22, 2026 •

Copy link
Copy Markdown
Author

see

This approach doesn't work anymore in mapbox 11.26.0

@orca-nazar orca-nazar reopened this Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants