Skip to content

Commit

Permalink
fixed more issues with on style loaded not being called (#787)
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-ht authored Nov 24, 2021
1 parent 8e39db6 commit 743b2bf
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions ios/Classes/MapboxMapController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
private var mapView: MGLMapView
private var isMapReady = false
private var isStyleReady = false
private var isStyleReadyNotified = false
private var onStyleLoadedCalled = false
private var mapReadyResult: FlutterResult?

private var initialTilt: CGFloat?
Expand Down Expand Up @@ -97,10 +97,10 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
result(nil)
//Style could happen to been ready before the map was ready due to the order of methods invoked
//We should invoke onStyleLoaded
if isStyleReady && !isStyleReadyNotified {
if isStyleReady && !onStyleLoadedCalled {
if let channel = channel {
onStyleLoadedCalled = true
channel.invokeMethod("map#onStyleLoaded", arguments: nil)
isStyleReadyNotified = true
}
}
} else {
Expand Down Expand Up @@ -919,7 +919,7 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
* MGLMapViewDelegate
*/
func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
isStyleReadyNotified = false
onStyleLoadedCalled = false
isMapReady = true
updateMyLocationEnabled()

Expand Down Expand Up @@ -953,17 +953,15 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
}
}

mapReadyResult?(nil)

//If map is ready and map#waitForMap was called, we invoke onStyleLoaded callback directly
//If not, we will have to call it when map#waitForMap is done
if let mapReadyResult = mapReadyResult {
mapReadyResult(nil)
if (!isStyleReadyNotified) {
if let channel = channel {
channel.invokeMethod("map#onStyleLoaded", arguments: nil)
isStyleReadyNotified = true
}
if !onStyleLoadedCalled {
if let channel = channel {
onStyleLoadedCalled = true
channel.invokeMethod("map#onStyleLoaded", arguments: nil)
}

}

isStyleReady = true
Expand Down

0 comments on commit 743b2bf

Please sign in to comment.