Skip to content

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

@japarson

Description

@japarson

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.

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

Relevant Files

  • src/Core/maps/src/Handlers/Map/MapHandler.cs
  • src/Core/maps/src/Handlers/Map/MapHandler.Android.cs
  • src/Controls/Maps/src/HandlerImpl/Map.Impl.cs
  • src/Controls/Maps/src/Map.cs
Checklist
  • Modify src/Core/maps/src/Handlers/Map/MapHandler.Android.cs ! No changes made Edit
  • Running GitHub Actions for src/Core/maps/src/Handlers/Map/MapHandler.Android.csEdit
  • Modify src/Core/maps/src/Handlers/Map/MapHandler.cs3d956e2 Edit
  • Running GitHub Actions for src/Core/maps/src/Handlers/Map/MapHandler.csEdit
  • Modify src/Controls/Maps/src/Map.cs ! No changes made Edit
  • Running GitHub Actions for src/Controls/Maps/src/Map.csEdit

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions