Skip to content

Commit

Permalink
fix(tabbar): initial orientation and selection not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoy312 committed Nov 27, 2024
1 parent 6ed77fc commit 120831b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Uno.Toolkit.UI/Controls/TabBar/TabBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
using Uno.Disposables;
Expand Down Expand Up @@ -195,6 +196,14 @@ private void OnLoaded(object sender, RoutedEventArgs e)
UpdateOrientation();
}

internal void OnItemsPanelConnected(TabBarListPanel panel)
{
Debug.Assert(ItemsPanelRoot != null, "ItemsPanelRoot is expected to be already set in here.");

SynchronizeInitialSelection();
UpdateOrientation();
}

private void OnTabBarItemClick(object sender, RoutedEventArgs e)
{
if (_isSynchronizingSelection)
Expand Down Expand Up @@ -441,7 +450,7 @@ private void RaiseSelectionChangedEvent(object? prevItem, object? nextItem)
return null;
}

private bool IsReady => _isLoaded && HasItems;
private bool IsReady => _isLoaded && HasItems && ItemsPanelRoot is { };

private bool HasItems => this.GetItems().Any();
}
Expand Down
15 changes: 15 additions & 0 deletions src/Uno.Toolkit.UI/Controls/TabBar/TabBarListPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace Uno.Toolkit.UI
{
public partial class TabBarListPanel : Panel
{
#region Orientation
public Orientation Orientation
{
get { return (Orientation)GetValue(OrientationProperty); }
Expand All @@ -28,6 +29,20 @@ public Orientation Orientation
typeof(Orientation),
typeof(TabBarListPanel),
new PropertyMetadata(Orientation.Horizontal, (s, e) => ((TabBarListPanel)s).OnPropertyChanged(e)));
#endregion

public TabBarListPanel()
{
this.Loaded += OnLoaded;
}

private void OnLoaded(object sender, RoutedEventArgs e)
{
var owner = this.FindFirstParent<TabBar>();

// workaround for #1287 ItemsPanelRoot resolution timing related issue
owner?.OnItemsPanelConnected(this);
}

private void OnPropertyChanged(DependencyPropertyChangedEventArgs args)
{
Expand Down

0 comments on commit 120831b

Please sign in to comment.