Skip to content

Commit

Permalink
fix: ScaleBarVisibility for Android
Browse files Browse the repository at this point in the history
  • Loading branch information
tuyen-vuduc committed Sep 18, 2024
1 parent 7f5dc68 commit 00c04dc
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/libs/Mapbox.Maui/Mapbox.Maui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<RepositoryUrl>https://github.com/tuyen-vuduc/mapbox-maui</RepositoryUrl>
<PackageProjectUrl>https://mapbox.tuyen-vuduc.tech</PackageProjectUrl>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageVersion>11.6.0-alpha01</PackageVersion>
<PackageVersion>11.6.0-alpha02</PackageVersion>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>tv-mapbox.png</PackageIcon>
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Mapbox.Maui/MapboxView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public DebugOption[] DebugOptions
nameof(ScaleBarVisibility),
typeof(OrnamentVisibility),
typeof(MapboxView),
OrnamentVisibility.Hidden
OrnamentVisibility.Visible
);
public OrnamentVisibility ScaleBarVisibility
{
Expand Down
10 changes: 4 additions & 6 deletions src/libs/Mapbox.Maui/Platforms/Android/AdditionalExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Com.Mapbox.Maps.Plugins.Animation;
using Com.Mapbox.Functions;
using Com.Mapbox.Maps.Plugins;
using System.ComponentModel;

static class AdditionalExtensions
{
Expand Down Expand Up @@ -313,13 +314,10 @@ internal static PlatformValue GetVolatileProperties(this MapboxSource source)
}

internal static MapView GetMapView(this MapboxViewHandler handler)
=> handler.PlatformView.GetMapView();

internal static MapView GetMapView(this FragmentContainerView container)
{
var mainActivity = (MauiAppCompatActivity)container.Context.GetActivity();
var tag = $"mapbox-maui-{container.Id}";
var fragnent = mainActivity.SupportFragmentManager.FindFragmentByTag(tag);
var fragmentManager = handler.MauiContext.Services.GetService<FragmentManager>();
var tag = $"mapbox-maui-{handler.PlatformView.Id}";
var fragnent = fragmentManager.FindFragmentByTag(tag);
return (fragnent as MapboxFragment)?.MapView;
}

Expand Down
4 changes: 2 additions & 2 deletions src/libs/Mapbox.Maui/Platforms/Android/MapboxFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ public override View OnCreateView(LayoutInflater inflater, ViewGroup container,
}

MapView = new MapView(Context);

MapReady?.Invoke(MapView);
return MapView;
}

public override void OnViewCreated(View view, Bundle savedInstanceState)
{
base.OnViewCreated(view, savedInstanceState);

MapReady?.Invoke(MapView);

cancelables.Add(
MapView.MapboxMap.SubscribeCameraChanged(this)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public partial class MapboxViewHandler : Locations.ILocationComponentPlugin
{
private ILocationComponentPlugin GetPlugin()
{
var mapView = PlatformView.GetMapView();
var mapView = this.GetMapView();
if (mapView is null) return null;

return LocationComponentUtils.GetLocationComponent(mapView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ partial class MapboxViewHandler : IMapFeatureQueryable
{
public Task<IEnumerable<XQueriedFeature>> QueryRenderedFeaturesWith(ScreenPosition point, XRenderedQueryOptions options)
{
var mapView = PlatformView.GetMapView();
var mapView = this.GetMapView();
if (mapView == null) return Task.FromResult(
Array.Empty<XQueriedFeature>() as IEnumerable<XQueriedFeature>
);
Expand Down
2 changes: 0 additions & 2 deletions src/libs/Mapbox.Maui/Platforms/Android/MapboxViewHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ private static void HandleScaleBarVisibilityChanged(MapboxViewHandler handler, I
var mapView = handler.GetMapView();
if (mapView is null) return;

if (mapView.MapboxMap.Style?.IsStyleLoaded != true) return;

var scaleBarPlugin = ScaleBarUtils.GetScaleBar(mapView);

scaleBarPlugin.Enabled = view.ScaleBarVisibility != OrnamentVisibility.Hidden;
Expand Down

0 comments on commit 00c04dc

Please sign in to comment.