Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions ios/RNMBX/RNMBXAtmosphere.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ public class RNMBXAtmosphere : RNMBXSingletonLayer, RNMBXMapComponent, RNMBXSour
public func removeFromMap(_ map: RNMBXMapView, reason _: RemovalReason) -> Bool {
self.map = nil

guard let mapboxMap = map.mapboxMap else {
return false
map.withMapboxMap { [weak self] _mapboxMap in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this. Maybe we should store the style we've added ourself to? Doesn't make much sense to wait for a style here. It could be other style, then we've added to, so...

Also not sure if a race like this is possible:

  1. item added to map with style A
  2. style removed from map
  3. item tries to removeFromMap so it's waits for style
  4. style B is added to map
  5. item is added to style B
  6. withMapboxMap is executed item removed from style B

this can't happen as 6.) will be called before 4.) but it's something I need to think about on every change like this.

guard let self = self else { return }
let style = _mapboxMap.style
self.removeFromMap(map, style: style)
}

let style = mapboxMap.style
removeFromMap(map, style: style)
return true
}

Expand Down
36 changes: 21 additions & 15 deletions ios/RNMBX/RNMBXCamera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,22 @@ struct CameraUpdateItem {
var duration: TimeInterval?

func execute(map: RNMBXMapView, cameraAnimator: inout BasicCameraAnimator?) {
logged("CameraUpdateItem.execute") {
if let center = camera.center {
try center.validate()
}
map.withMapView { _mapView in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

logged("CameraUpdateItem.execute") {
if let center = camera.center {
try center.validate()
}

switch mode {
case .flight:
map.mapView.camera.fly(to: camera, duration: duration)
case .ease:
map.mapView.camera.ease(to: camera, duration: duration ?? 0, curve: .easeInOut, completion: nil)
case .linear:
map.mapView.camera.ease(to: camera, duration: duration ?? 0, curve: .linear, completion: nil)
default:
map.mapboxMap.setCamera(to: camera)
switch mode {
case .flight:
_mapView.camera.fly(to: camera, duration: duration)
case .ease:
_mapView.camera.ease(to: camera, duration: duration ?? 0, curve: .easeInOut, completion: nil)
case .linear:
_mapView.camera.ease(to: camera, duration: duration ?? 0, curve: .linear, completion: nil)
default:
_mapView.mapboxMap.setCamera(to: camera)
}
}
}
}
Expand Down Expand Up @@ -92,7 +94,9 @@ open class RNMBXMapComponentBase : UIView, RNMBXMapComponent {

func withMapView(_ callback: @escaping (_ mapView: MapView) -> Void) {
withRNMBXMapView { mapView in
callback(mapView.mapView)
mapView.withMapView { _mapView in
callback(_mapView)
}
}
}

Expand Down Expand Up @@ -529,7 +533,9 @@ open class RNMBXCamera : RNMBXMapComponentBase {
return false
}

map.mapView.viewport.removeStatusObserver(self)
map.withMapView { _mapView in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the other remove, we don't want to try to remove from other mapViewpot we've added ourselves to

_mapView.viewport.removeStatusObserver(self)
}
return super.removeFromMap(map, reason:reason)
}

Expand Down
10 changes: 5 additions & 5 deletions ios/RNMBX/RNMBXCustomLocationProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public class RNMBXCustomLocationProvider: UIView, RNMBXMapComponent {

public func addToMap(_ map: RNMBXMapView, style: Style) {
self.map = map
if let mapView = map.mapView {
installCustomeLocationProviderIfNeeded(mapView: mapView)
map.withMapView{ _mapView in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we have a valid style, we should have a map too. Maybe add a map parameter as well?!

self.installCustomeLocationProviderIfNeeded(mapView: _mapView)
}
}

Expand All @@ -61,10 +61,10 @@ public class RNMBXCustomLocationProvider: UIView, RNMBXMapComponent {
}

public func removeFromMap(_ map: RNMBXMapView, reason: RemovalReason) -> Bool {
if let mapView = map.mapView {
removeCustomLocationProvider(mapView: mapView)
map.withMapView { _mapView in
self.removeCustomLocationProvider(mapView: _mapView)
self.map = nil
}
self.map = nil
return true
}

Expand Down
20 changes: 13 additions & 7 deletions ios/RNMBX/RNMBXImageSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ public class RNMBXImageSource : RNMBXSource {
didSet {
if var source = source as? ImageSource {
source.url = url
self.doUpdate { (style) in
try! style.setSourceProperty(for: id, property: "url", value: url)
self.map?.withMapboxMap { [weak self] _mapboxMap in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same concern here as well. We've added ourself to style. So we don't want to wait for it again. Maybe we should save the style here as well

guard let self = self else { return }
self.doUpdate(_mapboxMap: _mapboxMap) { (style) in
try! style.setSourceProperty(for: self.id, property: "url", value: source.url)
}
}
}
}
Expand All @@ -22,8 +25,11 @@ public class RNMBXImageSource : RNMBXSource {
} else {
source.coordinates = nil
}
self.doUpdate { (style) in
try! style.setSourceProperty(for: id, property: "coordinates", value: source.coordinates)
self.map?.withMapboxMap { [weak self] _mapboxMap in
guard let self = self else { return }
self.doUpdate(_mapboxMap: _mapboxMap) { (style) in
try! style.setSourceProperty(for: self.id, property: "coordinates", value: source.coordinates)
}
}
}
}
Expand Down Expand Up @@ -51,14 +57,14 @@ public class RNMBXImageSource : RNMBXSource {
return result
}

func doUpdate(_ update:(Style) -> Void) {
func doUpdate(_mapboxMap: MapboxMap, _ update:(Style) -> Void) {
guard let map = self.map,
let _ = self.source,
map.mapboxMap.style.sourceExists(withId: id) else {
_mapboxMap.style.sourceExists(withId: id) else {
return
}

let style = map.mapboxMap.style
let style = _mapboxMap.style
update(style)
}

Expand Down
7 changes: 6 additions & 1 deletion ios/RNMBX/RNMBXInteractiveElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ public class RNMBXInteractiveElement : UIView, RNMBXMapComponent {
}
didSet {
if oldValue != nil && oldValue != id {
if let map = map { addToMap(map, style: map.mapboxMap.style) }
if let map = map {
self.map?.withMapboxMap { [weak self] _mapboxMap in
guard let self = self else { return }
self.addToMap(map, style: _mapboxMap.style)
}
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion ios/RNMBX/RNMBXLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,10 @@ public class RNMBXLayer : UIView, RNMBXMapComponent, RNMBXSourceConsumer {
}

public func removeFromMap(_ map: RNMBXMapView, reason: RemovalReason) -> Bool {
removeFromMap(map.mapboxMap.style)
map.withMapboxMap { [weak self] _mapboxMap in
guard let self = self else { return }
self.removeFromMap(_mapboxMap.style)
}
return true
}

Expand Down
9 changes: 6 additions & 3 deletions ios/RNMBX/RNMBXLight.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ public class RNMBXLight: UIView, RNMBXMapComponent {
}

public func addToMap(_ map: RNMBXMapView, style: Style) {
self.map = map.mapboxMap
if (reactStyle != nil) {
addStyles()
map.withMapboxMap { [weak self] _mapboxMap in
guard let self = self else { return }
self.map = _mapboxMap
if (self.reactStyle != nil) {
self.addStyles()
}
}
}

Expand Down
Loading
Loading