From 743b2bfb5e21a98b04ffba901ef1aaea56478472 Mon Sep 17 00:00:00 2001 From: Felix Horvat Date: Wed, 24 Nov 2021 22:14:16 +0100 Subject: [PATCH] fixed more issues with on style loaded not being called (#787) --- ios/Classes/MapboxMapController.swift | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/ios/Classes/MapboxMapController.swift b/ios/Classes/MapboxMapController.swift index 213de1d32..222e065f8 100644 --- a/ios/Classes/MapboxMapController.swift +++ b/ios/Classes/MapboxMapController.swift @@ -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? @@ -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 { @@ -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() @@ -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