react-native-mapbox-gl icon indicating copy to clipboard operation
react-native-mapbox-gl copied to clipboard

[Android] MapView loading callbacks not fired after first use

Open luskin opened this issue 6 years ago • 14 comments

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 avatar Jun 05 '18 17:06 luskin

@luskin the Android SDK does not fire events off as reliable, I will look into it and see what's happening

nitaliano avatar Jun 05 '18 17:06 nitaliano

Thanks as always @nitaliano, please keep me posted if you find anything, seems like a crucial callback to not be reliable.

luskin avatar Jun 05 '18 17:06 luskin

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

nitaliano avatar Jun 05 '18 17:06 nitaliano

Do you have a timeframe in mind ? We are seeing the exact same issue... :confused:

Gp2mv3 avatar Jun 12 '18 14:06 Gp2mv3

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.

nitaliano avatar Jun 12 '18 18:06 nitaliano

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 avatar Jun 12 '18 20:06 nitaliano

@nitaliano I'm using "@mapbox/react-native-mapbox-gl": "^6.1.1" but ShapeSource onPress still not working.

jsina avatar Jun 25 '18 13:06 jsina

@nitaliano Same issue with ^6.1.2-beta2. Callbacks not fired after first use.

kidasov avatar Jun 29 '18 10:06 kidasov

@nitaliano Also seeing same issue on 6.1.2-beta2 - but are you saying this is only an issue on android debug builds?

luskin avatar Jun 29 '18 22:06 luskin

@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“

jsina avatar Jun 30 '18 06:06 jsina

@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).

luskin avatar Jul 15 '18 21:07 luskin

@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

beisert1 avatar Oct 05 '18 19:10 beisert1

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?

mosofsky avatar Jan 11 '20 00:01 mosofsky

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.

Screen Shot 2020-01-22 at 2 54 47 PM Screen Shot 2020-01-22 at 2 54 51 PM

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);
  }
}

langsmith avatar Jan 22 '20 22:01 langsmith