import {NativeModules} from 'react-native'; import OfflineCreatePackOptions from './OfflineCreatePackOptions'; const VietmapGLOfflineManager = NativeModules.MGLOfflineModule; type OfflinePackStatus = { name: string; state: number; percentage: number; completedResourceCount: number; completedResourceSize: number; completedTileSize: number; completedTileCount: number; requiredResourceCount: number; }; class OfflinePack { private pack: OfflineCreatePackOptions; private _metadata: Record | null; constructor(pack: OfflineCreatePackOptions) { this.pack = pack; this._metadata = null; } get name(): string | null { const {metadata} = this; return metadata && metadata.name; } get bounds(): string { return this.pack.bounds; } get metadata(): Record | null { if (!this._metadata && this.pack.metadata) { this._metadata = JSON.parse(this.pack.metadata); } return this._metadata; } status(): Promise { return VietmapGLOfflineManager.getPackStatus(this.name); } resume(): Promise { return VietmapGLOfflineManager.resumePackDownload(this.name); } pause(): Promise { return VietmapGLOfflineManager.pausePackDownload(this.name); } } export default OfflinePack;