dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.04k stars 1.73k forks source link

[Maps] [Android] [Regression] Registering for CameraMove events in a custom MapHandler disables Map.VisibleRegion.Center #21094

Open mfeingol opened 7 months ago

mfeingol commented 7 months ago

Description

Create a custom map class and a handler for it, and inside that handler register for CameraMove events from the underlying GoogleMap (either via SetOnCameraMoveListener or the CameraMove event). When you do this, the Maui Map's VisibleRegion property no longer updates when you move the map. In particular, the Center property always returns the map's initial location.

Comment out the += to the CameraMove event, or the call to SetOnCameraMoveListener, and VisibleRegion.Center will update again. This is very broken, and it is a regression from Xamarin.Forms.

cf https://github.com/dotnet/maui/issues/13186 - I mistakenly closed this thinking the issue was fixed. It was not.

Steps to Reproduce

class CustomMapHandler : MapHandler
{
    protected override void ConnectHandler(Android.Gms.Maps.MapView platformView)
    {
        base.ConnectHandler(platformView);
        platformView.GetMapAsync(new CustomMapCallbackHandler(this));
    }

    internal void OnMapReady(Android.Gms.Maps.GoogleMap googleMap)
    {
        googleMap.CameraMove += this.OnCameraMoved;
    }

    void OnCameraMoved(object sender, EventArgs e)
    {
    }
}

class CustomMapCallbackHandler : Java.Lang.Object, Android.Gms.Maps.IOnMapReadyCallback
{
    readonly CustomMapHandler handler;

    public CustomMapCallbackHandler(CustomMapHandler handler)
    {
        this.handler = handler;
    }

    public void OnMapReady(Android.Gms.Maps.GoogleMap map)
    {
        this.handler.OnMapReady(map);
    }
}

Link to public reproduction project repository

https://github.com/mfeingol/repros/tree/master/MapVisibleRegionRepro

Version with bug

8.0.7 SR2

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

14

Did you find any workaround?

No workaround.

Relevant log output

No response

mfeingol commented 6 months ago

Hello. There's a repro mentioned above: https://github.com/mfeingol/repros/tree/master/MapVisibleRegionRepro

andersondamasio commented 1 month ago

I have the same problem. We hope to have some workaround soon.