From f0b9ed3aee54ba0073372bad028c6108d3803e7f Mon Sep 17 00:00:00 2001 From: Fynn Godau Date: Tue, 18 Apr 2023 22:14:43 +0200 Subject: [PATCH 1/2] Less optimistic callback invocation Never invoke onInitalized call back before onCreate --- .../main/kotlin/org/microg/gms/maps/mapbox/GoogleMap.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/GoogleMap.kt b/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/GoogleMap.kt index 662817b61..27f6130c3 100644 --- a/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/GoogleMap.kt +++ b/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/GoogleMap.kt @@ -813,8 +813,13 @@ class GoogleMapImpl(context: Context, var options: GoogleMapOptions) : AbstractG if (initialized) { Log.d(TAG, "Invoking callback instantly, as map is initialized") runCallback() - } else if (mapView?.isShown != true) { - // If map is not shown, an app (e.g. Dott) may expect it to initialize anyway – before showing it + } else if (mapView?.isShown == false) { + /* If map is hidden, an app (e.g. Dott) may expect it to initialize anyway and + * will not show the map until it is initialized. However, we should not call + * the callback before onCreate is started (we know this is the case if mapView is + * null), otherwise that results in other problems (e.g. Gas Now app not + * initializing). + */ Log.d(TAG, "Invoking callback instantly: map cannot be initialized because it is not shown (yet)") runCallback() } else { -- GitLab From 53aba0ceb82b75f72b7167ab51ab571a51c5f3db Mon Sep 17 00:00:00 2001 From: Fynn Godau Date: Mon, 24 Apr 2023 14:44:13 +0200 Subject: [PATCH 2/2] Call callback later An app (Biryani By Kilo) is, for an unknown reason, not performing its map updates if the callback is executed before the rest of its code that immediately follows the call that sets the callback (likely: the rest of its onCreate). Therefore, delay callback invocation until after next UI draw. --- .../src/main/kotlin/org/microg/gms/maps/mapbox/GoogleMap.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/GoogleMap.kt b/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/GoogleMap.kt index 27f6130c3..77a3a5e72 100644 --- a/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/GoogleMap.kt +++ b/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/GoogleMap.kt @@ -820,8 +820,10 @@ class GoogleMapImpl(context: Context, var options: GoogleMapOptions) : AbstractG * null), otherwise that results in other problems (e.g. Gas Now app not * initializing). */ - Log.d(TAG, "Invoking callback instantly: map cannot be initialized because it is not shown (yet)") - runCallback() + mapView?.post { + Log.d(TAG, "Invoking callback now: map cannot be initialized because it is not shown (yet)") + runCallback() + } } else { Log.d(TAG, "Delay callback invocation, as map is not yet initialized") initializedCallbackList.add { runCallback() } -- GitLab