Skip to content

Commit

Permalink
Fix null handling in UpdateIndicatorLayout method (#22361) (#22382)
Browse files Browse the repository at this point in the history
* Fix null handling in UpdateIndicatorLayout method (#22361)

* Added a unit test (#22361)
  • Loading branch information
kubaflo authored May 14, 2024
1 parent 0f7d1f3 commit 110671d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Controls/src/Core/IndicatorView/IndicatorView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static void UpdateIndicatorLayout(IndicatorView indicatorView, object newValue)
{
indicatorView.IndicatorLayout = new IndicatorStackLayout(indicatorView) { Spacing = DefaultPadding };
}
else if (indicatorView.IndicatorLayout == null)
else if (indicatorView.IndicatorLayout is not null)
{
(indicatorView.IndicatorLayout as IndicatorStackLayout)?.Remove();
indicatorView.IndicatorLayout = null;
Expand Down
15 changes: 15 additions & 0 deletions src/Controls/tests/Core.UnitTests/IndicatorViewLayoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,20 @@ public void IndicatorStackLayout_ResetIndicatorCount_ShouldBindChildren(int oldC
// Assert
Assert.Equal(expected, indicatorStackLayout.Children.Count);
}

[Fact]
public void IndicatorLayout_ShouldBeRemovedWhenIndicatorTemplateIsNulled()
{
// Arrange
var indicatorView = new IndicatorView() { ItemsSource = new List<string> { "item1", "item2" } };
indicatorView.IndicatorTemplate = new DataTemplate();
Assert.NotNull(indicatorView.IndicatorLayout);

// Act
indicatorView.IndicatorTemplate = null;

//Assert
Assert.Null(indicatorView.IndicatorLayout);
}
}
}

0 comments on commit 110671d

Please sign in to comment.