Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Handle case when SelectedItem is not of type TabBarItem #516

Merged
merged 2 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Uno.Toolkit.RuntimeTests/Tests/TabBarTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public async Task Verify_Indicator_Transitions(Orientation orientation, Indicato
{
const int NumItems = 3;
const double ItemSize = 100d;
var source = Enumerable.Range(0, NumItems).Select(x => new TabBarItem { Content = x }).ToArray();
var source = Enumerable.Range(0, NumItems).ToArray();
var indicator = new Border() { Background = new SolidColorBrush(Colors.Red) };
var SUT = new TabBar
{
Expand Down
4 changes: 2 additions & 2 deletions src/Uno.Toolkit.UI/Controls/TabBar/TabBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,10 @@ private void OnSelectedIndexChanged(DependencyPropertyChangedEventArgs? args)
TabBarItem? oldItem = null;
if (args?.OldValue is int oldIndex)
{
oldItem = this.FindContainerByIndex<TabBarItem>(oldIndex);
oldItem = this.ContainerFromIndex(oldIndex) as TabBarItem;
}

var newItem = this.FindContainerByIndex<TabBarItem>(SelectedIndex);
var newItem = this.ContainerFromIndex(SelectedIndex) as TabBarItem;

if (TryUpdateTabBarItemSelectedState(oldItem, newItem))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,15 @@ private void StopStoryboards()

private void UpdateSelectionIndicatorPosition(Point? destination = null)
{
destination ??= GetRelativePosition(Owner?.SelectedItem as TabBarItem);
if (Owner is not { } tabBar)
{
return;
}

if (destination == null && tabBar.SelectedIndex != -1)
{
destination = GetRelativePosition(tabBar.ContainerFromIndex(tabBar.SelectedIndex) as TabBarItem);
}

if (destination == null ||
GetSelectionIndicator() is not { } indicator ||
Expand Down