@maplibre/maplibre-react-native 11.0.0-alpha.17 → 11.0.0-alpha.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/android/src/main/java/org/maplibre/reactnative/MLRNPackage.kt +6 -6
  2. package/android/src/main/java/org/maplibre/reactnative/modules/MLRNLocationModule.kt +5 -0
  3. package/android/src/main/java/org/maplibre/reactnative/modules/MLRNLogModule.kt +99 -0
  4. package/ios/modules/location/MLRNLocationManager.h +2 -2
  5. package/ios/modules/location/MLRNLocationManager.m +38 -25
  6. package/ios/modules/location/MLRNLocationModule.mm +11 -0
  7. package/ios/modules/logging/MLRNLogModule.h +10 -0
  8. package/ios/modules/logging/MLRNLogModule.mm +39 -0
  9. package/ios/modules/logging/MLRNLogging.h +15 -2
  10. package/ios/modules/logging/MLRNLogging.m +22 -55
  11. package/lib/commonjs/components/map-view/MapView.js +3 -3
  12. package/lib/commonjs/components/map-view/MapView.js.map +1 -1
  13. package/lib/commonjs/index.js +4 -4
  14. package/lib/commonjs/index.js.map +1 -1
  15. package/lib/commonjs/modules/location/LocationManager.js +22 -4
  16. package/lib/commonjs/modules/location/LocationManager.js.map +1 -1
  17. package/lib/commonjs/modules/location/NativeLocationModule.js.map +1 -1
  18. package/lib/commonjs/modules/log/LogManager.js +99 -0
  19. package/lib/commonjs/modules/log/LogManager.js.map +1 -0
  20. package/lib/commonjs/modules/log/NativeLogModule.js +9 -0
  21. package/lib/commonjs/modules/log/NativeLogModule.js.map +1 -0
  22. package/lib/module/components/map-view/MapView.js +3 -3
  23. package/lib/module/components/map-view/MapView.js.map +1 -1
  24. package/lib/module/index.js +1 -1
  25. package/lib/module/index.js.map +1 -1
  26. package/lib/module/modules/location/LocationManager.js +23 -5
  27. package/lib/module/modules/location/LocationManager.js.map +1 -1
  28. package/lib/module/modules/location/NativeLocationModule.js.map +1 -1
  29. package/lib/module/modules/log/LogManager.js +96 -0
  30. package/lib/module/modules/log/LogManager.js.map +1 -0
  31. package/lib/module/modules/log/NativeLogModule.js +5 -0
  32. package/lib/module/modules/log/NativeLogModule.js.map +1 -0
  33. package/lib/typescript/commonjs/src/index.d.ts +1 -1
  34. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  35. package/lib/typescript/commonjs/src/modules/location/LocationManager.d.ts +10 -1
  36. package/lib/typescript/commonjs/src/modules/location/LocationManager.d.ts.map +1 -1
  37. package/lib/typescript/commonjs/src/modules/location/NativeLocationModule.d.ts +1 -0
  38. package/lib/typescript/commonjs/src/modules/location/NativeLocationModule.d.ts.map +1 -1
  39. package/lib/typescript/commonjs/src/modules/log/LogManager.d.ts +45 -0
  40. package/lib/typescript/commonjs/src/modules/log/LogManager.d.ts.map +1 -0
  41. package/lib/typescript/commonjs/src/modules/log/NativeLogModule.d.ts +13 -0
  42. package/lib/typescript/commonjs/src/modules/log/NativeLogModule.d.ts.map +1 -0
  43. package/lib/typescript/module/src/index.d.ts +1 -1
  44. package/lib/typescript/module/src/index.d.ts.map +1 -1
  45. package/lib/typescript/module/src/modules/location/LocationManager.d.ts +10 -1
  46. package/lib/typescript/module/src/modules/location/LocationManager.d.ts.map +1 -1
  47. package/lib/typescript/module/src/modules/location/NativeLocationModule.d.ts +1 -0
  48. package/lib/typescript/module/src/modules/location/NativeLocationModule.d.ts.map +1 -1
  49. package/lib/typescript/module/src/modules/log/LogManager.d.ts +45 -0
  50. package/lib/typescript/module/src/modules/log/LogManager.d.ts.map +1 -0
  51. package/lib/typescript/module/src/modules/log/NativeLogModule.d.ts +13 -0
  52. package/lib/typescript/module/src/modules/log/NativeLogModule.d.ts.map +1 -0
  53. package/package.json +2 -1
  54. package/src/components/map-view/MapView.tsx +3 -3
  55. package/src/index.ts +1 -1
  56. package/src/modules/location/LocationManager.ts +23 -4
  57. package/src/modules/location/NativeLocationModule.ts +2 -0
  58. package/src/modules/log/LogManager.ts +114 -0
  59. package/src/modules/log/NativeLogModule.ts +16 -0
  60. package/android/src/main/java/org/maplibre/reactnative/modules/MLRNLogging.java +0 -140
  61. package/lib/commonjs/modules/Logger.js +0 -112
  62. package/lib/commonjs/modules/Logger.js.map +0 -1
  63. package/lib/module/modules/Logger.js +0 -107
  64. package/lib/module/modules/Logger.js.map +0 -1
  65. package/lib/typescript/commonjs/src/modules/Logger.d.ts +0 -49
  66. package/lib/typescript/commonjs/src/modules/Logger.d.ts.map +0 -1
  67. package/lib/typescript/module/src/modules/Logger.d.ts +0 -49
  68. package/lib/typescript/module/src/modules/Logger.d.ts.map +0 -1
  69. package/src/modules/Logger.ts +0 -127
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Log levels in decreasing order of severity
3
+ */
4
+ export type LogLevel = "error" | "warn" | "info" | "debug" | "verbose";
5
+ interface LogEvent {
6
+ level: LogLevel;
7
+ tag: string;
8
+ message: string;
9
+ }
10
+ /**
11
+ * Handler for `onLog` events
12
+ *
13
+ * Called before logging a message, return false to proceed with default logging.
14
+ *
15
+ * @param event
16
+ */
17
+ type LogHandler = (event: LogEvent) => boolean;
18
+ declare class LogManager {
19
+ private logLevel;
20
+ private startedCount;
21
+ private logHandler;
22
+ private subscription;
23
+ constructor();
24
+ /**
25
+ * Override logging behavior
26
+ *
27
+ * @param logHandler
28
+ */
29
+ onLog(logHandler: LogHandler): void;
30
+ /**
31
+ * Set the minimum log level for a message to be logged
32
+ *
33
+ * @param level Minimum log level
34
+ */
35
+ setLogLevel(level: LogLevel): void;
36
+ start(): void;
37
+ stop(): void;
38
+ private subscribe;
39
+ private unsubscribe;
40
+ private effectiveLevel;
41
+ private handleLog;
42
+ }
43
+ declare const logManager: LogManager;
44
+ export { logManager as LogManager };
45
+ //# sourceMappingURL=LogManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LogManager.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/log/LogManager.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;AAEvE,UAAU,QAAQ;IAChB,KAAK,EAAE,QAAQ,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;GAMG;AACH,KAAK,UAAU,GAAG,CAAC,KAAK,EAAE,QAAQ,KAAK,OAAO,CAAC;AAE/C,cAAM,UAAU;IACd,OAAO,CAAC,QAAQ,CAAoB;IACpC,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,UAAU,CAAqC;IACvD,OAAO,CAAC,YAAY,CAA4C;;IAMhE;;;;OAIG;IACH,KAAK,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAInC;;;;OAIG;IACH,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAKlC,KAAK,IAAI,IAAI;IAQb,IAAI,IAAI,IAAI;IAQZ,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,WAAW;IAOnB,OAAO,CAAC,cAAc;IAatB,OAAO,CAAC,SAAS;CAgBlB;AAED,QAAA,MAAM,UAAU,YAAmB,CAAC;AAEpC,OAAO,EAAE,UAAU,IAAI,UAAU,EAAE,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { TurboModule, CodegenTypes } from "react-native";
2
+ type NativeLogLevel = "error" | "warn" | "info" | "debug" | "verbose";
3
+ export interface Spec extends TurboModule {
4
+ setLogLevel(logLevel: NativeLogLevel): void;
5
+ readonly onLog: CodegenTypes.EventEmitter<{
6
+ level: NativeLogLevel;
7
+ tag: string;
8
+ message: string;
9
+ }>;
10
+ }
11
+ declare const _default: Spec;
12
+ export default _default;
13
+ //# sourceMappingURL=NativeLogModule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeLogModule.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/log/NativeLogModule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG9D,KAAK,cAAc,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;AAEtE,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,WAAW,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI,CAAC;IAE5C,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC,YAAY,CAAC;QACxC,KAAK,EAAE,cAAc,CAAC;QACtB,GAAG,EAAE,MAAM,CAAC;QACZ,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC,CAAC;CACJ;;AAED,wBAAuE"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@maplibre/maplibre-react-native",
3
3
  "description": "React Native library for creating maps with MapLibre Native for Android & iOS",
4
- "version": "11.0.0-alpha.17",
4
+ "version": "11.0.0-alpha.19",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "provenance": true
@@ -134,6 +134,7 @@
134
134
  "modulesProvider": {
135
135
  "MLRNCameraModule": "MLRNCameraModule",
136
136
  "MLRNLocationModule": "MLRNLocationModule",
137
+ "MLRNLogModule": "MLRNLogModule",
137
138
  "MLRNMapViewModule": "MLRNMapViewModule"
138
139
  }
139
140
  }
@@ -27,7 +27,7 @@ import MapViewNativeComponent, {
27
27
  type NativeProps,
28
28
  } from "./MapViewNativeComponent";
29
29
  import NativeMapViewModule from "./NativeMapViewModule";
30
- import { Logger } from "../../modules/Logger";
30
+ import { LogManager } from "../../modules/log/LogManager";
31
31
  import { type BaseProps } from "../../types/BaseProps";
32
32
  import type { Bounds } from "../../types/Bounds";
33
33
  import {
@@ -547,10 +547,10 @@ export const MapView = memo(
547
547
 
548
548
  // Start before rendering
549
549
  useLayoutEffect(() => {
550
- Logger.sharedInstance().start();
550
+ LogManager.start();
551
551
 
552
552
  return () => {
553
- Logger.sharedInstance().stop();
553
+ LogManager.stop();
554
554
  };
555
555
  }, []);
556
556
 
package/src/index.ts CHANGED
@@ -80,6 +80,6 @@ export type { PressEvent, PressEventWithFeatures } from "./types/PressEvent";
80
80
  export type { ViewPadding } from "./types/ViewPadding";
81
81
 
82
82
  export { Animated } from "./utils/animated/Animated";
83
- export { Logger, type LogLevel } from "./modules/Logger";
83
+ export { LogManager, type LogLevel } from "./modules/log/LogManager";
84
84
 
85
85
  export type { MapLibrePluginProps } from "./plugin/MapLibrePluginProps";
@@ -2,10 +2,10 @@ import {
2
2
  type EventSubscription,
3
3
  type Permission,
4
4
  PermissionsAndroid,
5
+ Platform,
5
6
  } from "react-native";
6
7
 
7
8
  import NativeLocationModule from "./NativeLocationModule";
8
- import { isAndroid } from "../../utils";
9
9
 
10
10
  interface GeolocationCoordinates {
11
11
  /**
@@ -135,8 +135,17 @@ class LocationManager {
135
135
  this.listeners.forEach((listener) => listener(location));
136
136
  }
137
137
 
138
- async requestAndroidPermissions(): Promise<boolean> {
139
- if (isAndroid()) {
138
+ /**
139
+ * Request location permissions
140
+ *
141
+ * Requests the following:
142
+ * - Android: `ACCESS_FINE_LOCATION`, `ACCESS_COARSE_LOCATION`
143
+ * - iOS: `requestWhenInUseAuthorization`
144
+ *
145
+ * @returns Promise resolves to true if permissions were granted, false otherwise
146
+ */
147
+ async requestPermissions(): Promise<boolean> {
148
+ if (Platform.OS === "android") {
140
149
  const res = await PermissionsAndroid.requestMultiple([
141
150
  PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION as Permission,
142
151
  PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION as Permission,
@@ -147,7 +156,17 @@ class LocationManager {
147
156
  );
148
157
  }
149
158
 
150
- throw new Error("This method should only be called on Android");
159
+ if (Platform.OS === "ios") {
160
+ try {
161
+ await NativeLocationModule.requestPermissions();
162
+ return true;
163
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
164
+ } catch (_error) {
165
+ return false;
166
+ }
167
+ }
168
+
169
+ return false;
151
170
  }
152
171
  }
153
172
 
@@ -25,6 +25,8 @@ export interface Spec extends TurboModule {
25
25
 
26
26
  setMinDisplacement(minDisplacement: number): void;
27
27
 
28
+ requestPermissions(): Promise<void>;
29
+
28
30
  readonly onUpdate: CodegenTypes.EventEmitter<NativeGeolocationPosition>;
29
31
  }
30
32
 
@@ -0,0 +1,114 @@
1
+ import { type EventSubscription } from "react-native";
2
+
3
+ import NativeLogModule from "./NativeLogModule";
4
+
5
+ /**
6
+ * Log levels in decreasing order of severity
7
+ */
8
+ export type LogLevel = "error" | "warn" | "info" | "debug" | "verbose";
9
+
10
+ interface LogEvent {
11
+ level: LogLevel;
12
+ tag: string;
13
+ message: string;
14
+ }
15
+
16
+ /**
17
+ * Handler for `onLog` events
18
+ *
19
+ * Called before logging a message, return false to proceed with default logging.
20
+ *
21
+ * @param event
22
+ */
23
+ type LogHandler = (event: LogEvent) => boolean;
24
+
25
+ class LogManager {
26
+ private logLevel: LogLevel = "warn";
27
+ private startedCount: number = 0;
28
+ private logHandler: LogHandler | undefined = undefined;
29
+ private subscription: EventSubscription | undefined = undefined;
30
+
31
+ constructor() {
32
+ this.handleLog = this.handleLog.bind(this);
33
+ }
34
+
35
+ /**
36
+ * Override logging behavior
37
+ *
38
+ * @param logHandler
39
+ */
40
+ onLog(logHandler: LogHandler): void {
41
+ this.logHandler = logHandler;
42
+ }
43
+
44
+ /**
45
+ * Set the minimum log level for a message to be logged
46
+ *
47
+ * @param level Minimum log level
48
+ */
49
+ setLogLevel(level: LogLevel): void {
50
+ this.logLevel = level;
51
+ NativeLogModule.setLogLevel(level);
52
+ }
53
+
54
+ start(): void {
55
+ if (this.startedCount === 0) {
56
+ this.subscribe();
57
+ }
58
+
59
+ this.startedCount += 1;
60
+ }
61
+
62
+ stop(): void {
63
+ this.startedCount -= 1;
64
+
65
+ if (this.startedCount === 0) {
66
+ this.unsubscribe();
67
+ }
68
+ }
69
+
70
+ private subscribe(): void {
71
+ this.subscription = NativeLogModule.onLog(this.handleLog);
72
+ }
73
+
74
+ private unsubscribe(): void {
75
+ if (this.subscription) {
76
+ this.subscription.remove();
77
+ this.subscription = undefined;
78
+ }
79
+ }
80
+
81
+ private effectiveLevel({ level, message, tag }: LogEvent): LogLevel {
82
+ // Reduce level of cancelled HTTP requests from warn to info
83
+ if (
84
+ level === "warn" &&
85
+ tag === "Mbgl-HttpRequest" &&
86
+ message.startsWith("Request failed due to a permanent error: Canceled")
87
+ ) {
88
+ return "info";
89
+ }
90
+
91
+ return level;
92
+ }
93
+
94
+ private handleLog(log: LogEvent): void {
95
+ if (!this.logHandler || !this.logHandler(log)) {
96
+ const { message, tag } = log;
97
+ const level = this.effectiveLevel(log);
98
+
99
+ const consoleMessage = `MapLibre Native [${level.toUpperCase()}] [${tag}] ${message}`;
100
+
101
+ if (level === "error") {
102
+ console.error(consoleMessage);
103
+ } else if (level === "warn" && this.logLevel !== "error") {
104
+ console.warn(consoleMessage);
105
+ } else if (this.logLevel !== "error" && this.logLevel !== "warn") {
106
+ console.info(consoleMessage);
107
+ }
108
+ }
109
+ }
110
+ }
111
+
112
+ const logManager = new LogManager();
113
+
114
+ export { logManager as LogManager };
@@ -0,0 +1,16 @@
1
+ import type { TurboModule, CodegenTypes } from "react-native";
2
+ import { TurboModuleRegistry } from "react-native";
3
+
4
+ type NativeLogLevel = "error" | "warn" | "info" | "debug" | "verbose";
5
+
6
+ export interface Spec extends TurboModule {
7
+ setLogLevel(logLevel: NativeLogLevel): void;
8
+
9
+ readonly onLog: CodegenTypes.EventEmitter<{
10
+ level: NativeLogLevel;
11
+ tag: string;
12
+ message: string;
13
+ }>;
14
+ }
15
+
16
+ export default TurboModuleRegistry.getEnforcing<Spec>("MLRNLogModule");
@@ -1,140 +0,0 @@
1
- package org.maplibre.reactnative.modules;
2
-
3
- import com.facebook.react.bridge.Arguments;
4
- import com.facebook.react.bridge.ReactApplicationContext;
5
- import com.facebook.react.bridge.ReactContextBaseJavaModule;
6
- import com.facebook.react.bridge.ReactMethod;
7
- import com.facebook.react.bridge.WritableMap;
8
- import com.facebook.react.module.annotations.ReactModule;
9
- import com.facebook.react.modules.core.DeviceEventManagerModule;
10
- import org.maplibre.android.log.Logger;
11
- import org.maplibre.android.log.LoggerDefinition;
12
- import android.util.Log;
13
-
14
- @ReactModule(name = MLRNLogging.REACT_CLASS)
15
- public class MLRNLogging extends ReactContextBaseJavaModule {
16
- public static final String REACT_CLASS = "MLRNLogging";
17
- private ReactApplicationContext mReactContext;
18
-
19
- public MLRNLogging(ReactApplicationContext reactApplicationContext) {
20
- super(reactApplicationContext);
21
- mReactContext = reactApplicationContext;
22
-
23
- Logger.setVerbosity(Logger.WARN);
24
- Logger.setLoggerDefinition(new LoggerDefinition() {
25
- @Override
26
- public void v(String tag, String msg) {
27
- Log.v(tag, msg);
28
- onLog("verbose", tag, msg, null);
29
- }
30
-
31
- @Override
32
- public void v(String tag, String msg, Throwable tr) {
33
- Log.v(tag, msg, tr);
34
- onLog("verbose", tag, msg, tr);
35
- }
36
-
37
- @Override
38
- public void d(String tag, String msg) {
39
- Log.d(tag, msg);
40
- onLog("debug", tag, msg, null);
41
- }
42
-
43
- @Override
44
- public void d(String tag, String msg, Throwable tr) {
45
- Log.d(tag, msg, tr);
46
- onLog("debug",tag,msg,tr);
47
- }
48
-
49
- @Override
50
- public void i(String tag, String msg) {
51
- Log.i(tag, msg);
52
- onLog("info", tag, msg, null);
53
- }
54
-
55
- @Override
56
- public void i(String tag, String msg, Throwable tr) {
57
- Log.i(tag, msg, tr);
58
- onLog("info", tag, msg, tr);
59
- }
60
-
61
- @Override
62
- public void w(String tag, String msg) {
63
- Log.w(tag, msg);
64
- onLog("warning", tag, msg, null);
65
- }
66
-
67
- @Override
68
- public void w(String tag, String msg, Throwable tr) {
69
- Log.w(tag, msg, tr);
70
- onLog("warning", tag, msg, tr);
71
- }
72
-
73
- @Override
74
- public void e(String tag, String msg) {
75
- Log.e(tag, msg);
76
- onLog("error", tag, msg, null);
77
- }
78
-
79
- @Override
80
- public void e(String tag, String msg, Throwable tr) {
81
- Log.e(tag, msg, tr);
82
- onLog("error", tag, msg, tr);
83
- }
84
- });
85
- }
86
-
87
- @Override
88
- public String getName() {
89
- return REACT_CLASS;
90
- }
91
-
92
- @ReactMethod
93
- public void setLogLevel(String level) {
94
- @Logger.LogLevel int logLevel = Logger.NONE;
95
- switch(level)
96
- {
97
- case "error":
98
- logLevel = Logger.ERROR;
99
- break;
100
- case "warning":
101
- logLevel = Logger.WARN;
102
- break;
103
- case "info":
104
- logLevel = Logger.INFO;
105
- break;
106
- case "debug":
107
- logLevel = Logger.DEBUG;
108
- break;
109
- case "verbose":
110
- logLevel = Logger.VERBOSE;
111
- break;
112
- default:
113
- logLevel = Logger.NONE;
114
- break;
115
- }
116
- Logger.setVerbosity(logLevel);
117
- }
118
-
119
- @ReactMethod
120
- public void addListener(String eventName) {
121
- // Set up any upstream listeners or background tasks as necessary
122
- }
123
-
124
- @ReactMethod
125
- public void removeListeners(Integer count) {
126
- // Remove upstream listeners, stop unnecessary background tasks
127
- }
128
-
129
- public void onLog(String level, String tag, String msg, Throwable tr) {
130
- WritableMap event = Arguments.createMap();
131
- event.putString("message", msg);
132
- event.putString("tag", tag);
133
- event.putString("level", level);
134
-
135
- mReactContext
136
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
137
- .emit("LogEvent", event);
138
- }
139
-
140
- }
@@ -1,112 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Logger = void 0;
7
- var _reactNative = require("react-native");
8
- const MLRNLogging = _reactNative.NativeModules.MLRNLogging;
9
-
10
- /**
11
- * Supported log levels
12
- */
13
-
14
- /**
15
- * This callback is displayed as part of the Requester class.
16
- * @param {object} log
17
- * @param {string} log.message - the message of the log
18
- * @param {string} log.level - log level
19
- * @param {string} log.tag - optional tag used on android
20
- */
21
-
22
- class Logger {
23
- static instance = null;
24
- static sharedInstance() {
25
- if (this.instance === null) {
26
- this.instance = new Logger();
27
- }
28
- return this.instance;
29
- }
30
- constructor() {
31
- this.loggerEmitter = new _reactNative.NativeEventEmitter(MLRNLogging);
32
- this.startedCount = 0;
33
- this.logCallback = null;
34
- this.subscription = null;
35
- }
36
-
37
- /**
38
- * Set custom logger function
39
- *
40
- * @param logCallback - callback taking a log object as param. If callback return falsy value then default logging
41
- * will take place.
42
- */
43
- static setLogCallback(logCallback) {
44
- this.sharedInstance().setLogCallback(logCallback);
45
- }
46
-
47
- /**
48
- * Set custom logger function
49
- *
50
- * @param logCallback - callback taking a log object as param. If callback return falsy value then default logging
51
- * will take place.
52
- */
53
- setLogCallback(logCallback) {
54
- this.logCallback = logCallback;
55
- }
56
- static setLogLevel(level) {
57
- MLRNLogging.setLogLevel(level);
58
- }
59
- start() {
60
- if (this.startedCount === 0) {
61
- this.subscribe();
62
- }
63
- this.startedCount += 1;
64
- }
65
- stop() {
66
- this.startedCount -= 1;
67
- if (this.startedCount === 0) {
68
- this.unsubscribe();
69
- }
70
- }
71
- subscribe() {
72
- this.subscription = this.loggerEmitter.addListener("LogEvent", log => {
73
- this.onLog(log);
74
- });
75
- }
76
- unsubscribe() {
77
- if (this.subscription) {
78
- this.subscription.remove();
79
- this.subscription = null;
80
- }
81
- }
82
- effectiveLevel({
83
- level,
84
- message,
85
- tag
86
- }) {
87
- if (level === "warning") {
88
- if (tag === "Mbgl-HttpRequest" && message.startsWith("Request failed due to a permanent error: Canceled")) {
89
- // this seems to happening too much to show a warning every time
90
- return "info";
91
- }
92
- }
93
- return level;
94
- }
95
- onLog(log) {
96
- if (!this.logCallback || !this.logCallback(log)) {
97
- const {
98
- message
99
- } = log;
100
- const level = this.effectiveLevel(log);
101
- if (level === "error") {
102
- console.error("MapLibre error", message, log);
103
- } else if (level === "warning") {
104
- console.warn("MapLibre warning", message, log);
105
- } else {
106
- console.log(`MapLibre [${level}]`, message, log);
107
- }
108
- }
109
- }
110
- }
111
- exports.Logger = Logger;
112
- //# sourceMappingURL=Logger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_reactNative","require","MLRNLogging","NativeModules","Logger","instance","sharedInstance","constructor","loggerEmitter","NativeEventEmitter","startedCount","logCallback","subscription","setLogCallback","setLogLevel","level","start","subscribe","stop","unsubscribe","addListener","log","onLog","remove","effectiveLevel","message","tag","startsWith","console","error","warn","exports"],"sourceRoot":"../../../src","sources":["modules/Logger.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAKA,MAAMC,WAAW,GAAGC,0BAAa,CAACD,WAAW;;AAE7C;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGO,MAAME,MAAM,CAAC;EAClB,OAAOC,QAAQ,GAAkB,IAAI;EAErC,OAAOC,cAAcA,CAAA,EAAW;IAC9B,IAAI,IAAI,CAACD,QAAQ,KAAK,IAAI,EAAE;MAC1B,IAAI,CAACA,QAAQ,GAAG,IAAID,MAAM,CAAC,CAAC;IAC9B;IACA,OAAO,IAAI,CAACC,QAAQ;EACtB;EAOAE,WAAWA,CAAA,EAAG;IACZ,IAAI,CAACC,aAAa,GAAG,IAAIC,+BAAkB,CAACP,WAAW,CAAC;IACxD,IAAI,CAACQ,YAAY,GAAG,CAAC;IACrB,IAAI,CAACC,WAAW,GAAG,IAAI;IACvB,IAAI,CAACC,YAAY,GAAG,IAAI;EAC1B;;EAEA;AACF;AACA;AACA;AACA;AACA;EACE,OAAOC,cAAcA,CAACF,WAAwB,EAAQ;IACpD,IAAI,CAACL,cAAc,CAAC,CAAC,CAACO,cAAc,CAACF,WAAW,CAAC;EACnD;;EAEA;AACF;AACA;AACA;AACA;AACA;EACEE,cAAcA,CAACF,WAAwB,EAAQ;IAC7C,IAAI,CAACA,WAAW,GAAGA,WAAW;EAChC;EAEA,OAAOG,WAAWA,CAACC,KAAe,EAAQ;IACxCb,WAAW,CAACY,WAAW,CAACC,KAAK,CAAC;EAChC;EAEAC,KAAKA,CAAA,EAAS;IACZ,IAAI,IAAI,CAACN,YAAY,KAAK,CAAC,EAAE;MAC3B,IAAI,CAACO,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ACE,IAAI,CAAC,kBAAkB,EAAEL,OAAO,EAAEJ,GAAG,CAAC;MAChD,CAAC,MAAM;QACLO,OAAO,CAACP,GAAG,CAAC,aAAaN,KAAK,GAAG,EAAEU,OAAO,EAAEJ,GAAG,CAAC;MAClD;IACF;EACF;AACF;AAACU,OAAA,CAAA3B,MAAA,GAAAA,MAAA","ignoreList":[]}
@@ -1,107 +0,0 @@
1
- "use strict";
2
-
3
- import { NativeEventEmitter, NativeModules } from "react-native";
4
- const MLRNLogging = NativeModules.MLRNLogging;
5
-
6
- /**
7
- * Supported log levels
8
- */
9
-
10
- /**
11
- * This callback is displayed as part of the Requester class.
12
- * @param {object} log
13
- * @param {string} log.message - the message of the log
14
- * @param {string} log.level - log level
15
- * @param {string} log.tag - optional tag used on android
16
- */
17
-
18
- export class Logger {
19
- static instance = null;
20
- static sharedInstance() {
21
- if (this.instance === null) {
22
- this.instance = new Logger();
23
- }
24
- return this.instance;
25
- }
26
- constructor() {
27
- this.loggerEmitter = new NativeEventEmitter(MLRNLogging);
28
- this.startedCount = 0;
29
- this.logCallback = null;
30
- this.subscription = null;
31
- }
32
-
33
- /**
34
- * Set custom logger function
35
- *
36
- * @param logCallback - callback taking a log object as param. If callback return falsy value then default logging
37
- * will take place.
38
- */
39
- static setLogCallback(logCallback) {
40
- this.sharedInstance().setLogCallback(logCallback);
41
- }
42
-
43
- /**
44
- * Set custom logger function
45
- *
46
- * @param logCallback - callback taking a log object as param. If callback return falsy value then default logging
47
- * will take place.
48
- */
49
- setLogCallback(logCallback) {
50
- this.logCallback = logCallback;
51
- }
52
- static setLogLevel(level) {
53
- MLRNLogging.setLogLevel(level);
54
- }
55
- start() {
56
- if (this.startedCount === 0) {
57
- this.subscribe();
58
- }
59
- this.startedCount += 1;
60
- }
61
- stop() {
62
- this.startedCount -= 1;
63
- if (this.startedCount === 0) {
64
- this.unsubscribe();
65
- }
66
- }
67
- subscribe() {
68
- this.subscription = this.loggerEmitter.addListener("LogEvent", log => {
69
- this.onLog(log);
70
- });
71
- }
72
- unsubscribe() {
73
- if (this.subscription) {
74
- this.subscription.remove();
75
- this.subscription = null;
76
- }
77
- }
78
- effectiveLevel({
79
- level,
80
- message,
81
- tag
82
- }) {
83
- if (level === "warning") {
84
- if (tag === "Mbgl-HttpRequest" && message.startsWith("Request failed due to a permanent error: Canceled")) {
85
- // this seems to happening too much to show a warning every time
86
- return "info";
87
- }
88
- }
89
- return level;
90
- }
91
- onLog(log) {
92
- if (!this.logCallback || !this.logCallback(log)) {
93
- const {
94
- message
95
- } = log;
96
- const level = this.effectiveLevel(log);
97
- if (level === "error") {
98
- console.error("MapLibre error", message, log);
99
- } else if (level === "warning") {
100
- console.warn("MapLibre warning", message, log);
101
- } else {
102
- console.log(`MapLibre [${level}]`, message, log);
103
- }
104
- }
105
- }
106
- }
107
- //# sourceMappingURL=Logger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["NativeEventEmitter","NativeModules","MLRNLogging","Logger","instance","sharedInstance","constructor","loggerEmitter","startedCount","logCallback","subscription","setLogCallback","setLogLevel","level","start","subscribe","stop","unsubscribe","addListener","log","onLog","remove","effectiveLevel","message","tag","startsWith","console","error","warn"],"sourceRoot":"../../../src","sources":["modules/Logger.ts"],"mappings":";;AAAA,SAEEA,kBAAkB,EAClBC,aAAa,QACR,cAAc;AACrB,MAAMC,WAAW,GAAGD,aAAa,CAACC,WAAW;;AAE7C;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,OAAO,MAAMC,MAAM,CAAC;EAClB,OAAOC,QAAQ,GAAkB,IAAI;EAErC,OAAOC,cAAcA,CAAA,EAAW;IAC9B,IAAI,IAAI,CAACD,QAAQ,KAAK,IAAI,EAAE;MAC1B,IAAI,CAACA,QAAQ,GAAG,IAAID,MAAM,CAAC,CAAC;IAC9B;IACA,OAAO,IAAI,CAACC,QAAQ;EACtB;EAOAE,WAAWA,CAAA,EAAG;IACZ,IAAI,CAACC,aAAa,GAAG,IAAIP,kBA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