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

Hiding/Showing 2 fragments with MapViews doesn't fully clear one of the MapViews.

Open DejanRistic opened this issue 9 years ago • 3 comments

Platform: Mapbox SDK version: mapbox-android-sdk:4.2.1

Tested on a LGE Nexus 5X (Android 7.1.1, API 25)

Steps to trigger behavior

  1. Create two fragment instances, each containing a MapView.
  2. Add both fragments to a container frame layout.
  3. Have some control to show one fragment while hiding the other (bottom navigation), swapping which one is visible in the container (transaction.hide()/show()).

Expected behavior

The map in the first fragment is fully hidden along with the MapView inside of the view, and the map in the second fragment is shown without issue.

Actual behavior

The map from the first fragment isn't fully cleared. The second fragment shows up and its map shows up. But it shows up below what looks like a "ghost" of the map in fragment one. Interactions go through the "ghost" of map one and seem to work properly, but the map itself is just burned above fragment 2 map.

Screenshots of issue:

screenshot_20170121-175116 screenshot_20170121-175126

Example project that shows the behavior can be found here: https://github.com/DejanRistic/MapboxMapViewFragment

DejanRistic avatar Jan 21 '17 23:01 DejanRistic

Thank you for reaching out, the detailed explanation and the sample code!

The source of this will be related to SurfaceView, which is the component we use as a drawing surface:

From reference:

Provides a dedicated drawing surface embedded inside of a view hierarchy. The surface is Z ordered so that it is behind the window holding its SurfaceView; the SurfaceView punches a hole in its window to allow its surface to be displayed. The view hierarchy will take care of correctly compositing with the Surface any siblings of the SurfaceView that would normally appear on top of it.

The ghost that you are seeing is the surface mentioned above, which is behind the Activity window. It seems that this isn't cleaned up as part of the hiding a fragment using a fragment transaction. I don't think there is much we can do from our side than calling this an unsupported use-case. The interaction model shown above can be handled differently using fragments (use on fragment container and calling replace) or you can workaround this by forcing a MapView.setVisibility(View.GONE) when the fragment transaction occurs.

Feel free to add more information to help us look into this issue but I'm currently leaning towards calling this an unsupported use-case.

tobrun avatar Jan 22 '17 11:01 tobrun

@tobrun Thanks for looking into this so quickly. I noticed it worked with replace, but I didn't want the fragment (thats one of our main tabs and contains a map) to go through teardown events in the lifecycle, which then forces us to re-create or restore state for the map it will hold and other controls.

I understand marking this an unsupported use-case, just figured i'd toss it out to you guys just in case. Ill play with some different options to workaround the window issue, I just got really curious when I saw the issue. The SurfaceView makes sense, i was just hoping the hiding the fragment would have cleaned up better.

Thanks

DejanRistic avatar Jan 23 '17 00:01 DejanRistic

I noticed it worked with replace, but I didn't want the fragment (thats one of our main tabs and contains a map) to go through teardown events in the lifecycle, which then forces us to re-create or restore state for the map it will hold and other controls.

That makes it more obvious as we need those lifecycle events to destroy the surface.

Closing as non-actionable, thank you for reaching out and reporting!

tobrun avatar Jan 23 '17 10:01 tobrun