react-native-mapbox-gl
react-native-mapbox-gl copied to clipboard
[Android] MapView loading callbacks not fired after first use
I have confirmed after much testing that on Android after the first use of mapbox the following callback methods are not fired:
onWillStartLoadingMap()
onDidFinishLoadingMap()
onDidFinishRenderingMap()
onDidFinishRenderingMapFully()
Our application waits until the map is loaded and then fades in. This functionality works great every time on iOS and the first time the Android app is run, but then these methods are not fired so the fade in animation never occurs (thus the map is never displayed to the user). There is no way the Mapbox team let something like this slip so I'm sure there is an implementation issue on our end. Can anybody shed some light?
Referencing issue #863 and #383 but no conclusive information about why these are not fired. I would expect from the Mapbox team that these methods would be documented properly if they were iOS only callbacks - however they are being fired on the first use of mapbox in our application.
@luskin the Android SDK does not fire events off as reliable, I will look into it and see what's happening
Thanks as always @nitaliano, please keep me posted if you find anything, seems like a crucial callback to not be reliable.
We're also a major version behind the native SDKs, so I expect things to be better once we move to the newer native versions this month
Do you have a timeframe in mind ? We are seeing the exact same issue... :confused:
I believe these are related https://github.com/mapbox/react-native-mapbox-gl/issues/1189#issuecomment-396368226, seems like something is messing up after a debug reload. I am looking into this today and will let everyone know what I find.
I'm not having an issue with this on master this PR fixed it https://github.com/mapbox/react-native-mapbox-gl/pull/1214 I would recommend giving master a try and I will publish another npm package soon
@nitaliano I'm using "@mapbox/react-native-mapbox-gl": "^6.1.1"
but ShapeSource
onPress still not working.
@nitaliano Same issue with ^6.1.2-beta2. Callbacks not fired after first use.
@nitaliano Also seeing same issue on 6.1.2-beta2 - but are you saying this is only an issue on android debug builds?
@kidasov you can get the master branch to solve it
"@mapbox/react-native-mapbox-gl": "git+https://github.com/mapbox/react-native-mapbox-gl#release/6.1.2“
@nitaliano any update on new package release with a fix for this? I see it occasionally in release builds on android as well (even though we thought it was a debug only bug).
@nitaliano The callback methods and onpress events are not working on first launch for release build on Android. Once you hardclose the app and reopen then the events work.
We tested on 6.1.2 , 6.1.2beta2, and 6.1.3
OnDidFinishRenderingMapListener.onDidFinishRenderingMap
and OnDidFinishLoadingMapListener.onDidFinishLoadingMap
don't fire for me on com.mapbox.mapboxsdk:mapbox-android-sdk:8.5.0
even though I can see the map rendered in my application.
However OnDidFinishLoadingStyleListener.onDidFinishLoadingStyle
and OnDidFinishRenderingFrameListener.onDidFinishRenderingFrame
do fire, although the boolean passed in the later is always false.
Any updates on a fix?
Please see https://github.com/nitaliano/react-native-mapbox-gl#deprecation-notice related to this repo's deprecation.
Unrelated to React Native:
I took the listener log lines from the Maps SDK of Android's test app https://github.com/mapbox/mapbox-gl-native-android/blob/master/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapChangeActivity.java and added them to the Mapbox demo app's SimpleMapViewActivity
to log the following listeners and adjusted the gradle file to use 8.5.0
of the Maps SDK for Android.
Both the onDidFinishLoadingMap
and onDidFinishRenderingMap
listeners fired.
public class SimpleMapViewActivity extends AppCompatActivity {
private MapView mapView;
private String TAG = "SimpleMapViewActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Mapbox access token is configured here. This needs to be called either in your application
// object or in the same activity which contains the mapview.
Mapbox.getInstance(this, getString(R.string.access_token));
// This contains the MapView in XML and needs to be called after the access token is configured.
setContentView(R.layout.activity_basic_simple_mapview);
mapView = findViewById(R.id.mapView);
mapView.addOnCameraIsChangingListener(() -> Log.d(TAG,"OnCameraIsChanging"));
mapView.addOnCameraDidChangeListener(animated -> Log.d(TAG, "OnCamaraDidChange()"));
mapView.addOnCameraWillChangeListener(animated -> Log.d(TAG, "OnCameraWilChange()"));
mapView.addOnDidFailLoadingMapListener(errorMessage -> Log.d(TAG,"OnDidFailLoadingMap:"));
mapView.addOnDidFinishLoadingMapListener(() -> Log.d(TAG,"OnDidFinishLoadingMap"));
mapView.addOnDidFinishLoadingStyleListener(() -> Log.d(TAG,"OnDidFinishLoadingStyle"));
mapView.addOnDidFinishRenderingFrameListener(fully -> Log.d(TAG, "OnDidFinishRenderingFrame:"));
mapView.addOnDidFinishRenderingMapListener(fully -> Log.d(TAG, "OnDidFinishRenderingMap:"));
mapView.addOnDidBecomeIdleListener(() -> Log.d(TAG,"OnDidBecomeIdle"));
mapView.addOnSourceChangedListener(sourceId -> Log.d(TAG, "OnSourceChangedListener:)"));
mapView.addOnWillStartLoadingMapListener(() -> Log.d(TAG,"OnWillStartLoadingMap"));
mapView.addOnWillStartRenderingFrameListener(() -> Log.d(TAG,"OnWillStartRenderingFrame"));
mapView.addOnWillStartRenderingMapListener(() -> Log.d(TAG,"OnWillStartRenderingMap"));
mapView.onCreate(savedInstanceState); mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mapboxMap.setStyle(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {
// Map is set up and the style has loaded. Now you can add data or make other map adjustments.
}
});
}
});
}
// Add the mapView lifecycle to the activity's lifecycle methods
@Override
public void onResume() {
super.onResume();
mapView.onResume();
}
@Override
protected void onStart() {
super.onStart();
mapView.onStart();
}
@Override
protected void onStop() {
super.onStop();
mapView.onStop();
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
}