@rnmapbox/maps 10.0.10-rc.2 → 10.0.11-rc.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.
@@ -7,7 +7,6 @@ protocol RCTMGLImageSetter : AnyObject {
7
7
  class RCTMGLImages : UIView, RCTMGLMapComponent {
8
8
 
9
9
  weak var bridge : RCTBridge! = nil
10
- var remoteImages : [String:String] = [:]
11
10
 
12
11
  weak var style: Style? = nil
13
12
 
@@ -15,7 +14,13 @@ class RCTMGLImages : UIView, RCTMGLMapComponent {
15
14
  var onImageMissing: RCTBubblingEventBlock? = nil
16
15
 
17
16
  @objc
18
- var images : [String:Any] = [:]
17
+ var images : [String:Any] = [:] {
18
+ didSet {
19
+ updateImages(images: images, oldImages: oldValue)
20
+ }
21
+ }
22
+
23
+ var loadedImages : Set<String> = []
19
24
 
20
25
  var imageViews: [RCTMGLImage] = []
21
26
 
@@ -24,7 +29,7 @@ class RCTMGLImages : UIView, RCTMGLMapComponent {
24
29
  didSet {
25
30
  nativeImageInfos = nativeImages.compactMap { decodeImage($0) }
26
31
  }
27
- };
32
+ }
28
33
 
29
34
  typealias NativeImageInfo = (name:String, sdf: Bool, stretchX:[(from:Float, to:Float)], stretchY:[(from:Float, to:Float)], content: (left:Float,top:Float,right:Float,bottom:Float)? );
30
35
  var nativeImageInfos: [NativeImageInfo] = []
@@ -57,7 +62,7 @@ class RCTMGLImages : UIView, RCTMGLMapComponent {
57
62
  map.images.append(self)
58
63
 
59
64
  self.addNativeImages(style: style, nativeImages: nativeImageInfos)
60
- self.addRemoteImages(style: style, remoteImages: images)
65
+ self.addImages(style: style, images: images, oldImages: [:])
61
66
  self.addImageViews(style: style, imageViews: imageViews)
62
67
  }
63
68
 
@@ -67,7 +72,21 @@ class RCTMGLImages : UIView, RCTMGLMapComponent {
67
72
  return true
68
73
  }
69
74
 
70
- func addRemoteImages(style: Style, remoteImages: [String: Any]) {
75
+ func sameImage(oldValue: Any?, newValue: Any?) -> Bool {
76
+ if let oldS = oldValue as? String, let newS = newValue as? String {
77
+ return oldS == newS
78
+ } else {
79
+ return false
80
+ }
81
+ }
82
+
83
+ func updateImages(images: [String:Any], oldImages: [String:Any]) {
84
+ if let style = self.style {
85
+ addImages(style: style, images: images, oldImages: oldImages)
86
+ }
87
+ }
88
+
89
+ func addImages(style: Style, images: [String: Any], oldImages: [String:Any]) {
71
90
  var missingImages : [String:Any] = [:]
72
91
 
73
92
  // Add image placeholder for images that are not yet available in the style. This way
@@ -78,17 +97,25 @@ class RCTMGLImages : UIView, RCTMGLMapComponent {
78
97
  //
79
98
  // See also: https://github.com/mapbox/mapbox-gl-native/pull/14253#issuecomment-478827792
80
99
 
81
- for imageName in remoteImages.keys {
82
- if style.styleManager.getStyleImage(forImageId: imageName) == nil {
83
- logged("RCTMGLImages.addImagePlaceholder") {
84
- try? style.addImage(placeholderImage, id: imageName, stretchX: [], stretchY: [])
85
- missingImages[imageName] = remoteImages[imageName]
100
+ for name in images.keys {
101
+ let newImage = oldImages[name] == nil
102
+ if oldImages[name] == nil || loadedImages.contains(name) || !sameImage(oldValue: oldImages[name], newValue: images[name]) {
103
+ let addPlaceholder = oldImages[name] == nil
104
+ if !sameImage(oldValue: oldImages[name], newValue: images[name]) {
105
+ missingImages[name] = images[name]
106
+ } else {
107
+ if style.styleManager.getStyleImage(forImageId: name) == nil {
108
+ logged("RCTMGLImages.addImagePlaceholder") {
109
+ try? style.addImage(placeholderImage, id: name, stretchX: [], stretchY: [])
110
+ missingImages[name] = images[name]
111
+ }
112
+ }
86
113
  }
87
114
  }
88
115
  }
89
116
 
90
117
  if missingImages.count > 0 {
91
- RCTMGLUtils.fetchImages(bridge, style: style, objects: missingImages, forceUpdate: true, callback: { })
118
+ RCTMGLUtils.fetchImages(bridge, style: style, objects: missingImages, forceUpdate: true, loaded: { name in self.loadedImages.insert(name) } ,callback: { })
92
119
  }
93
120
  }
94
121
 
@@ -104,8 +131,8 @@ class RCTMGLImages : UIView, RCTMGLMapComponent {
104
131
  return true
105
132
  }
106
133
 
107
- if let remoteImage = images[imageName] {
108
- addRemoteImages(style: style, remoteImages: [imageName: remoteImage])
134
+ if let image = images[imageName] {
135
+ addImages(style: style, images: [imageName: image], oldImages: [:])
109
136
  return true
110
137
  }
111
138
  return false
@@ -8,7 +8,7 @@ class RCTMGLUtils {
8
8
  RCTMGLImageQueue.sharedInstance.addImage(url, scale: scale, bridge: bridge, handler: callback)
9
9
  }
10
10
 
11
- static func fetchImages(_ bridge: RCTBridge, style: Style, objects: [String:Any], forceUpdate: Bool, callback: @escaping ()->Void) {
11
+ static func fetchImages(_ bridge: RCTBridge, style: Style, objects: [String:Any], forceUpdate: Bool, loaded: @escaping (_ name:String) -> Void, callback: @escaping ()->Void) {
12
12
  guard !objects.isEmpty else {
13
13
  callback()
14
14
  return
@@ -47,8 +47,8 @@ class RCTMGLUtils {
47
47
  DispatchQueue.main.async {
48
48
  if let image = image {
49
49
  logged("RCTMGLUtils.fetchImage-\(imageName)") {
50
- print("width=\(image.size.width) height=\(image.size.height) scale=\(image.scale) scale2=\(scale)")
51
50
  try style.addImage(image, id: imageName, sdf:sdf, stretchX: stretchX, stretchY: stretchY, content: content)
51
+ loaded(imageName)
52
52
  imageLoadedBlock()
53
53
  }
54
54
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rnmapbox/maps",
3
3
  "description": "A Mapbox react native module for creating custom maps",
4
- "version": "10.0.10-rc.2",
4
+ "version": "10.0.11-rc.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },