react-native-maplibre-gl-js 1.0.0

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 (137) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +146 -0
  3. package/lib/module/communication/messages.types.js +4 -0
  4. package/lib/module/communication/messages.types.js.map +1 -0
  5. package/lib/module/communication/messages.utils.js +27 -0
  6. package/lib/module/communication/messages.utils.js.map +1 -0
  7. package/lib/module/index.js +14 -0
  8. package/lib/module/index.js.map +1 -0
  9. package/lib/module/package.json +1 -0
  10. package/lib/module/react-native/components/Map/Map.js +11 -0
  11. package/lib/module/react-native/components/Map/Map.js.map +1 -0
  12. package/lib/module/react-native/components/Map/Map.types.js +4 -0
  13. package/lib/module/react-native/components/Map/Map.types.js.map +1 -0
  14. package/lib/module/react-native/components/MapProvider/MapProvider.hooks.js +18 -0
  15. package/lib/module/react-native/components/MapProvider/MapProvider.hooks.js.map +1 -0
  16. package/lib/module/react-native/components/MapProvider/MapProvider.js +118 -0
  17. package/lib/module/react-native/components/MapProvider/MapProvider.js.map +1 -0
  18. package/lib/module/react-native/components/MapProvider/MapProvider.types.js +4 -0
  19. package/lib/module/react-native/components/MapProvider/MapProvider.types.js.map +1 -0
  20. package/lib/module/react-native/components/Marker/Marker.js +11 -0
  21. package/lib/module/react-native/components/Marker/Marker.js.map +1 -0
  22. package/lib/module/react-native/components/Marker/Marker.types.js +4 -0
  23. package/lib/module/react-native/components/Marker/Marker.types.js.map +1 -0
  24. package/lib/module/react-native/components/Popup/Popup.js +12 -0
  25. package/lib/module/react-native/components/Popup/Popup.js.map +1 -0
  26. package/lib/module/react-native/components/Popup/Popup.types.js +4 -0
  27. package/lib/module/react-native/components/Popup/Popup.types.js.map +1 -0
  28. package/lib/module/react-native/components-factory/createWebObjectAsComponent.js +23 -0
  29. package/lib/module/react-native/components-factory/createWebObjectAsComponent.js.map +1 -0
  30. package/lib/module/react-native/components-factory/createWebObjectAsComponent.types.js +4 -0
  31. package/lib/module/react-native/components-factory/createWebObjectAsComponent.types.js.map +1 -0
  32. package/lib/module/react-native/components-factory/hooks/useWebObjectMethodsProxy.js +54 -0
  33. package/lib/module/react-native/components-factory/hooks/useWebObjectMethodsProxy.js.map +1 -0
  34. package/lib/module/react-native/components-factory/hooks/useWebObjectMountOnLaunch.js +68 -0
  35. package/lib/module/react-native/components-factory/hooks/useWebObjectMountOnLaunch.js.map +1 -0
  36. package/lib/module/react-native/components-factory/hooks/useWebObjectOptionsUpdater.js +20 -0
  37. package/lib/module/react-native/components-factory/hooks/useWebObjectOptionsUpdater.js.map +1 -0
  38. package/lib/module/react-native/hooks/atoms/useMapAtoms.js +198 -0
  39. package/lib/module/react-native/hooks/atoms/useMapAtoms.js.map +1 -0
  40. package/lib/module/react-native/hooks/atoms/useMapAtoms.utils.js +18 -0
  41. package/lib/module/react-native/hooks/atoms/useMapAtoms.utils.js.map +1 -0
  42. package/lib/module/react-native/logger/rn-logger.js +42 -0
  43. package/lib/module/react-native/logger/rn-logger.js.map +1 -0
  44. package/lib/module/typedoc.js +4 -0
  45. package/lib/module/typedoc.js.map +1 -0
  46. package/lib/module/web/bridge/ReactNativeBridge.js +38 -0
  47. package/lib/module/web/bridge/ReactNativeBridge.js.map +1 -0
  48. package/lib/module/web/generated/index.html +18 -0
  49. package/lib/module/web/generated/index.js +21 -0
  50. package/lib/module/web/generated/index.js.map +1 -0
  51. package/lib/module/web/generated/webview_static_html.js +23529 -0
  52. package/lib/module/web/generated/webview_static_html.js.map +1 -0
  53. package/lib/module/web/logger/web-logger.js +35 -0
  54. package/lib/module/web/logger/web-logger.js.map +1 -0
  55. package/lib/module/web/maplibre-gl-js/MapController.js +264 -0
  56. package/lib/module/web/maplibre-gl-js/MapController.js.map +1 -0
  57. package/lib/typescript/package.json +1 -0
  58. package/lib/typescript/src/communication/messages.types.d.ts +105 -0
  59. package/lib/typescript/src/communication/messages.types.d.ts.map +1 -0
  60. package/lib/typescript/src/communication/messages.utils.d.ts +6 -0
  61. package/lib/typescript/src/communication/messages.utils.d.ts.map +1 -0
  62. package/lib/typescript/src/index.d.ts +19 -0
  63. package/lib/typescript/src/index.d.ts.map +1 -0
  64. package/lib/typescript/src/react-native/components/Map/Map.d.ts +9 -0
  65. package/lib/typescript/src/react-native/components/Map/Map.d.ts.map +1 -0
  66. package/lib/typescript/src/react-native/components/Map/Map.types.d.ts +70 -0
  67. package/lib/typescript/src/react-native/components/Map/Map.types.d.ts.map +1 -0
  68. package/lib/typescript/src/react-native/components/MapProvider/MapProvider.d.ts +9 -0
  69. package/lib/typescript/src/react-native/components/MapProvider/MapProvider.d.ts.map +1 -0
  70. package/lib/typescript/src/react-native/components/MapProvider/MapProvider.hooks.d.ts +12 -0
  71. package/lib/typescript/src/react-native/components/MapProvider/MapProvider.hooks.d.ts.map +1 -0
  72. package/lib/typescript/src/react-native/components/MapProvider/MapProvider.types.d.ts +12 -0
  73. package/lib/typescript/src/react-native/components/MapProvider/MapProvider.types.d.ts.map +1 -0
  74. package/lib/typescript/src/react-native/components/Marker/Marker.d.ts +9 -0
  75. package/lib/typescript/src/react-native/components/Marker/Marker.d.ts.map +1 -0
  76. package/lib/typescript/src/react-native/components/Marker/Marker.types.d.ts +31 -0
  77. package/lib/typescript/src/react-native/components/Marker/Marker.types.d.ts.map +1 -0
  78. package/lib/typescript/src/react-native/components/Popup/Popup.d.ts +9 -0
  79. package/lib/typescript/src/react-native/components/Popup/Popup.d.ts.map +1 -0
  80. package/lib/typescript/src/react-native/components/Popup/Popup.types.d.ts +25 -0
  81. package/lib/typescript/src/react-native/components/Popup/Popup.types.d.ts.map +1 -0
  82. package/lib/typescript/src/react-native/components-factory/createWebObjectAsComponent.d.ts +5 -0
  83. package/lib/typescript/src/react-native/components-factory/createWebObjectAsComponent.d.ts.map +1 -0
  84. package/lib/typescript/src/react-native/components-factory/createWebObjectAsComponent.types.d.ts +129 -0
  85. package/lib/typescript/src/react-native/components-factory/createWebObjectAsComponent.types.d.ts.map +1 -0
  86. package/lib/typescript/src/react-native/components-factory/hooks/useWebObjectMethodsProxy.d.ts +12 -0
  87. package/lib/typescript/src/react-native/components-factory/hooks/useWebObjectMethodsProxy.d.ts.map +1 -0
  88. package/lib/typescript/src/react-native/components-factory/hooks/useWebObjectMountOnLaunch.d.ts +12 -0
  89. package/lib/typescript/src/react-native/components-factory/hooks/useWebObjectMountOnLaunch.d.ts.map +1 -0
  90. package/lib/typescript/src/react-native/components-factory/hooks/useWebObjectOptionsUpdater.d.ts +5 -0
  91. package/lib/typescript/src/react-native/components-factory/hooks/useWebObjectOptionsUpdater.d.ts.map +1 -0
  92. package/lib/typescript/src/react-native/hooks/atoms/useMapAtoms.d.ts +40 -0
  93. package/lib/typescript/src/react-native/hooks/atoms/useMapAtoms.d.ts.map +1 -0
  94. package/lib/typescript/src/react-native/hooks/atoms/useMapAtoms.utils.d.ts +9 -0
  95. package/lib/typescript/src/react-native/hooks/atoms/useMapAtoms.utils.d.ts.map +1 -0
  96. package/lib/typescript/src/react-native/logger/rn-logger.d.ts +12 -0
  97. package/lib/typescript/src/react-native/logger/rn-logger.d.ts.map +1 -0
  98. package/lib/typescript/src/typedoc.d.ts +8 -0
  99. package/lib/typescript/src/typedoc.d.ts.map +1 -0
  100. package/lib/typescript/src/web/bridge/ReactNativeBridge.d.ts +14 -0
  101. package/lib/typescript/src/web/bridge/ReactNativeBridge.d.ts.map +1 -0
  102. package/lib/typescript/src/web/generated/index.d.ts +2 -0
  103. package/lib/typescript/src/web/generated/index.d.ts.map +1 -0
  104. package/lib/typescript/src/web/generated/webview_static_html.d.ts +2 -0
  105. package/lib/typescript/src/web/generated/webview_static_html.d.ts.map +1 -0
  106. package/lib/typescript/src/web/logger/web-logger.d.ts +11 -0
  107. package/lib/typescript/src/web/logger/web-logger.d.ts.map +1 -0
  108. package/lib/typescript/src/web/maplibre-gl-js/MapController.d.ts +15 -0
  109. package/lib/typescript/src/web/maplibre-gl-js/MapController.d.ts.map +1 -0
  110. package/package.json +196 -0
  111. package/src/communication/messages.types.ts +121 -0
  112. package/src/communication/messages.utils.ts +58 -0
  113. package/src/index.ts +31 -0
  114. package/src/react-native/components/Map/Map.tsx +14 -0
  115. package/src/react-native/components/Map/Map.types.ts +149 -0
  116. package/src/react-native/components/MapProvider/MapProvider.hooks.ts +13 -0
  117. package/src/react-native/components/MapProvider/MapProvider.tsx +139 -0
  118. package/src/react-native/components/MapProvider/MapProvider.types.ts +12 -0
  119. package/src/react-native/components/Marker/Marker.tsx +14 -0
  120. package/src/react-native/components/Marker/Marker.types.ts +56 -0
  121. package/src/react-native/components/Popup/Popup.tsx +14 -0
  122. package/src/react-native/components/Popup/Popup.types.ts +43 -0
  123. package/src/react-native/components-factory/createWebObjectAsComponent.ts +33 -0
  124. package/src/react-native/components-factory/createWebObjectAsComponent.types.ts +176 -0
  125. package/src/react-native/components-factory/hooks/useWebObjectMethodsProxy.ts +61 -0
  126. package/src/react-native/components-factory/hooks/useWebObjectMountOnLaunch.ts +79 -0
  127. package/src/react-native/components-factory/hooks/useWebObjectOptionsUpdater.ts +29 -0
  128. package/src/react-native/hooks/atoms/useMapAtoms.ts +261 -0
  129. package/src/react-native/hooks/atoms/useMapAtoms.utils.ts +15 -0
  130. package/src/react-native/logger/rn-logger.ts +51 -0
  131. package/src/typedoc.ts +35 -0
  132. package/src/web/bridge/ReactNativeBridge.ts +44 -0
  133. package/src/web/generated/index.html +18 -0
  134. package/src/web/generated/index.ts +17 -0
  135. package/src/web/generated/webview_static_html.ts +23528 -0
  136. package/src/web/logger/web-logger.ts +36 -0
  137. package/src/web/maplibre-gl-js/MapController.ts +322 -0
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Emilien Aufauvre
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,146 @@
1
+ <div align="center">
2
+ <h1>react-native-maplibre-gl-js</h1>
3
+ </div>
4
+ <div align="center">
5
+ <img src="https://img.shields.io/github/license/emilienaufauvre/react-native-maplibre-gl-js?style=for-the-badge&labelColor=black" />
6
+ <img src="https://img.shields.io/github/actions/workflow/status/emilienaufauvre/react-native-maplibre-gl-js/ci.yml?branch=main&style=for-the-badge&label=CI&labelColor=black" />
7
+ <img src="https://img.shields.io/github/actions/workflow/status/emilienaufauvre/react-native-maplibre-gl-js/cd.yml?branch=main&style=for-the-badge&label=CD&labelColor=black" />
8
+ <img src="https://img.shields.io/npm/v/react-native-maplibre-gl-js.svg?style=for-the-badge&label=NPM&labelColor=black" />
9
+ </div>
10
+
11
+ <div align="center">
12
+ <br/>
13
+ <p>
14
+ A TypeScript library to enable the use of
15
+ <a href="https://github.com/maplibre/maplibre-gl-js" target="_blank">
16
+ MapLibre GL JS
17
+ </a>
18
+ within React Native.
19
+ <br/>
20
+ Aims to bring all the web features into React Native components, thereby
21
+ offering new capabilities to React Native developers.
22
+ </p>
23
+ <p align="center">
24
+ <img
25
+ src="./res/demo1.gif"
26
+ width="300"
27
+ alt="Example of a MapLibre GL JS map in React Native with marker drag"
28
+ />
29
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
30
+ <img
31
+ src="./res/demo2.gif"
32
+ width="300"
33
+ alt="Example of a MapLibre GL JS map in React Native with flyto camera animation"
34
+ />
35
+ </p>
36
+ </div>
37
+
38
+ > [!IMPORTANT]
39
+ > This project **is not** affiliated with, endorsed by, or sponsored by MapLibre.
40
+
41
+
42
+ ## Supported platforms
43
+
44
+ | Platform | Status |
45
+ |--------|--------|
46
+ | iOS | ✅ |
47
+ | Android | ✅ |
48
+ | Web | ❌ |
49
+
50
+ ## Documentation
51
+
52
+ 📘 [**API Reference** – Complete TypeScript API documentation.](./docs/api/index.md)
53
+
54
+ 🧪 [**Examples** – Real-world examples showcasing common use cases.](./docs/examples/index.md)
55
+
56
+ 📚 [**For library developers** – Internal architecture, glossary and design decisions.](./docs/developer/index.md)
57
+
58
+
59
+ ## Installation
60
+
61
+ ** TODO not available on npm yet **
62
+
63
+ ```sh
64
+ npm install react-native-maplibre-gl-js
65
+ ```
66
+
67
+ ## Getting started
68
+
69
+ The minimal setup to render a MapLibre map in React Native.
70
+
71
+ ```js
72
+ import RNMapLibreGlJs from 'react-native-maplibre-gl-js';
73
+
74
+ export const MyMapComponent = () => {
75
+ return (
76
+ <RNMapLibreGlJs.MapProvider>
77
+ <RNMapLibreGlJs.Map
78
+ options={{
79
+ style: 'https://tiles.openfreemap.org/styles/liberty',
80
+ center: [2.32, 48.86],
81
+ zoom: 12,
82
+ }}
83
+ />
84
+ </RNMapLibreGlJs.MapProvider>
85
+ )
86
+ }
87
+ ```
88
+
89
+
90
+ ## Design rationale
91
+
92
+ Explain why I decided to build a new React Native map library instead of using
93
+ an existing one.
94
+
95
+ ### Existing React Native map solutions
96
+
97
+ Considering tile-based maps, these are the maintained or supported libraries
98
+ that can be used in React Native. Each has its strengths, and credit goes to
99
+ their contributors. Still, I have highlighted what I consider to be their main
100
+ drawbacks.
101
+
102
+ | Library | Notes | Main Drawbacks |
103
+ |-----------------------------|------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
104
+ | `react-native-maps` / `expo-maps` | Overlay custom tiles on Apple Maps (iOS) or Google Maps (iOS/Android). | - On tile loading, the map below (Google Maps or Apple Maps) is visible.<br/>- If the map provider is Google Maps (mandatory on the Android platform), an API key is needed to use Google Maps SDK, and therefore its use is billed. |
105
+ | `@rnmapbox/maps` | - | - Dependence on Mapbox choices.<br>- On the latest versions, an API key is required (at least on the Android side that drops the MapLibre SDK support), and therefore its use is billed.<br>- To render animated markers or markers with dynamic content and developed visual styles, the use of native views is necessary, and this greatly slows down the application. |
106
+ | `maplibre-react-native` | Open source fork of MapBox. | - Being an open source fork of MapBox, the library is years behind (1000+ commits to date) and lacks many features and bug fixes.<br>- The same performance issue with native views as `@rnmapbox` is also present. |
107
+
108
+ ### Architectural approach
109
+
110
+ To address these drawbacks, two main approaches are possible (as far as I know):
111
+ either build a library on top of native views using free mobile SDKs (such as
112
+ MapLibre Native, meaning the effort should instead go into improving
113
+ `maplibre-react-native`), or leverage existing web-based map libraries.
114
+
115
+ The second option is far easier to build and maintain since it relies on a
116
+ single rendering engine rather than separate iOS and Android SDKs. It also opens
117
+ the door to fixing performance issues and limitations found in earlier
118
+ libraries, while enabling more features.
119
+
120
+ I outline two solutions in this category below, along with the issues they still
121
+ carry. This library implements the second approach.
122
+
123
+ | Approach | Description | Main Drawbacks |
124
+ |-----------------------------------------------|-----------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
125
+ | Remote WebView-based map | Host a map on a web page and access it through a WebView. | - Requires additional infrastructure.<br>- Very sensitive to network latency, and in general, a degraded user experience.<br>- Offline usage is not possible. |
126
+ | Embedded WebView with bundled MapLibre GL JS | Bundle JS code that runs MapLibre GL JS, enabling two-way communication with React Native, and inject it into a WebView for execution. | - Any interaction between the WebView content and the React Native world is made through message-passing, which can make certain interactions more indirect.<br>- Some objects cannot be serialized and sent between the WebView code and React Native (e.g., HTMLElement).<br>- Some GitHub repositories are implementing this solution, however, no one is actively maintained, and the underlying web libraries are missing key features — good examples being `react-native-leaflet-view` and `@neukolabs/react-native-maplibre-js`. |
127
+
128
+
129
+ ## Contributing
130
+
131
+ - [Development workflow](CONTRIBUTING.md#development-workflow)
132
+ - [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
133
+ - [Code of conduct](CODE_OF_CONDUCT.md)
134
+
135
+
136
+ ## Credits
137
+
138
+ - [OpenFreeMap](https://openfreemap.org/) for providing free tile data in the
139
+ examples ❤️.
140
+
141
+
142
+ ## License
143
+
144
+ MIT
145
+
146
+ ---
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ export {};
4
+ //# sourceMappingURL=messages.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["communication/messages.types.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ export const isWebObjectListenerOnRN = listener => {
4
+ if (!listener) {
5
+ return false;
6
+ }
7
+ return 'rnListener' in listener;
8
+ };
9
+ export const isWebObjectListenerOnObject = listener => {
10
+ if (!listener) {
11
+ return false;
12
+ }
13
+ return 'objectListener' in listener;
14
+ };
15
+ export const isWebObjectListenerOnMapLayer = listener => {
16
+ if (!listener) {
17
+ return false;
18
+ }
19
+ return 'layerListener' in listener;
20
+ };
21
+ export const isWebObjectListenerOnHTMLElement = listener => {
22
+ if (!listener) {
23
+ return false;
24
+ }
25
+ return 'elementListener' in listener;
26
+ };
27
+ //# sourceMappingURL=messages.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["isWebObjectListenerOnRN","listener","isWebObjectListenerOnObject","isWebObjectListenerOnMapLayer","isWebObjectListenerOnHTMLElement"],"sourceRoot":"../../../src","sources":["communication/messages.utils.ts"],"mappings":";;AAOA,OAAO,MAAMA,uBAAuB,GAClCC,QAIoC,IACxB;EACZ,IAAI,CAACA,QAAQ,EAAE;IACb,OAAO,KAAK;EACd;EACA,OAAO,YAAY,IAAIA,QAAQ;AACjC,CAAC;AAED,OAAO,MAAMC,2BAA2B,GACtCD,QAIoC,IACxB;EACZ,IAAI,CAACA,QAAQ,EAAE;IACb,OAAO,KAAK;EACd;EACA,OAAO,gBAAgB,IAAIA,QAAQ;AACrC,CAAC;AAED,OAAO,MAAME,6BAA6B,GACxCF,QAIoC,IACxB;EACZ,IAAI,CAACA,QAAQ,EAAE;IACb,OAAO,KAAK;EACd;EACA,OAAO,eAAe,IAAIA,QAAQ;AACpC,CAAC;AAED,OAAO,MAAMG,gCAAgC,GAC3CH,QAIoC,IACxB;EACZ,IAAI,CAACA,QAAQ,EAAE;IACb,OAAO,KAAK;EACd;EACA,OAAO,iBAAiB,IAAIA,QAAQ;AACtC,CAAC","ignoreList":[]}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Public API of react-native-maplibre-gl-js.
5
+ * @module Public API
6
+ * @packageDocumentation
7
+ */
8
+
9
+ import MapProvider from 'react-native-maplibre-gl-js/react-native/components/MapProvider/MapProvider';
10
+ import Map from 'react-native-maplibre-gl-js/react-native/components/Map/Map';
11
+ import Marker from 'react-native-maplibre-gl-js/react-native/components/Marker/Marker';
12
+ import Popup from 'react-native-maplibre-gl-js/react-native/components/Popup/Popup';
13
+ export { MapProvider, Map, Marker, Popup };
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["MapProvider","Map","Marker","Popup"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;;AAqBA,OAAOA,WAAW,MAAM,6EAA6E;AACrG,OAAOC,GAAG,MAAM,6DAA6D;AAC7E,OAAOC,MAAM,MAAM,mEAAmE;AACtF,OAAOC,KAAK,MAAM,iEAAiE;AAEnF,SAASH,WAAW,EAAEC,GAAG,EAAEC,MAAM,EAAEC,KAAK","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ import createWebObjectAsComponent from 'react-native-maplibre-gl-js/react-native/components-factory/createWebObjectAsComponent';
4
+ /**
5
+ * MapLibre Map view.
6
+ * @see {@link https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/ MapLibre GL JS docs}
7
+ * @group Components
8
+ */
9
+ const Map = createWebObjectAsComponent('map');
10
+ export default Map;
11
+ //# sourceMappingURL=Map.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createWebObjectAsComponent","Map"],"sourceRoot":"../../../../../src","sources":["react-native/components/Map/Map.tsx"],"mappings":";;AAAA,OAAOA,0BAA0B,MAAM,wFAAwF;AAM/H;AACA;AACA;AACA;AACA;AACA,MAAMC,GAAG,GAAGD,0BAA0B,CAAmB,KAAK,CAAC;AAE/D,eAAeC,GAAG","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ export {};
4
+ //# sourceMappingURL=Map.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../../../src","sources":["react-native/components/Map/Map.types.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ import { StyleSheet } from 'react-native';
4
+ import { useMemo } from 'react';
5
+ export const useStyles = () => {
6
+ return useMemo(() => StyleSheet.create({
7
+ container: {
8
+ width: '100%',
9
+ height: '100%',
10
+ overflow: 'hidden'
11
+ },
12
+ webview: {
13
+ flex: 1,
14
+ backgroundColor: 'transparent'
15
+ }
16
+ }), []);
17
+ };
18
+ //# sourceMappingURL=MapProvider.hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["StyleSheet","useMemo","useStyles","create","container","width","height","overflow","webview","flex","backgroundColor"],"sourceRoot":"../../../../../src","sources":["react-native/components/MapProvider/MapProvider.hooks.ts"],"mappings":";;AAAA,SAASA,UAAU,QAAQ,cAAc;AACzC,SAASC,OAAO,QAAQ,OAAO;AAE/B,OAAO,MAAMC,SAAS,GAAGA,CAAA,KAAM;EAC7B,OAAOD,OAAO,CACZ,MACED,UAAU,CAACG,MAAM,CAAC;IAChBC,SAAS,EAAE;MAAEC,KAAK,EAAE,MAAM;MAAEC,MAAM,EAAE,MAAM;MAAEC,QAAQ,EAAE;IAAS,CAAC;IAChEC,OAAO,EAAE;MAAEC,IAAI,EAAE,CAAC;MAAEC,eAAe,EAAE;IAAc;EACrD,CAAC,CAAC,EACJ,EACF,CAAC;AACH,CAAC","ignoreList":[]}
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+
3
+ import { View } from 'react-native';
4
+ import { WebView } from 'react-native-webview';
5
+ import { WEBVIEW_STATIC_HTML } from 'react-native-maplibre-gl-js/web/generated/webview_static_html';
6
+ import RNLogger from 'react-native-maplibre-gl-js/react-native/logger/rn-logger';
7
+ import useMapAtoms from 'react-native-maplibre-gl-js/react-native/hooks/atoms/useMapAtoms';
8
+ import { isWebObjectListenerOnHTMLElement, isWebObjectListenerOnMapLayer, isWebObjectListenerOnObject, isWebObjectListenerOnRN } from 'react-native-maplibre-gl-js/communication/messages.utils';
9
+ import { useStyles } from 'react-native-maplibre-gl-js/react-native/components/MapProvider/MapProvider.hooks';
10
+ import { useCallback, useEffect } from 'react';
11
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
+ /**
13
+ * Provide the main
14
+ * @param props -
15
+ * @group Components
16
+ */
17
+ const MapProvider = ({
18
+ children
19
+ }) => {
20
+ // States.
21
+ // - Global.
22
+ const {
23
+ setWebView,
24
+ setIsWebWorldReady,
25
+ isMapMountMessageReady,
26
+ flushMessages,
27
+ getWebObjectListeners,
28
+ resolveWebObjectPendingMethodResponse
29
+ } = useMapAtoms();
30
+ // Theme.
31
+ const styles = useStyles();
32
+
33
+ // On start, the map must be mounted before any other map element. When the
34
+ // mount message of the map is ready, we flush all the pending messages to
35
+ // the web world.
36
+ useEffect(() => {
37
+ if (isMapMountMessageReady) {
38
+ flushMessages();
39
+ }
40
+ }, [flushMessages, isMapMountMessageReady]);
41
+
42
+ // Handler of messages from the web world.
43
+ const onMessage = useCallback(
44
+ // Not an anonymous function => get the function name for logger.
45
+ function handleMessage(event) {
46
+ try {
47
+ RNLogger.debug('RN', handleMessage.name, event?.nativeEvent?.data);
48
+ const message = JSON.parse(event.nativeEvent.data);
49
+ switch (message.type) {
50
+ case 'console':
51
+ {
52
+ RNLogger[message.payload.level]('Web', message.payload.args[0], ...message.payload.args.slice(1));
53
+ break;
54
+ }
55
+ case 'ready':
56
+ {
57
+ setIsWebWorldReady(true);
58
+ break;
59
+ }
60
+ case 'webObjectListenerEvent':
61
+ {
62
+ // Retrieve the corresponding object listener.
63
+ const listener = getWebObjectListeners({
64
+ objectId: message.payload.objectId
65
+ })?.[message.payload.eventName];
66
+ // Then, call it.
67
+ if (isWebObjectListenerOnRN(listener)) {
68
+ ;
69
+ listener.rnListener(message.payload.event);
70
+ }
71
+ if (isWebObjectListenerOnObject(listener)) {
72
+ ;
73
+ listener.objectListener(message.payload.event);
74
+ }
75
+ if (isWebObjectListenerOnMapLayer(listener)) {
76
+ ;
77
+ listener.layerListener(message.payload.event);
78
+ }
79
+ if (isWebObjectListenerOnHTMLElement(listener)) {
80
+ ;
81
+ listener.elementListener(message.payload.event);
82
+ }
83
+ break;
84
+ }
85
+ case 'webObjectMethodResponse':
86
+ {
87
+ resolveWebObjectPendingMethodResponse({
88
+ requestId: message.payload.requestId,
89
+ result: message.payload.result
90
+ });
91
+ break;
92
+ }
93
+ }
94
+ } catch (error) {
95
+ RNLogger.error('RN', handleMessage.name, error.message);
96
+ }
97
+ }, [setIsWebWorldReady, getWebObjectListeners, resolveWebObjectPendingMethodResponse]);
98
+ return /*#__PURE__*/_jsxs(View, {
99
+ style: styles.container,
100
+ children: [/*#__PURE__*/_jsx(WebView, {
101
+ ref: setWebView,
102
+ style: styles.webview,
103
+ originWhitelist: ['*'],
104
+ javaScriptEnabled: true,
105
+ allowFileAccess: true,
106
+ domStorageEnabled: true,
107
+ scrollEnabled: false,
108
+ allowUniversalAccessFromFileURLs: true,
109
+ mixedContentMode: 'always',
110
+ onMessage: onMessage,
111
+ source: {
112
+ html: WEBVIEW_STATIC_HTML
113
+ }
114
+ }), children]
115
+ });
116
+ };
117
+ export default MapProvider;
118
+ //# sourceMappingURL=MapProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["View","WebView","WEBVIEW_STATIC_HTML","RNLogger","useMapAtoms","isWebObjectListenerOnHTMLElement","isWebObjectListenerOnMapLayer","isWebObjectListenerOnObject","isWebObjectListenerOnRN","useStyles","useCallback","useEffect","jsx","_jsx","jsxs","_jsxs","MapProvider","children","setWebView","setIsWebWorldReady","isMapMountMessageReady","flushMessages","getWebObjectListeners","resolveWebObjectPendingMethodResponse","styles","onMessage","handleMessage","event","debug","name","nativeEvent","data","message","JSON","parse","type","payload","level","args","slice","listener","objectId","eventName","rnListener","objectListener","layerListener","elementListener","requestId","result","error","style","container","ref","webview","originWhitelist","javaScriptEnabled","allowFileAccess","domStorageEnabled","scrollEnabled","allowUniversalAccessFromFileURLs","mixedContentMode","source","html"],"sourceRoot":"../../../../../src","sources":["react-native/components/MapProvider/MapProvider.tsx"],"mappings":";;AAAA,SAASA,IAAI,QAAQ,cAAc;AACnC,SAASC,OAAO,QAAkC,sBAAsB;AACxE,SAASC,mBAAmB,QAAQ,+DAA+D;AAEnG,OAAOC,QAAQ,MAAM,2DAA2D;AAChF,OAAOC,WAAW,MAAM,kEAAkE;AAC1F,SACEC,gCAAgC,EAChCC,6BAA6B,EAC7BC,2BAA2B,EAC3BC,uBAAuB,QAClB,0DAA0D;AACjE,SAASC,SAAS,QAAQ,mFAAmF;AAC7G,SAASC,WAAW,EAAEC,SAAS,QAAQ,OAAO;AAAA,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAS9C;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAW,GAAGA,CAAC;EAAEC;AAA2B,CAAC,KAAK;EACtD;EACA;EACA,MAAM;IACJC,UAAU;IACVC,kBAAkB;IAClBC,sBAAsB;IACtBC,aAAa;IACbC,qBAAqB;IACrBC;EACF,CAAC,GAAGnB,WAAW,CAAC,CAAC;EACjB;EACA,MAAMoB,MAAM,GAAGf,SAAS,CAAC,CAAC;;EAE1B;EACA;EACA;EACAE,SAAS,CAAC,MAAM;IACd,IAAIS,sBAAsB,EAAE;MAC1BC,aAAa,CAAC,CAAC;IACjB;EACF,CAAC,EAAE,CAACA,aAAa,EAAED,sBAAsB,CAAC,CAAC;;EAE3C;EACA,MAAMK,SAAS,GAAGf,WAAW;EAC3B;EACA,SAASgB,aAAaA,CAACC,KAA0B,EAAE;IACjD,IAAI;MACFxB,QAAQ,CAACyB,KAAK,CAAC,IAAI,EAAEF,aAAa,CAACG,IAAI,EAAEF,KAAK,EAAEG,WAAW,EAAEC,IAAI,CAAC;MAClE,MAAMC,OAAO,GAAGC,IAAI,CAACC,KAAK,CAACP,KAAK,CAACG,WAAW,CAACC,IAAI,CAAuB;MAExE,QAAQC,OAAO,CAACG,IAAI;QAClB,KAAK,SAAS;UAAE;YACdhC,QAAQ,CAAC6B,OAAO,CAACI,OAAO,CAACC,KAAK,CAAC,CAC7B,KAAK,EACLL,OAAO,CAACI,OAAO,CAACE,IAAI,CAAC,CAAC,CAAC,EACvB,GAAGN,OAAO,CAACI,OAAO,CAACE,IAAI,CAACC,KAAK,CAAC,CAAC,CACjC,CAAC;YACD;UACF;QACA,KAAK,OAAO;UAAE;YACZpB,kBAAkB,CAAC,IAAI,CAAC;YACxB;UACF;QACA,KAAK,wBAAwB;UAAE;YAC7B;YACA,MAAMqB,QAAQ,GAAGlB,qBAAqB,CAAC;cACrCmB,QAAQ,EAAET,OAAO,CAACI,OAAO,CAACK;YAC5B,CAAC,CAAC,GAAGT,OAAO,CAACI,OAAO,CAACM,SAAS,CAAC;YAC/B;YACA,IAAIlC,uBAAuB,CAACgC,QAAQ,CAAC,EAAE;cACrC;cAAEA,QAAQ,CAAgCG,UAAU,CAClDX,OAAO,CAACI,OAAO,CAACT,KAClB,CAAC;YACH;YACA,IAAIpB,2BAA2B,CAACiC,QAAQ,CAAC,EAAE;cACzC;cAAEA,QAAQ,CAAoCI,cAAc,CAC1DZ,OAAO,CAACI,OAAO,CAACT,KAClB,CAAC;YACH;YACA,IAAIrB,6BAA6B,CAACkC,QAAQ,CAAC,EAAE;cAC3C;cAAEA,QAAQ,CAAsCK,aAAa,CAC3Db,OAAO,CAACI,OAAO,CAACT,KAClB,CAAC;YACH;YACA,IAAItB,gCAAgC,CAACmC,QAAQ,CAAC,EAAE;cAC9C;cACEA,QAAQ,CACRM,eAAe,CAACd,OAAO,CAACI,OAAO,CAACT,KAAK,CAAC;YAC1C;YACA;UACF;QACA,KAAK,yBAAyB;UAAE;YAC9BJ,qCAAqC,CAAC;cACpCwB,SAAS,EAAEf,OAAO,CAACI,OAAO,CAACW,SAAS;cACpCC,MAAM,EAAEhB,OAAO,CAACI,OAAO,CAACY;YAC1B,CAAC,CAAC;YACF;UACF;MACF;IACF,CAAC,CAAC,OAAOC,KAAU,EAAE;MACnB9C,QAAQ,CAAC8C,KAAK,CAAC,IAAI,EAAEvB,aAAa,CAACG,IAAI,EAAEoB,KAAK,CAACjB,OAAO,CAAC;IACzD;EACF,CAAC,EACD,CACEb,kBAAkB,EAClBG,qBAAqB,EACrBC,qCAAqC,CAEzC,CAAC;EAED,oBACER,KAAA,CAACf,IAAI;IAACkD,KAAK,EAAE1B,MAAM,CAAC2B,SAAU;IAAAlC,QAAA,gBAC5BJ,IAAA,CAACZ,OAAO;MACNmD,GAAG,EAAElC,UAAW;MAChBgC,KAAK,EAAE1B,MAAM,CAAC6B,OAAQ;MACtBC,eAAe,EAAE,CAAC,GAAG,CAAE;MACvBC,iBAAiB,EAAE,IAAK;MACxBC,eAAe,EAAE,IAAK;MACtBC,iBAAiB,EAAE,IAAK;MACxBC,aAAa,EAAE,KAAM;MACrBC,gCAAgC,EAAE,IAAK;MACvCC,gBAAgB,EAAE,QAAS;MAC3BnC,SAAS,EAAEA,SAAU;MACrBoC,MAAM,EAAE;QAAEC,IAAI,EAAE5D;MAAoB;IAAE,CACvC,CAAC,EACDe,QAAQ;EAAA,CACL,CAAC;AAEX,CAAC;AAED,eAAeD,WAAW","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ export {};
4
+ //# sourceMappingURL=MapProvider.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../../../src","sources":["react-native/components/MapProvider/MapProvider.types.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ import createWebObjectAsComponent from 'react-native-maplibre-gl-js/react-native/components-factory/createWebObjectAsComponent';
4
+ /**
5
+ * MapLibre Marker view.
6
+ * @see {@link https://maplibre.org/maplibre-gl-js/docs/API/classes/Marker/ MapLibre GL JS docs}
7
+ * @group Components
8
+ */
9
+ const Marker = createWebObjectAsComponent('marker');
10
+ export default Marker;
11
+ //# sourceMappingURL=Marker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createWebObjectAsComponent","Marker"],"sourceRoot":"../../../../../src","sources":["react-native/components/Marker/Marker.tsx"],"mappings":";;AAAA,OAAOA,0BAA0B,MAAM,wFAAwF;AAM/H;AACA;AACA;AACA;AACA;AACA,MAAMC,MAAM,GAAGD,0BAA0B,CAAyB,QAAQ,CAAC;AAE3E,eAAeC,MAAM","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ export {};
4
+ //# sourceMappingURL=Marker.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../../../src","sources":["react-native/components/Marker/Marker.types.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ import createWebObjectAsComponent from 'react-native-maplibre-gl-js/react-native/components-factory/createWebObjectAsComponent';
4
+
5
+ /**
6
+ * MapLibre Popup view.
7
+ * @see {@link https://maplibre.org/maplibre-gl-js/docs/API/classes/Popup/ MapLibre GL JS docs}
8
+ * @group Components
9
+ */
10
+ const Popup = createWebObjectAsComponent('popup');
11
+ export default Popup;
12
+ //# sourceMappingURL=Popup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createWebObjectAsComponent","Popup"],"sourceRoot":"../../../../../src","sources":["react-native/components/Popup/Popup.tsx"],"mappings":";;AAIA,OAAOA,0BAA0B,MAAM,wFAAwF;;AAE/H;AACA;AACA;AACA;AACA;AACA,MAAMC,KAAK,GAAGD,0BAA0B,CAAuB,OAAO,CAAC;AAEvE,eAAeC,KAAK","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ export {};
4
+ //# sourceMappingURL=Popup.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../../../src","sources":["react-native/components/Popup/Popup.types.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ import { forwardRef, useId } from 'react';
4
+ import useWebObjectMountOnLaunch from 'react-native-maplibre-gl-js/react-native/components-factory/hooks/useWebObjectMountOnLaunch';
5
+ import useWebObjectMethodsProxy from 'react-native-maplibre-gl-js/react-native/components-factory/hooks/useWebObjectMethodsProxy';
6
+ const createWebObjectAsComponent = objectType => {
7
+ return /*#__PURE__*/forwardRef((props, ref) => {
8
+ // UID of the web object.
9
+ const id = useId();
10
+ // Mount the web object on launch.
11
+ useWebObjectMountOnLaunch(props, id, objectType);
12
+ // Forward a method call on the RN object to the web object.
13
+ useWebObjectMethodsProxy(ref, id);
14
+ // TODO needed?
15
+ //useWebObjectOptionsUpdater<Options, Listener>(
16
+ // props, id, dispatchMessage
17
+ //)
18
+
19
+ return null;
20
+ });
21
+ };
22
+ export default createWebObjectAsComponent;
23
+ //# sourceMappingURL=createWebObjectAsComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["forwardRef","useId","useWebObjectMountOnLaunch","useWebObjectMethodsProxy","createWebObjectAsComponent","objectType","props","ref","id"],"sourceRoot":"../../../../src","sources":["react-native/components-factory/createWebObjectAsComponent.ts"],"mappings":";;AAAA,SAASA,UAAU,EAAEC,KAAK,QAAQ,OAAO;AAOzC,OAAOC,yBAAyB,MAAM,6FAA6F;AACnI,OAAOC,wBAAwB,MAAM,4FAA4F;AAEjI,MAAMC,0BAA0B,GAI9BC,UAAyB,IACU;EACnC,oBAAOL,UAAU,CAAa,CAACM,KAAK,EAAEC,GAAG,KAAK;IAC5C;IACA,MAAMC,EAAE,GAAGP,KAAK,CAAC,CAAC;IAClB;IACAC,yBAAyB,CAAQI,KAAK,EAAEE,EAAE,EAAEH,UAAU,CAAC;IACvD;IACAF,wBAAwB,CAAMI,GAAG,EAAEC,EAAE,CAAC;IACtC;IACA;IACA;IACA;;IAEA,OAAO,IAAI;EACb,CAAC,CAAC;AACJ,CAAC;AAED,eAAeJ,0BAA0B","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ export {};
4
+ //# sourceMappingURL=createWebObjectAsComponent.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../../src","sources":["react-native/components-factory/createWebObjectAsComponent.types.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ import { useCallback, useImperativeHandle, useMemo } from 'react';
4
+ import useMapAtoms from 'react-native-maplibre-gl-js/react-native/hooks/atoms/useMapAtoms';
5
+ /**
6
+ * Create a proxy to call the methods of the corresponding web world object,
7
+ * then expose it as the given `ref`.
8
+ * @param ref - A React ref object that will be updated to point to the web
9
+ * methods proxy.
10
+ * @param objectId - The ID of the web object that owns the method.
11
+ */
12
+ export const useWebObjectMethodsProxy = (ref, objectId) => {
13
+ // States.
14
+ // - Global.
15
+ const {
16
+ dispatchMessage,
17
+ setWebObjectPendingMethodResponse
18
+ } = useMapAtoms();
19
+ const createProxy = useCallback(() => {
20
+ return new Proxy({}, {
21
+ get(_, propKey) {
22
+ if (propKey === 'getId') {
23
+ return () => objectId;
24
+ }
25
+ return (...args) => {
26
+ return new Promise(resolve => {
27
+ // TODO generator.
28
+ const requestId = Math.random().toString(36).slice(2, 11);
29
+ // Store the resolver as a pending response.
30
+ setWebObjectPendingMethodResponse({
31
+ requestId,
32
+ resolve
33
+ });
34
+ // Send the method call message to the WebView.
35
+ dispatchMessage({
36
+ type: 'webObjectMethodCall',
37
+ payload: {
38
+ requestId,
39
+ objectId,
40
+ method: propKey,
41
+ args
42
+ }
43
+ });
44
+ });
45
+ };
46
+ }
47
+ });
48
+ }, [objectId, dispatchMessage, setWebObjectPendingMethodResponse]);
49
+ const methodsProxy = useMemo(() => createProxy(), [createProxy]);
50
+ // Expose the web methods as the component methods.
51
+ useImperativeHandle(ref, () => methodsProxy);
52
+ };
53
+ export default useWebObjectMethodsProxy;
54
+ //# sourceMappingURL=useWebObjectMethodsProxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useCallback","useImperativeHandle","useMemo","useMapAtoms","useWebObjectMethodsProxy","ref","objectId","dispatchMessage","setWebObjectPendingMethodResponse","createProxy","Proxy","get","_","propKey","args","Promise","resolve","requestId","Math","random","toString","slice","type","payload","method","methodsProxy"],"sourceRoot":"../../../../../src","sources":["react-native/components-factory/hooks/useWebObjectMethodsProxy.ts"],"mappings":";;AAAA,SAEEA,WAAW,EACXC,mBAAmB,EACnBC,OAAO,QACF,OAAO;AACd,OAAOC,WAAW,MAAM,kEAAkE;AAG1F;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,wBAAwB,GAAGA,CACtCC,GAAsB,EACtBC,QAAgB,KACb;EACH;EACA;EACA,MAAM;IAAEC,eAAe;IAAEC;EAAkC,CAAC,GAAGL,WAAW,CAAC,CAAC;EAE5E,MAAMM,WAAW,GAAGT,WAAW,CAAC,MAAW;IACzC,OAAO,IAAIU,KAAK,CACd,CAAC,CAAC,EACF;MACEC,GAAGA,CAACC,CAAC,EAAEC,OAAO,EAAE;QACd,IAAIA,OAAO,KAAK,OAAO,EAAE;UACvB,OAAO,MAAMP,QAAQ;QACvB;QACA,OAAO,CAAC,GAAGQ,IAAW,KAAK;UACzB,OAAO,IAAIC,OAAO,CAAEC,OAAO,IAAK;YAC9B;YACA,MAAMC,SAAS,GAAGC,IAAI,CAACC,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,EAAE,CAAC,CAACC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;YACzD;YACAb,iCAAiC,CAAC;cAAES,SAAS;cAAED;YAAQ,CAAC,CAAC;YACzD;YACAT,eAAe,CAAC;cACde,IAAI,EAAE,qBAAqB;cAC3BC,OAAO,EAAE;gBACPN,SAAS;gBACTX,QAAQ;gBACRkB,MAAM,EAAEX,OAAiB;gBACzBC;cACF;YACF,CAAC,CAAC;UACJ,CAAC,CAAC;QACJ,CAAC;MACH;IACF,CACF,CAAC;EACH,CAAC,EAAE,CAACR,QAAQ,EAAEC,eAAe,EAAEC,iCAAiC,CAAC,CAAC;EAElE,MAAMiB,YAAY,GAAGvB,OAAO,CAAC,MAAMO,WAAW,CAAC,CAAC,EAAE,CAACA,WAAW,CAAC,CAAC;EAChE;EACAR,mBAAmB,CAACI,GAAG,EAAE,MAAMoB,YAAY,CAAC;AAC9C,CAAC;AAED,eAAerB,wBAAwB","ignoreList":[]}
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ import { useCallback, useEffect, useRef } from 'react';
4
+ import useMapAtoms from 'react-native-maplibre-gl-js/react-native/hooks/atoms/useMapAtoms';
5
+ /**
6
+ * Mount the web object once the React Native one is mounted.
7
+ * @param props - The RN object props.
8
+ * @param objectId - The ID of the web object that owns the method.
9
+ * @param objectType - The type of the associated web object.
10
+ */
11
+ const useWebObjectMountOnLaunch = (props, objectId, objectType) => {
12
+ // Refs.
13
+ const isMounted = useRef(false);
14
+ // States.
15
+ // - Global.
16
+ const {
17
+ isWebWorldReady,
18
+ dispatchMessage,
19
+ setWebObjectListeners,
20
+ deleteWebObjectListeners
21
+ } = useMapAtoms();
22
+ const mount = useCallback(() => {
23
+ // Mount the component as a web object on the web world.
24
+ dispatchMessage({
25
+ type: `webObjectMount`,
26
+ payload: {
27
+ objectId: objectId,
28
+ objectType,
29
+ options: props.options ?? {},
30
+ listeners: props.listeners ?? {}
31
+ }
32
+ });
33
+ // Register listeners on event from the web world.
34
+ setWebObjectListeners({
35
+ objectId: objectId,
36
+ listeners: props.listeners ?? {}
37
+ });
38
+ isMounted.current = true;
39
+ }, [objectId, objectType, props.options, props.listeners, dispatchMessage, setWebObjectListeners]);
40
+ const unmount = useCallback(() => {
41
+ dispatchMessage({
42
+ type: `webObjectUnmount`,
43
+ payload: {
44
+ objectId
45
+ }
46
+ });
47
+ deleteWebObjectListeners({
48
+ objectId
49
+ });
50
+ isMounted.current = false;
51
+ }, [objectId, dispatchMessage, deleteWebObjectListeners]);
52
+
53
+ // On mount/unmount update the web object.
54
+ useEffect(() => {
55
+ if (!isWebWorldReady) {
56
+ return;
57
+ }
58
+ if (!isMounted.current) {
59
+ mount();
60
+ }
61
+ // TODO verify if we unmount here? it sure that it must not be in this
62
+ // use effect, otherwise on start if mount then unmount then mount, but
63
+ // we may have to unmount in another effect
64
+ //return unmount
65
+ }, [objectId, isWebWorldReady, dispatchMessage, props, unmount, mount]);
66
+ };
67
+ export default useWebObjectMountOnLaunch;
68
+ //# sourceMappingURL=useWebObjectMountOnLaunch.js.map