MapboxGL.offlineManager.subscribe progressListener doesn't execute if downloaded 100%
Describe the bug
Assume I'm downloading an offline pack when it's 50% I killed the app, the download will continue normally and I'm showing my users that's they still have 50% more to download so they need to resume the download. but when calling MapboxGL.offlineManager.subscribe() no callback function is called because the pack is 100% downloaded.
Expected behavior status in progressListener should be executed with status.percentage=100 .
Versions:
- Platfrom:Android
- Device: Custom Emulator
- OS: Pie
- SDK Version 28
- React Native Version 0.59
Code:
export function* resumeOfflinePackDownload(action) {
const progressListener = (offlinePack, status) => {
progressChannel.put(setOfflineDownloadProgress(action.name, Math.ceil(status.percentage)))
console.log(offlinePack, status)
}
const errorListener = (offlinePack, err) => console.log(offlinePack, err)
yield MapboxGL.offlineManager.subscribe(action.name, progressListener, errorListener)
const pack = yield MapboxGL.offlineManager.getPack(action.name)
yield pack.resume()
}
I was facing this issue myself, so was working on a fix/pull request. While working trough the code I stumbled on an undocumented method was probably meant to be used instead of getting the status using a subscriber.
const pack = await Mapbox.offlineManager.getPack(packName); // Or get the pack by name
const status = await pack.status(); // <-- Undocumented method
// You can then call progressListener yourself
progressListener(pack, status);
Not sure if you would actually want the progress listener to be called when you subscribe to a completed pack, since the subscription itself could have been avoided in that case.
Would love to know the teams opinion on this. Either way documentation needs to change.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.