Skip to content

Commit

Permalink
Cherry-pick upstream#787 (fixed more issues with on style loaded not …
Browse files Browse the repository at this point in the history
…being called)

https: //github.com/flutter-mapbox-gl/maps/pull/787
Co-Authored-By: Felix Horvat <24698503+felix-ht@users.noreply.github.com>
  • Loading branch information
m0nac0 and felix-ht committed May 19, 2022
1 parent a7aab41 commit b247322
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 @@ -86,10 +86,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 @@ -891,7 +891,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 @@ -925,17 +925,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 b247322

Please sign in to comment.