Skip to content

Commit

Permalink
Merge pull request #223 from adospace/maps-fix
Browse files Browse the repository at this point in the history
Fixed Pin management in Maps
  • Loading branch information
adospace authored Mar 13, 2024
2 parents 510dce2 + 31761df commit 115f852
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
env:
Solution_Name: ./src/MauiReactor.Build.sln
TemplatePack_Name: ./src/MauiReactor.TemplatePack/MauiReactor.TemplatePack.csproj
Version: 2.0.32
Version: 2.0.33

steps:
- name: Checkout
Expand Down
11 changes: 9 additions & 2 deletions samples/MauiReactor.MapsDemo/Pages/MainPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@ public override VisualNode Render()
{
new Map()
{
State.Positions.Select((location, index)=> new Pin().Location(location).Label($"Pin{index+1}"))
State.Positions.Select((location, index)=> new Pin()
.Location(location)
.Label($"Pin{index+1}")
.OnMarkerClicked(()=> SetState(s => s.Positions.Remove(location)))
)
}
.AutomationId("Map")
.GridRow(1)
.OnMapClicked((map, args) => SetState(s => s.Positions.Add(args.Location)))
.OnMapClicked((map, args) =>
{
SetState(s => s.Positions.Add(args.Location));
})
};
}
}
25 changes: 24 additions & 1 deletion src/MauiReactor.Maps/Map.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace MauiReactor.Maps;
using System.Collections.Generic;

namespace MauiReactor.Maps;

[Scaffold(typeof(Microsoft.Maui.Controls.Maps.Map), implementItemTemplate: true)]
[ScaffoldChildren(typeof(Microsoft.Maui.Controls.Maps.Pin), nameof(Microsoft.Maui.Controls.Maps.Map.Pins))]
Expand All @@ -7,29 +9,50 @@
[ScaffoldChildren(typeof(Microsoft.Maui.Controls.Maps.Circle), nameof(Microsoft.Maui.Controls.Maps.Map.MapElements))]
public partial class Map
{

}

[Scaffold(typeof(Microsoft.Maui.Controls.Maps.Pin))]
public partial class Pin
{
protected override void MergeWith(VisualNode newNode)
{
base.OnUnmount();
}
}

[Scaffold(typeof(Microsoft.Maui.Controls.Maps.MapElement))]
public partial class MapElement
{
protected override void MergeWith(VisualNode newNode)
{
base.OnUnmount();
}
}

[Scaffold(typeof(Microsoft.Maui.Controls.Maps.Polygon))]
public partial class Polygon
{
protected override void MergeWith(VisualNode newNode)
{
base.OnUnmount();
}
}

[Scaffold(typeof(Microsoft.Maui.Controls.Maps.Polyline))]
public partial class Polyline
{
protected override void MergeWith(VisualNode newNode)
{
base.OnUnmount();
}
}

[Scaffold(typeof(Microsoft.Maui.Controls.Maps.Circle))]
public partial class Circle
{
protected override void MergeWith(VisualNode newNode)
{
base.OnUnmount();
}
}
8 changes: 4 additions & 4 deletions src/MauiReactor/Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected sealed override void OnAnimate()
base.OnAnimate();
}

internal override void MergeWith(VisualNode newNode)
protected override void MergeWith(VisualNode newNode)
{
if (newNode.GetType().FullName == GetType().FullName && _isMounted)
{
Expand Down Expand Up @@ -284,7 +284,7 @@ object IComponentWithProps.Props
}
}

internal override void MergeWith(VisualNode newNode)
protected override void MergeWith(VisualNode newNode)
{
if (!_derivedProps && newNode != this && newNode is IComponentWithProps newComponentWithProps)
{
Expand Down Expand Up @@ -457,7 +457,7 @@ protected virtual void SetState(Action<S> action, bool invalidateComponent = tru

if (invalidateComponent && !_isMounted)
{
System.Diagnostics.Debug.WriteLine($"WARNING: Your are calling SetState on an unmounted component '{this.GetType().Name}'");
System.Diagnostics.Debug.WriteLine($"WARNING: You are calling SetState on an unmounted component '{this.GetType().Name}'");
}

if (invalidateComponent && _isMounted)
Expand All @@ -466,7 +466,7 @@ protected virtual void SetState(Action<S> action, bool invalidateComponent = tru
}
}

internal override void MergeWith(VisualNode newNode)
protected override void MergeWith(VisualNode newNode)
{
if (!_derivedState && newNode != this && newNode is IComponentWithState newComponentWithState)
{
Expand Down
4 changes: 2 additions & 2 deletions src/MauiReactor/VisualNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ internal virtual void MergeChildrenFrom(IReadOnlyList<VisualNode> oldChildren)
}
}

internal virtual void MergeWith(VisualNode newNode)
protected virtual void MergeWith(VisualNode newNode)
{
if (newNode == this)
return;
Expand Down Expand Up @@ -750,7 +750,7 @@ internal Action<T?> ComponentRefAction
set => _componentRefAction = value;
}

internal override void MergeWith(VisualNode newNode)
protected override void MergeWith(VisualNode newNode)
{
if (newNode == this)
return;
Expand Down

0 comments on commit 115f852

Please sign in to comment.