Skip to content

Commit

Permalink
Fix - iOS NativeUserLocation puckBearing logic typo and puck image up…
Browse files Browse the repository at this point in the history
…dates not being applied properly (#3352)

* Update RNMBXNativeUserLocation.swift

- Fixed incorrect puckBearing name in switch case
- Resolved warnings in Xcode
- Fixed puck images not being fetched after initial addToMap
- Fixed puck images not being correctly applied when changed on the fly

* Update ios/RNMBX/RNMBXNativeUserLocation.swift

Co-authored-by: Miklós Fazekas <[email protected]>

* Update ios/RNMBX/RNMBXNativeUserLocation.swift

Co-authored-by: Miklós Fazekas <[email protected]>

---------

Co-authored-by: Miklós Fazekas <[email protected]>
  • Loading branch information
mysport12 and mfazekas authored Feb 5, 2024
1 parent 12e37ac commit 3a285c2
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions ios/RNMBX/RNMBXNativeUserLocation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class RNMBXNativeUserLocation: UIView, RNMBXMapComponent {
case shadow
}

var imageNames: [PuckImagePart: String] = [:]
var imageNames: [PuckImagePart: String?] = [:]
var subscriptions: [PuckImagePart: ImageManager.Subscription] = [:]
var images: [PuckImagePart: UIImage] = [:]

Expand Down Expand Up @@ -63,12 +63,12 @@ public class RNMBXNativeUserLocation: UIView, RNMBXMapComponent {
switch(value) {
case "heading":
_puckBearing = .heading
case "coures":
case "course":
_puckBearing = .course
case nil:
_puckBearing = nil
default:
Logger.error("RNMBXNativeUserLocation puckBearing is uncrecognized: \(value)")
Logger.error("RNMBXNativeUserLocation puckBearing is uncrecognized: \(optional: value)")
_puckBearing = nil
}
}
Expand All @@ -87,18 +87,8 @@ public class RNMBXNativeUserLocation: UIView, RNMBXMapComponent {

func imageNameUpdated(_ image: PuckImagePart, _ name: String?) {
imageNames[image] = name
if let subscription = subscriptions[image] {
subscription.cancel()
subscriptions.removeValue(forKey: image)
}

guard let name = name else {
imageUpdated(image, nil)
return
}

if let imageManager = imageManager {
subscribe(imageManager, image, name)
if let map = self.map {
_fetchImages(map)
}
}

Expand Down Expand Up @@ -132,11 +122,11 @@ public class RNMBXNativeUserLocation: UIView, RNMBXMapComponent {
return Value.constant(0.0)
}
default:
Logger.error("toDoubleValue: \(name): has unknown type: \(type(of:value)) \(value) ")
Logger.error("toDoubleValue: \(name): has unknown type: \(type(of:value)) \(optional: value) ")
return .constant(1.0)
}
}

func _apply() {
guard let map = self.map else {
return
Expand All @@ -145,10 +135,6 @@ public class RNMBXNativeUserLocation: UIView, RNMBXMapComponent {
Logger.error("RNMBXNativeUserLocation mapView was nil")
return
}
_apply(mapView)
}

func _apply(_ mapView: MapView) {
guard let location = mapView.location else {
Logger.error("RNMBXNativeUserLocation location was nil")
return
Expand Down Expand Up @@ -195,7 +181,7 @@ public class RNMBXNativeUserLocation: UIView, RNMBXMapComponent {
pulsingConfig.radius = .constant(radius.doubleValue)
}

if let color = pulsing["color"] as? Any {
if let color = pulsing["color"] {
if let uicolor = RCTConvert.uiColor(color) {
pulsingConfig.color = uicolor
} else {
Expand Down Expand Up @@ -264,8 +250,14 @@ extension RNMBXNativeUserLocation {
func _fetchImages(_ map: RNMBXMapView) {
if let style = map.mapView?.mapboxMap?.style {
imageNames.forEach { (part, name) in
if style.imageExists(withId: name), let image = style.image(withId: name) {
images[part] = image
if let name = name {
if style.imageExists(withId: name), let image = style.image(withId: name) {
images[part] = image
} else {
images.removeValue(forKey: part)
}
} else {
images.removeValue(forKey: part)
}
}
}
Expand All @@ -274,7 +266,9 @@ extension RNMBXNativeUserLocation {
removeSubscriptions()
self.imageManager = imageManager
imageNames.forEach { (part,name) in
subscribe(imageManager, part, name)
if let name = name {
subscribe(imageManager, part, name)
}
}
}

Expand Down

0 comments on commit 3a285c2

Please sign in to comment.