Skip to content

Commit

Permalink
resolve ambiguous expression issue introduced in Xcode 16 (#3562)
Browse files Browse the repository at this point in the history
  • Loading branch information
decomoraes authored Jul 3, 2024
1 parent 485dca8 commit 0c37ee8
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 88 deletions.
2 changes: 1 addition & 1 deletion ios/RNMBX/Extensions/Array+asExpressions.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import MapboxMaps

internal extension Array where Element == Any {
func asExpression() throws -> Expression? {
func asExpression() throws -> MapboxMaps.Expression? {
let filter = self
if filter.count > 0 {
let data = try JSONSerialization.data(withJSONObject: filter, options: .prettyPrinted)
Expand Down
74 changes: 37 additions & 37 deletions ios/RNMBX/RNMBXLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public class RNMBXLayer : UIView, RNMBXMapComponent, RNMBXSourceConsumer {
}
}
}

var style: Style? = nil

@objc public var filter : Array<Any>? = nil {
didSet { optionsChanged() }
}

@objc public var id: String! = nil {
willSet {
if id != nil && newValue != id {
Expand All @@ -58,7 +58,7 @@ public class RNMBXLayer : UIView, RNMBXMapComponent, RNMBXSourceConsumer {
@objc public var sourceID: String? = nil {
didSet { optionsChanged() }
}

@objc public var minZoomLevel : NSNumber? = nil {
didSet { optionsChanged() }
}
Expand All @@ -85,7 +85,7 @@ public class RNMBXLayer : UIView, RNMBXMapComponent, RNMBXSourceConsumer {
}
}
}

@objc public var layerIndex : NSNumber? = nil {
didSet {
if let layerIndex = layerIndex {
Expand All @@ -95,13 +95,13 @@ public class RNMBXLayer : UIView, RNMBXMapComponent, RNMBXSourceConsumer {
}
}
}

@objc public var slot: String? = nil {
didSet {
optionsChanged()
}
}

@objc weak var map: RNMBXMapView? = nil

deinit {
Expand All @@ -110,31 +110,31 @@ public class RNMBXLayer : UIView, RNMBXMapComponent, RNMBXSourceConsumer {
self.waitingForID = nil
}
}

var styleLayer: Layer? = nil

/// wearther we inserted the layer or we're referring to an existing layer
var existingLayer = false

// MARK: - RNMBXMapComponent
public func waitForStyleLoad() -> Bool {
return true
}

func removeAndReaddLayer() {
if let map = map, let style = style {
self.removeFromMap(style)
self.addToMap(map, style:style)
}
}

/**
addStyles - adds the styles defined by reactStyle to the current layer, but does not apply to the style to the map style
*/
func addStyles() {
fatalError("Subclasses need to implement the `addStyles()` method.")
}

func addStylesAndUpdate() {
guard styleLayer != nil else {
return
Expand All @@ -148,15 +148,15 @@ public class RNMBXLayer : UIView, RNMBXMapComponent, RNMBXSourceConsumer {
}
}
}

func makeLayer(style: Style) throws -> Layer {
fatalError("Subclasses need to implement the `makeLayer(style:)` method.")
}

func findLayer(style: Style, id: String) throws -> Layer {
return try style.layer(withId: id)
}

func layerType() -> Layer.Type {
fatalError("Subclasses need to implement the `layerType` method. \(self)")
}
Expand Down Expand Up @@ -188,7 +188,7 @@ public class RNMBXLayer : UIView, RNMBXMapComponent, RNMBXSourceConsumer {
return .default
}
}

func inserLayer(_ map: RNMBXMapView) {
if self.style == nil {
print("inserLayer but style is nil")
Expand All @@ -205,7 +205,7 @@ public class RNMBXLayer : UIView, RNMBXMapComponent, RNMBXSourceConsumer {
loggedApply(style: style)
}
}

func layerWithSourceID<T : Source>(in style: Style) throws -> T {
let result = try style.source(withId: self.sourceID!, type: T.self)
return result
Expand All @@ -217,9 +217,9 @@ public class RNMBXLayer : UIView, RNMBXMapComponent, RNMBXSourceConsumer {
}

func addedToMap() {

}

public func addToMap(_ map: RNMBXMapView, style: Style) {
self.map = map
self.style = style
Expand All @@ -239,7 +239,7 @@ public class RNMBXLayer : UIView, RNMBXMapComponent, RNMBXSourceConsumer {
} catch {
Logger.log(level: .error, message: "find/makeLayer failed for layer id=\(id)", error: error)
}

guard self.styleLayer != nil else {
Logger.log(level: .error, message: "find/makeLayer retuned nil for layer id=\(id)")
return
Expand All @@ -253,11 +253,11 @@ public class RNMBXLayer : UIView, RNMBXMapComponent, RNMBXSourceConsumer {
}
addedToMap()
}

func removeFromMap(_ map: RNMBXMapView, style: Style) {
removeFromMap(style)
}

#if RNMBX_11
func _toSlot(_ slot: String) -> Slot? {
switch slot {
Expand All @@ -272,36 +272,36 @@ public class RNMBXLayer : UIView, RNMBXMapComponent, RNMBXSourceConsumer {
}
}
#endif

func setBaseOptions<T: Layer>(_ layer: inout T) {
if let minZoom = minZoomLevel {
layer.minZoom = minZoom.doubleValue
}

if let maxZoom = maxZoomLevel {
layer.maxZoom = maxZoom.doubleValue
}

#if RNMBX_11
if let slot = slot {
layer.slot = _toSlot(slot)
}
#endif
}

func setOptions(_ layer: inout Layer) {
setBaseOptions(&layer)
#if !RNMBX_11
if let sourceLayerID = sourceLayerID {
layer.sourceLayer = sourceLayerID
}

if let sourceID = sourceID {
if !(existingLayer && sourceID == DEFAULT_SOURCE_ID) && hasSource() {
layer.source = sourceID
}
}

if let filter = filter, filter.count > 0 {
do {
let data = try JSONSerialization.data(withJSONObject: filter, options: .prettyPrinted)
Expand All @@ -313,7 +313,7 @@ public class RNMBXLayer : UIView, RNMBXMapComponent, RNMBXSourceConsumer {
}
#endif
}

private func optionsChanged() {
if let style = self.style, self.styleLayer != nil {
self.setOptions(&self.styleLayer!)
Expand All @@ -325,7 +325,7 @@ public class RNMBXLayer : UIView, RNMBXMapComponent, RNMBXSourceConsumer {
removeFromMap(map.mapboxMap.style)
return true
}

private func removeFromMap(_ style: Style) {
if let waitingForID = waitingForID {
Logger.log(level:.warn, message: "RNMBXLayer.removeFromMap - unmetPositionDependency: layer: \(optional: id) was waiting for layer: \(optional: waitingForID) but it hasn't added to map")
Expand All @@ -337,7 +337,7 @@ public class RNMBXLayer : UIView, RNMBXMapComponent, RNMBXSourceConsumer {
Logger.log(level: .error, message: "RNMBXLayer.removeFromMap: removing layer failed for layer \(optional: id): \(error.localizedDescription)")
}
}

func insert(_ style: Style, layerPosition: LayerPosition, onInsert: (() -> Void)? = nil) {
var idToWaitFor: String?
switch layerPosition {
Expand All @@ -350,8 +350,8 @@ public class RNMBXLayer : UIView, RNMBXMapComponent, RNMBXSourceConsumer {
default:
idToWaitFor = nil
}


if let idToWaitFor = idToWaitFor {
self.waitingForID = idToWaitFor
map!.waitForLayerWithID(idToWaitFor) { _ in
Expand All @@ -362,20 +362,20 @@ public class RNMBXLayer : UIView, RNMBXMapComponent, RNMBXSourceConsumer {
self.attemptInsert(style, layerPosition: layerPosition, onInsert: onInsert)
}
}

private func attemptInsert(_ style: Style, layerPosition: LayerPosition, onInsert: (() -> Void)? = nil) {
guard let styleLayer = self.styleLayer else {
return
}

do {
try style.addLayer(styleLayer, layerPosition: layerPosition)
onInsert?()
} catch {
Logger.log(level: .error, message: "inserting layer failed at position \(layerPosition): \(error.localizedDescription)")
}
}

internal func hasSource() -> Bool {
return true
}
Expand All @@ -385,10 +385,10 @@ public class RNMBXLayer : UIView, RNMBXMapComponent, RNMBXSourceConsumer {
protocol LayerWithSource : Layer {
var source: String? { get set }
var sourceLayer: String? { get set }
var filter: Expression? { get set}
var filter: MapboxMaps.Expression? { get set}
}
#else
protocol LayerWithSource : Layer {

}
#endif
Loading

0 comments on commit 0c37ee8

Please sign in to comment.