@maydon_tech/react-native-nitro-maps 0.2.2 → 0.2.4
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.
- package/android/src/main/kotlin/com/margelo/nitro/nitromap/NitroMap.kt +20 -0
- package/android/src/main/kotlin/com/margelo/nitro/nitromap/NitroMapPackage.kt +4 -3
- package/android/src/main/kotlin/com/margelo/nitro/nitromap/NitroMapViewManager.kt +34 -0
- package/android/src/main/kotlin/com/margelo/nitro/nitromap/providers/google/GoogleMapProvider.kt +4 -0
- package/android/src/main/res/values/ids.xml +4 -0
- package/package.json +1 -1
|
@@ -58,6 +58,26 @@ class HybridNitroMap(context: Context) : HybridNitroMapSpec() {
|
|
|
58
58
|
private var isDisposed = false
|
|
59
59
|
|
|
60
60
|
init {
|
|
61
|
+
// Tag container so the ViewManager can retrieve this instance for proper disposal
|
|
62
|
+
container.setTag(R.id.nitro_map_hybrid_view, this)
|
|
63
|
+
|
|
64
|
+
// Fabric/Yoga intercepts requestLayout() on managed views, so dynamically
|
|
65
|
+
// added children (the MapView) never get a proper measure/layout pass.
|
|
66
|
+
// Re-measure and lay out the MapView whenever the container's dimensions change.
|
|
67
|
+
container.addOnLayoutChangeListener { _, left, top, right, bottom, _, _, _, _ ->
|
|
68
|
+
currentMapView?.let { mv ->
|
|
69
|
+
val w = right - left
|
|
70
|
+
val h = bottom - top
|
|
71
|
+
if (w > 0 && h > 0) {
|
|
72
|
+
mv.measure(
|
|
73
|
+
View.MeasureSpec.makeMeasureSpec(w, View.MeasureSpec.EXACTLY),
|
|
74
|
+
View.MeasureSpec.makeMeasureSpec(h, View.MeasureSpec.EXACTLY)
|
|
75
|
+
)
|
|
76
|
+
mv.layout(0, 0, w, h)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
61
81
|
container.addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
|
|
62
82
|
override fun onViewAttachedToWindow(v: View) {
|
|
63
83
|
if (!isDisposed) {
|
|
@@ -6,11 +6,12 @@ import com.facebook.react.bridge.ReactApplicationContext
|
|
|
6
6
|
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
7
7
|
import com.facebook.react.uimanager.ViewManager
|
|
8
8
|
|
|
9
|
-
import com.margelo.nitro.nitromap.views.HybridNitroMapManager
|
|
10
|
-
|
|
11
9
|
/**
|
|
12
10
|
* React Native Package for NitroMap.
|
|
13
11
|
* Registers the ViewManager and loads the native C++ library.
|
|
12
|
+
*
|
|
13
|
+
* Uses NitroMapViewManager (our subclass) instead of the generated
|
|
14
|
+
* HybridNitroMapManager to add proper MapView disposal on onDropViewInstance.
|
|
14
15
|
*/
|
|
15
16
|
class NitroMapPackage : BaseReactPackage() {
|
|
16
17
|
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
@@ -22,7 +23,7 @@ class NitroMapPackage : BaseReactPackage() {
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
25
|
-
return listOf(
|
|
26
|
+
return listOf(NitroMapViewManager())
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
companion object {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
package com.margelo.nitro.nitromap
|
|
2
|
+
|
|
3
|
+
import android.util.Log
|
|
4
|
+
import android.view.View
|
|
5
|
+
import com.margelo.nitro.nitromap.views.HybridNitroMapManager
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Custom ViewManager that extends the Nitrogen-generated HybridNitroMapManager
|
|
9
|
+
* to add proper MapView lifecycle management.
|
|
10
|
+
*
|
|
11
|
+
* The generated manager doesn't call dispose() on the HybridNitroMap when the
|
|
12
|
+
* view is dropped, which leaks the MapView (GL surface, GoogleMap instance,
|
|
13
|
+
* coroutine scope, etc.). This subclass retrieves the HybridNitroMap via a
|
|
14
|
+
* View tag set in HybridNitroMap.init and calls dispose() before the view
|
|
15
|
+
* is released.
|
|
16
|
+
*/
|
|
17
|
+
class NitroMapViewManager : HybridNitroMapManager() {
|
|
18
|
+
|
|
19
|
+
companion object {
|
|
20
|
+
private const val TAG = "NitroMap"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
override fun onDropViewInstance(view: View) {
|
|
24
|
+
// Retrieve the HybridNitroMap from the tag and dispose it before
|
|
25
|
+
// the generated manager removes it from its internal views map.
|
|
26
|
+
val hybridMap = view.getTag(R.id.nitro_map_hybrid_view) as? HybridNitroMap
|
|
27
|
+
if (hybridMap != null) {
|
|
28
|
+
hybridMap.dispose()
|
|
29
|
+
view.setTag(R.id.nitro_map_hybrid_view, null)
|
|
30
|
+
Log.d(TAG, "ViewManager: disposed HybridNitroMap on drop")
|
|
31
|
+
}
|
|
32
|
+
super.onDropViewInstance(view)
|
|
33
|
+
}
|
|
34
|
+
}
|
package/android/src/main/kotlin/com/margelo/nitro/nitromap/providers/google/GoogleMapProvider.kt
CHANGED
|
@@ -71,6 +71,10 @@ class GoogleMapProvider(internal val context: Context) : MapProviderInterface {
|
|
|
71
71
|
// Resuming from detach — GoogleMap is still valid, just resume the MapView
|
|
72
72
|
mv.onStart()
|
|
73
73
|
mv.onResume()
|
|
74
|
+
// Force Fabric to re-layout the GL surface. After onStop/onStart the
|
|
75
|
+
// GL surface may be recreated, but Yoga won't trigger requestLayout for
|
|
76
|
+
// an already-measured view — resulting in a blank map.
|
|
77
|
+
mv.post { mv.requestLayout() }
|
|
74
78
|
Log.d(TAG, "MapView resumed — GoogleMap still valid")
|
|
75
79
|
return
|
|
76
80
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maydon_tech/react-native-nitro-maps",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "A high-performance React Native map library powered by Nitro Modules with support for Apple Maps, Google Maps, and Yandex Maps. Features native clustering, custom markers, and seamless cross-platform integration.",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|