expo-gaode-map 2.2.42 → 2.2.43-next.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.
@@ -78,6 +78,8 @@ class MarkerView: ExpoView {
78
78
  private var pendingUpdateTask: DispatchWorkItem?
79
79
  /// 子视图变化后的延迟刷新任务
80
80
  private var pendingSubviewRefreshTask: DispatchWorkItem?
81
+ /// 子视图刷新代次,用于丢弃已经过期的主队列任务
82
+ private var childrenRefreshGeneration: UInt = 0
81
83
  /// 下一次主队列确认物理 detach 是否仍然成立
82
84
  private var pendingDetachCheckTask: DispatchWorkItem?
83
85
  /// 最近一次应用到 annotationView 的 children 结构签名
@@ -616,11 +618,19 @@ class MarkerView: ExpoView {
616
618
  return nil
617
619
  }
618
620
 
619
- private func refreshChildrenImageInPlace(invalidateChildrenCache: Bool = false, cacheImage: Bool = true) {
621
+ private func refreshChildrenImageInPlace(
622
+ invalidateChildrenCache: Bool = false,
623
+ cacheImage: Bool = true,
624
+ expectedGeneration: UInt? = nil
625
+ ) {
620
626
  guard !isRemoving else { return }
621
627
 
622
628
  let refresh = { [weak self] in
623
629
  guard let self = self, !self.isRemoving, !self.subviews.isEmpty else { return }
630
+ if let expectedGeneration,
631
+ self.childrenRefreshGeneration != expectedGeneration {
632
+ return
633
+ }
624
634
 
625
635
  if invalidateChildrenCache {
626
636
  self.lastRenderedChildrenSignature = nil
@@ -637,11 +647,19 @@ class MarkerView: ExpoView {
637
647
  let signature = self.childrenRenderSignature()
638
648
 
639
649
  if cacheImage, let cached = IconBitmapCache.shared.image(forKey: key) {
650
+ if let expectedGeneration,
651
+ self.childrenRefreshGeneration != expectedGeneration {
652
+ return
653
+ }
640
654
  self.applyChildrenImage(cached, to: targetView, signature: signature)
641
655
  return
642
656
  }
643
657
 
644
658
  if let generated = self.createImageFromSubviews(size: size, cacheImage: cacheImage) {
659
+ if let expectedGeneration,
660
+ self.childrenRefreshGeneration != expectedGeneration {
661
+ return
662
+ }
645
663
  self.applyChildrenImage(generated, to: targetView, signature: signature)
646
664
  return
647
665
  }
@@ -658,14 +676,30 @@ class MarkerView: ExpoView {
658
676
  }
659
677
  }
660
678
 
679
+ private func cancelPendingSubviewRefresh() {
680
+ childrenRefreshGeneration &+= 1
681
+ pendingSubviewRefreshTask?.cancel()
682
+ pendingSubviewRefreshTask = nil
683
+ }
684
+
661
685
  private func scheduleChildrenImageRefresh(
662
686
  invalidateChildrenCache: Bool = false,
663
687
  cacheImage: Bool = true
664
688
  ) {
665
- pendingSubviewRefreshTask?.cancel()
689
+ cancelPendingSubviewRefresh()
690
+ let scheduledGeneration = childrenRefreshGeneration
666
691
 
667
692
  let task = DispatchWorkItem { [weak self] in
668
- self?.refreshChildrenImageInPlace(invalidateChildrenCache: invalidateChildrenCache, cacheImage: cacheImage)
693
+ guard let self = self,
694
+ self.childrenRefreshGeneration == scheduledGeneration else {
695
+ return
696
+ }
697
+ self.pendingSubviewRefreshTask = nil
698
+ self.refreshChildrenImageInPlace(
699
+ invalidateChildrenCache: invalidateChildrenCache,
700
+ cacheImage: cacheImage,
701
+ expectedGeneration: scheduledGeneration
702
+ )
669
703
  }
670
704
 
671
705
  pendingSubviewRefreshTask = task
@@ -879,7 +913,7 @@ class MarkerView: ExpoView {
879
913
  cancelPendingDetachCheck()
880
914
  pendingAddTask?.cancel(); pendingAddTask = nil
881
915
  pendingUpdateTask?.cancel(); pendingUpdateTask = nil
882
- pendingSubviewRefreshTask?.cancel(); pendingSubviewRefreshTask = nil
916
+ cancelPendingSubviewRefresh()
883
917
  cleanupAnnotationFromMap()
884
918
  onPermanentDetach?(self)
885
919
  onPermanentDetach = nil
@@ -941,10 +975,17 @@ class MarkerView: ExpoView {
941
975
  private func scheduleSubviewRefresh(allowFallbackToDefault: Bool) {
942
976
  guard superview != nil else { return }
943
977
 
944
- pendingSubviewRefreshTask?.cancel()
978
+ cancelPendingSubviewRefresh()
979
+ let scheduledGeneration = childrenRefreshGeneration
945
980
 
946
981
  let task = DispatchWorkItem { [weak self] in
947
- guard let self = self, !self.isRemoving, self.superview != nil else { return }
982
+ guard let self = self,
983
+ !self.isRemoving,
984
+ self.superview != nil,
985
+ self.childrenRefreshGeneration == scheduledGeneration else {
986
+ return
987
+ }
988
+ self.pendingSubviewRefreshTask = nil
948
989
  self.refreshAnnotationForSubviewChanges(allowFallbackToDefault: allowFallbackToDefault)
949
990
  }
950
991
 
@@ -1015,8 +1056,7 @@ class MarkerView: ExpoView {
1015
1056
  let refresh = { [weak self] in
1016
1057
  guard let self = self, let mapView = self.mapView else { return }
1017
1058
 
1018
- self.pendingSubviewRefreshTask?.cancel()
1019
- self.pendingSubviewRefreshTask = nil
1059
+ self.cancelPendingSubviewRefresh()
1020
1060
 
1021
1061
  if invalidateChildrenCache {
1022
1062
  self.lastRenderedChildrenSignature = nil
@@ -1419,7 +1459,7 @@ class MarkerView: ExpoView {
1419
1459
  // 取消待处理的任务
1420
1460
  pendingAddTask?.cancel()
1421
1461
  pendingUpdateTask?.cancel()
1422
- pendingSubviewRefreshTask?.cancel()
1462
+ cancelPendingSubviewRefresh()
1423
1463
  pendingDetachCheckTask?.cancel()
1424
1464
 
1425
1465
  if Thread.isMainThread {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-gaode-map",
3
- "version": "2.2.42",
3
+ "version": "2.2.43-next.0",
4
4
  "description": "Expo Modules AMap (Gaode Map) stack for Expo/React Native: Config Plugin, New Architecture support, maps, location, search, offline maps, and react-native-amap3d migration guidance.",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",