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 d0f903c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Uno.Toolkit.UI/Controls/TabBar/TabBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ private void OnLoaded(object sender, RoutedEventArgs e)
UpdateOrientation();
}

internal void OnItemsPanelConnected(TabBarListPanel panel)
{
System.Diagnostics.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 +449,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 d0f903c

Please sign in to comment.