Skip to content

Commit

Permalink
[Android] Fix crash disconnecting the IndicatorView (#11346)
Browse files Browse the repository at this point in the history
* Fix crash disconnecting the IndicatorView on Android

* Added IndicatorViewStub

Co-authored-by: Rui Marinho <me@ruimarinho.net>
  • Loading branch information
jsuarezruiz and rmarinho authored Dec 6, 2022
1 parent cd5dd03 commit 3f8a4ea
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ protected override MauiPageControl CreatePlatformView()
private protected override void OnConnectHandler(AView platformView)
{
base.OnConnectHandler(platformView);
PlatformView.SetIndicatorView(VirtualView);

if(platformView is MauiPageControl pageControl)
pageControl.SetIndicatorView(VirtualView);
}

private protected override void OnDisconnectHandler(AView platformView)
{
base.OnDisconnectHandler(platformView);
PlatformView.SetIndicatorView(null);

if (platformView is MauiPageControl pageControl)
pageControl.SetIndicatorView(null);
}

public static void MapCount(IIndicatorViewHandler handler, IIndicatorView indicator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public partial class IndicatorViewHandler : ViewHandler<IIndicatorView, MauiPage
protected override void ConnectHandler(MauiPageControl platformView)
{
base.ConnectHandler(platformView);
PlatformView?.SetIndicatorView(VirtualView);

platformView?.SetIndicatorView(VirtualView);

UpdateIndicator();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ public partial class IndicatorViewHandler : ViewHandler<IIndicatorView, MauiPage
protected override void ConnectHandler(MauiPageControl platformView)
{
base.ConnectHandler(platformView);
PlatformView?.SetIndicatorView(VirtualView);

platformView?.SetIndicatorView(VirtualView);

UpdateIndicator();
}

protected override void DisconnectHandler(MauiPageControl platformView)
{
base.DisconnectHandler(platformView);
PlatformView?.SetIndicatorView(null);

platformView?.SetIndicatorView(null);
}

public static void MapCount(IIndicatorViewHandler handler, IIndicatorView indicator)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Microsoft.Maui.DeviceTests
{
public partial class IndicatorViewHandlerTests
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Microsoft.Maui.DeviceTests
{
public partial class IndicatorViewHandlerTests
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Microsoft.Maui.DeviceTests.Stubs;

namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.IndicatorView)]
public partial class IndicatorViewHandlerTests : CoreHandlerTestBase<IndicatorViewHandler, IndicatorViewStub>
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Microsoft.Maui.DeviceTests
{
public partial class IndicatorViewHandlerTests
{

}
}
21 changes: 21 additions & 0 deletions src/Core/tests/DeviceTests/Stubs/IndicatorViewStub.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Microsoft.Maui.DeviceTests.Stubs
{
public class IndicatorViewStub : StubBase, IIndicatorView
{
public int Count { get; set; }

public int Position { get; set; }

public double IndicatorSize { get; set; } = 6.0d;

public int MaximumVisible { get; set; } = int.MaxValue;

public bool HideSingle { get; set; }

public Paint IndicatorColor { get; set; } = new SolidPaint(Colors.Black);

public Paint SelectedIndicatorColor { get; set; } = new SolidPaint(Colors.Grey);

public IShape IndicatorsShape { get; set; }
}
}
1 change: 1 addition & 0 deletions src/Core/tests/DeviceTests/TestCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static class TestCategory
public const string Image = "Image";
public const string ImageButton = "ImageButton";
public const string ImageSource = "ImageSource";
public const string IndicatorView = "IndicatorView";
public const string Label = "Label";
public const string Layout = "Layout";
public const string NavigationView = "NavigationView";
Expand Down

0 comments on commit 3f8a4ea

Please sign in to comment.