expo-gaode-map 1.1.3 → 1.1.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.
|
@@ -27,6 +27,18 @@ import expo.modules.gaodemap.overlays.*
|
|
|
27
27
|
@Suppress("ViewConstructor")
|
|
28
28
|
class ExpoGaodeMapView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* 拦截 React Native 的 ViewManager 操作
|
|
32
|
+
* 重写 requestLayout 防止在移除视图时触发布局异常
|
|
33
|
+
*/
|
|
34
|
+
override fun requestLayout() {
|
|
35
|
+
try {
|
|
36
|
+
super.requestLayout()
|
|
37
|
+
} catch (e: Exception) {
|
|
38
|
+
Log.e(TAG, "requestLayout 异常被捕获", e)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
30
42
|
companion object {
|
|
31
43
|
private const val TAG = "ExpoGaodeMapView"
|
|
32
44
|
}
|
|
@@ -504,12 +516,23 @@ class ExpoGaodeMapView(context: Context, appContext: AppContext) : ExpoView(cont
|
|
|
504
516
|
|
|
505
517
|
/**
|
|
506
518
|
* 添加子视图时自动连接到地图
|
|
519
|
+
*
|
|
520
|
+
* 关键修复:MarkerView 不进入视图层级,但要确保 React Native 追踪正确
|
|
507
521
|
*/
|
|
508
522
|
override fun addView(child: View?, index: Int) {
|
|
509
523
|
if (child is MarkerView) {
|
|
510
|
-
//
|
|
524
|
+
// ✅ MarkerView 不加入视图层级
|
|
511
525
|
child.setMap(aMap)
|
|
512
526
|
markerViews.add(child)
|
|
527
|
+
Log.d(TAG, "✅ MarkerView 已添加到特殊列表(不在视图层级中),数量: ${markerViews.size}")
|
|
528
|
+
// ⚠️ 不调用 super.addView,所以 React Native 不会追踪它
|
|
529
|
+
return
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
// ⚠️ 如果是 MapView 本身,必须添加
|
|
533
|
+
if (child is com.amap.api.maps.MapView) {
|
|
534
|
+
super.addView(child, index)
|
|
535
|
+
Log.d(TAG, "✅ MapView 已添加")
|
|
513
536
|
return
|
|
514
537
|
}
|
|
515
538
|
|
|
@@ -533,22 +556,73 @@ class ExpoGaodeMapView(context: Context, appContext: AppContext) : ExpoView(cont
|
|
|
533
556
|
*/
|
|
534
557
|
override fun removeView(child: View?) {
|
|
535
558
|
if (child is MarkerView) {
|
|
536
|
-
// 从 MarkerView
|
|
559
|
+
// 从 MarkerView 列表中移除并清理
|
|
537
560
|
markerViews.remove(child)
|
|
561
|
+
child.removeMarker()
|
|
562
|
+
Log.d(TAG, "✅ MarkerView 已清理,当前 markerViews 数量: ${markerViews.size}")
|
|
538
563
|
return
|
|
539
564
|
}
|
|
540
|
-
|
|
565
|
+
|
|
566
|
+
try {
|
|
567
|
+
super.removeView(child)
|
|
568
|
+
} catch (e: Exception) {
|
|
569
|
+
Log.e(TAG, "removeView 异常", e)
|
|
570
|
+
}
|
|
541
571
|
}
|
|
542
572
|
|
|
543
573
|
/**
|
|
544
574
|
* 按索引移除视图
|
|
575
|
+
*
|
|
576
|
+
* 终极修复:完全忽略所有无效的移除请求
|
|
545
577
|
*/
|
|
546
578
|
override fun removeViewAt(index: Int) {
|
|
547
|
-
|
|
548
|
-
|
|
579
|
+
try {
|
|
580
|
+
val actualChildCount = super.getChildCount()
|
|
581
|
+
|
|
582
|
+
Log.d(TAG, "removeViewAt 调用: index=$index, super.childCount=$actualChildCount")
|
|
583
|
+
|
|
584
|
+
// ✅ 如果没有子视图,直接返回
|
|
585
|
+
if (actualChildCount == 0) {
|
|
586
|
+
Log.w(TAG, "⚠️ 无子视图,忽略: index=$index")
|
|
587
|
+
return
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
// ✅ 索引越界,直接返回
|
|
591
|
+
if (index < 0 || index >= actualChildCount) {
|
|
592
|
+
Log.w(TAG, "⚠️ 索引越界,忽略: index=$index, childCount=$actualChildCount")
|
|
593
|
+
return
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
// 检查要移除的视图类型
|
|
597
|
+
val child = super.getChildAt(index)
|
|
598
|
+
|
|
599
|
+
// ❌ MapView 绝对不能移除
|
|
600
|
+
if (child is com.amap.api.maps.MapView) {
|
|
601
|
+
Log.e(TAG, "❌ 阻止移除 MapView!index=$index")
|
|
602
|
+
// 不移除,直接返回
|
|
603
|
+
return
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// MarkerView 特殊处理(虽然理论上不应该出现在这里)
|
|
607
|
+
if (child is MarkerView) {
|
|
608
|
+
Log.d(TAG, "⚠️ 发现 MarkerView 在视图层级中,使用 removeView")
|
|
609
|
+
removeView(child)
|
|
610
|
+
return
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
// 正常移除其他视图
|
|
549
614
|
super.removeViewAt(index)
|
|
550
|
-
|
|
551
|
-
|
|
615
|
+
Log.d(TAG, "✅ 成功移除视图: index=$index")
|
|
616
|
+
|
|
617
|
+
} catch (e: IllegalArgumentException) {
|
|
618
|
+
// 索引异常,静默忽略
|
|
619
|
+
Log.w(TAG, "⚠️ 索引异常,已忽略: ${e.message}")
|
|
620
|
+
} catch (e: IndexOutOfBoundsException) {
|
|
621
|
+
// 越界异常,静默忽略
|
|
622
|
+
Log.w(TAG, "⚠️ 越界异常,已忽略: ${e.message}")
|
|
623
|
+
} catch (e: Exception) {
|
|
624
|
+
// 其他所有异常,静默忽略
|
|
625
|
+
Log.e(TAG, "⚠️ 移除视图异常,已忽略", e)
|
|
552
626
|
}
|
|
553
627
|
}
|
|
554
628
|
|
|
@@ -12,6 +12,12 @@ class ExpoGaodeMapViewModule : Module() {
|
|
|
12
12
|
|
|
13
13
|
View(ExpoGaodeMapView::class) {
|
|
14
14
|
Events("onMapPress", "onMapLongPress", "onLoad", "onLocation", "onMarkerPress", "onMarkerDragStart", "onMarkerDrag", "onMarkerDragEnd", "onCirclePress", "onPolygonPress", "onPolylinePress")
|
|
15
|
+
|
|
16
|
+
// ✅ 关键修复:拦截 React Native 的视图操作异常
|
|
17
|
+
OnViewDestroys { view: ExpoGaodeMapView ->
|
|
18
|
+
// 在视图销毁时不做任何抛出异常的操作
|
|
19
|
+
android.util.Log.d("ExpoGaodeMapViewModule", "视图正在销毁,清理资源")
|
|
20
|
+
}
|
|
15
21
|
|
|
16
22
|
Prop<Int>("mapType") { view, type ->
|
|
17
23
|
view.mapType = type
|