import { NativeModules } from 'react-native'; interface RNMBXModule { StyleURL: { Street: URL; Outdoors: URL; Light: URL; Dark: URL; Satellite: URL; SatelliteStreet: URL; }; OfflinePackDownloadState: { Inactive: string | number; Active: string | number; Complete: string | number; Unknown?: string | number; }; LineJoin: { Bevel: string | number; Round: string | number; Miter: string | number; }; StyleSource: { DefaultSourceID: string; }; TileServers: { Mapbox: string; }; removeCustomHeader(headerName: string): void; addCustomHeader(headerName: string, headerValue: string): void; addCustomHeaderWithOptions( headerName: string, headerValue: string, options: { urlRegexp?: string }, ): void; setAccessToken(accessToken: string | null): Promise; setWellKnownTileServer(tileServer: string): void; clearData(): Promise; getAccessToken(): Promise; setTelemetryEnabled(telemetryEnabled: boolean): void; setConnected(connected: boolean): void; } const RNMBXModule: RNMBXModule = NativeModules.RNMBXModule; if (NativeModules.RNMBXModule == null) { if ((global as { expo?: unknown }).expo != null) { // global.expo.modules.ExponentConstants; throw new Error( '@rnmapbox/maps native code not available. Make sure you have linked the library and rebuild your app. See https://rnmapbox.github.io/docs/install?rebuild=expo#rebuild', ); } else { throw new Error( '@rnmapbox/maps native code not available. Make sure you have linked the library and rebuild your app. See https://rnmapbox.github.io/docs/install', ); } } /** * Add a custom header to HTTP requests. * @param headerName - The name of the header * @param headerValue - The value of the header * @param options - Optional configuration. If provided with urlRegexp, the header will only be added to URLs matching the regex */ function addCustomHeader( headerName: string, headerValue: string, options?: { urlRegexp?: string }, ): void { if (options) { RNMBXModule.addCustomHeaderWithOptions(headerName, headerValue, options); } else { RNMBXModule.addCustomHeader(headerName, headerValue); } } export const { StyleURL, OfflinePackDownloadState, LineJoin, StyleSource, TileServers, removeCustomHeader, setAccessToken, setWellKnownTileServer, clearData, getAccessToken, setTelemetryEnabled, setConnected, } = RNMBXModule; export { addCustomHeader };