Skip to content

Commit

Permalink
fix(ios,v11): some RNMBX_11 were destroyed during the merge of #3136
Browse files Browse the repository at this point in the history
  • Loading branch information
mfazekas committed Oct 27, 2023
1 parent 1b44d3e commit a775fc3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
22 changes: 17 additions & 5 deletions ios/RNMBX/RNMBXImages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ protocol RNMBXImageSetter : AnyObject {
func addImage(name: String, image: UIImage, sdf: Bool?, stretchX: [[NSNumber]], stretchY: [[NSNumber]], content: [NSNumber]?, log: String) -> Bool
}

func hasImage(style: Style, name: String) -> Bool {
#if RNMBX_11
return style.imageExists(withId: name)
#else
return (style.styleManager.getStyleImage(forImageId: name) != nil)
#endif
}

#if RNMBX_11
typealias StyleImageMissingPayload = StyleImageMissing
#endif

open class RNMBXImages : UIView, RNMBXMapComponent {

@objc public weak var bridge : RCTBridge! = nil
Expand Down Expand Up @@ -104,9 +116,9 @@ open class RNMBXImages : UIView, RNMBXMapComponent {
if !sameImage(oldValue: oldImages[name], newValue: images[name]) {
missingImages[name] = images[name]
} else {
if style.styleManager.getStyleImage(forImageId: name) == nil {
if hasImage(style: style, name: name) {
logged("RNMBXImages.addImagePlaceholder") {
try? style.addImage(placeholderImage, id: name, stretchX: [], stretchY: [])
try style.addImage(placeholderImage, id: name, stretchX: [], stretchY: [])
missingImages[name] = images[name]
}
}
Expand All @@ -125,7 +137,7 @@ open class RNMBXImages : UIView, RNMBXMapComponent {
}
}

public func addMissingImageToStyle(style: Style, imageName: String) -> Bool {
internal func addMissingImageToStyle(style: Style, imageName: String) -> Bool {
if let nativeImage = nativeImageInfos.first(where: { $0.name == imageName }) {
addNativeImages(style: style, nativeImages: [nativeImage])
return true
Expand All @@ -138,7 +150,7 @@ open class RNMBXImages : UIView, RNMBXMapComponent {
return false
}

public func sendImageMissingEvent(imageName: String, payload: StyleImageMissingPayload) {
internal func sendImageMissingEvent(imageName: String, payload: StyleImageMissingPayload) {
let payload = ["imageKey":imageName]
let event = RNMBXEvent(type: .imageMissing, payload: payload)
if let onImageMissing = onImageMissing {
Expand Down Expand Up @@ -231,7 +243,7 @@ open class RNMBXImages : UIView, RNMBXMapComponent {
func addNativeImages(style: Style, nativeImages: [NativeImageInfo]) {
for imageInfo in nativeImages {
let imageName = imageInfo.name
if style.styleManager.getStyleImage(forImageId: imageInfo.name) == nil {
if hasImage(style: style, name:imageName) {
if let image = UIImage(named: imageName) {
logged("RNMBXImage.addNativeImage: \(imageName)") {
try style.addImage(image, id: imageName, sdf: imageInfo.sdf,
Expand Down
12 changes: 11 additions & 1 deletion ios/RNMBX/RNMBXLight.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import MapboxMaps

#if RNMBX_11
typealias Light = FlatLight
#endif

@objc(RNMBXLight)
public class RNMBXLight: UIView, RNMBXMapComponent {
@objc public weak var bridge : RCTBridge! = nil
Expand All @@ -19,7 +23,13 @@ public class RNMBXLight: UIView, RNMBXMapComponent {
func apply(light: Light) {
let lightData = try! JSONEncoder().encode(light)
let lightDictionary = try! JSONSerialization.jsonObject(with: lightData)
try! self.map.style.setLight(properties: lightDictionary as! [String:Any])
logged("RNMBXLight.apply") {
#if RNMBX_11
try self.map.setLights(light)
#else
try! self.map.style.setLight(properties: lightDictionary as! [String:Any])
#endif
}
}

func addStyles() {
Expand Down
4 changes: 4 additions & 0 deletions ios/RNMBX/RNMBXNativeUserLocation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ public class RNMBXNativeUserLocation : UIView, RNMBXMapComponent {
func _applySettings(_ map: RNMBXMapView) {
map.location.options.puckType = .puck2D(.makeDefault(showBearing: iosShowsUserHeadingIndicator))
if (iosShowsUserHeadingIndicator) {
#if RNMBX_11
map.location.options.puckBearing = .heading
#else
map.location.options.puckBearingSource = .heading
#endif
map.location.options.puckBearingEnabled = true
} else {
map.location.options.puckBearingEnabled = false
Expand Down

0 comments on commit a775fc3

Please sign in to comment.