Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[android] Fragment add two map and second map is being transparent #7887

Closed
Vacxe opened this issue Jan 27, 2017 · 11 comments
Closed

[android] Fragment add two map and second map is being transparent #7887

Vacxe opened this issue Jan 27, 2017 · 11 comments

Comments

@Vacxe
Copy link
Contributor

Vacxe commented Jan 27, 2017

Platform: Android
Mapbox SDK version: 4.2.2 and latest

Steps:

  1. Create single activity
  2. Create first fragment include full screen map (for example dark style)
  3. Add first fragment via SupportFragmentManager to "main_container"
    ...All correct
  4. Create second fragment with half map (in top side) and half semi transparent layout (in bottom side for example)
  5. Add second fragment via SupportFragmentManager to "main_container"
    ...
    Result: Map in second fragment fully transparent but mapbox logo is showed. And we see map from first fragment.

If don't add first layout, second layout is working correctly.
I created demo application for show
See: https://github.com/vacxe/MapboxMultilayerProblem

@bleege @tobrun folks, please help me

@tobrun
Copy link
Member

tobrun commented Jan 27, 2017

@Vacxe what you are noticing is a result of using a SurfaceView:

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. This can be used to place overlays such as buttons on top of the Surface, though note however that it can have an impact on performance since a full alpha-blended composite will be performed each time the Surface changes.

This explains the issue a bit as the surfaces behind the Activity window are in front of each other and this isn't something that can be fixed with the views found in the viewhiearchy. One workaround for this is enabling texture mode on the one that isn't visible atm (you can do this through xml or MapboxMapOptions).

Closing as this is how gl surfaces work and we do not provide support for z ordering mulitple surfaces,

@tobrun tobrun closed this as completed Jan 27, 2017
@Vacxe
Copy link
Contributor Author

Vacxe commented Jan 27, 2017

@tobrun thanks for explaining

@vkurchatkin
Copy link
Contributor

@tobrun texture mode is deprecated though, right?

@tobrun
Copy link
Member

tobrun commented Jan 27, 2017

We use SurfaceView as preferred rendering surface as it's more performant in general (Android SDK View syncing is actually better on a TextureView). We keep the option of TextureView open as long as we can support it without too much trouble. Note that for 5.0.0 we are aiming to move from SurfaceView to GLSurfaceView. This moves rendering to a separate render thread and we are hoping on delivering improved performance. As a side effect the setup is very different than with SurfaceView/TextureView so we will probably remove support for TextureView if that feature lands. PR for that in #7736.

@mhr9o2o
Copy link

mhr9o2o commented Sep 12, 2018

This bug still exists painfully!

@tobrun
Copy link
Member

tobrun commented Sep 12, 2018

@mhr9o20 this is worked as designed when using a SurfaceView, please use TextureView instead.
Update on depreciation notice, this is no longer deprecated and we will continue to support this.

@Vacxe
Copy link
Contributor Author

Vacxe commented Sep 17, 2018

@mhr9o2o actually it's not a bug. U can handle only one SurfaceView in yours view tree

@mhr9o2o
Copy link

mhr9o2o commented Sep 25, 2018

Thanks for your responses, the problem is that this bug only exists on devices running <7 Androids.
Actually, this bug enforced us to change our single-activity paradigm and that was the painful part.
We're using the latest android arch-components, loading our fragments, sometimes in front of each other, using navigation component.
In our use-case, as a ride-hailing application, our main screen is a map, then for some other interactions we need to show another map to the user [which is another fragment], previously we've worked with google maps and we hadn't faced any issue, also, myself running the app on an Android Pie device, I hadn't encountered the issue until our QA team reported it.
So my question is, how should I use a TextureView in my view tree hierarchy? we're using the latest stable SDK version [6.5.0].

@tobrun
Copy link
Member

tobrun commented Sep 25, 2018

You can enable TextureView with either xml attributes:

    <com.mapbox.mapboxsdk.maps.MapView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:mapbox_renderTextureMode="true"/>

or MapboxMapOptions:

    MapboxMapOptions options = new MapboxMapOptions().textureMode(true);
    mapView = new MapView(this, options);

@mhr9o2o
Copy link

mhr9o2o commented Sep 25, 2018

Thanks a million, I'll try this way as soon as possible and I'll inform you if anything was wrong.

@mhr9o2o
Copy link

mhr9o2o commented Sep 26, 2018

As long as I could check, from API 17 to 28, using TextureView solved the issue. Thanks again.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants