Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ protected virtual void OnItemsCollectionChanged(object sender, NotifyCollectionC
ViewControllers = viewControllers;
CustomizableViewControllers = Array.Empty<UIViewController>();

// Apply initial IsEnabled state for each tab item
SetTabItemsEnabledState();

if (goTo)
GoTo(ShellItem.CurrentItem);
}
Expand Down Expand Up @@ -290,6 +293,28 @@ void AddRenderer(IShellSectionRenderer renderer)
renderer.ShellSection.PropertyChanged += OnShellSectionPropertyChanged;
}

void SetTabItemsEnabledState()
{
if (TabBar?.Items is null)
{
return;
}

var items = ShellItemController.GetItems();
if (items is null)
{
return;
}

if (TabBar.Items.Length >= items.Count)
{
for (int tabIndex = 0; tabIndex < items.Count; tabIndex++)
{
TabBar.Items[tabIndex].Enabled = items[tabIndex].IsEnabled;
}
}
}

void CreateTabRenderers()
{
if (ShellItem.CurrentItem == null)
Expand All @@ -315,6 +340,9 @@ void CreateTabRenderers()
ViewControllers = viewControllers;
CustomizableViewControllers = Array.Empty<UIViewController>();

// Apply initial IsEnabled state for newly added tab items
SetTabItemsEnabledState();

UpdateTabBarHidden();

// Make sure we are at the right item
Expand Down
130 changes: 130 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue33158.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 33158, "IsEnabledProperty should work on Tabs", PlatformAffected.iOS)]
public class Issue33158 : Shell
{
public Issue33158()
{
var mainPageTab = new Tab
{
Title = "FirstPage",
IsEnabled = true,
};
mainPageTab.Items.Add(new ShellContent
{
ContentTemplate = new DataTemplate(() => new Issue33158MainPage())
});

var secondPageTab = new Tab
{
Title = "SecondTab",
IsEnabled = false,
AutomationId = "SecondTab"
};
secondPageTab.Items.Add(new ShellContent
{
ContentTemplate = new DataTemplate(() => new Issue33158SecondPage())
});
var thirdTab = new Tab
{
Title = "ThirdTab",
IsEnabled = true,
AutomationId = "ThirdTab"
};
thirdTab.Items.Add(new ShellContent
{
ContentTemplate = new DataTemplate(() => new Issue33158ThirdPage())
});
var tabBar = new TabBar();
tabBar.Items.Add(mainPageTab);
tabBar.Items.Add(secondPageTab);
tabBar.Items.Add(thirdTab);
Items.Add(tabBar);
}

public class Issue33158MainPage : ContentPage
{
public Issue33158MainPage()
{
Content = new StackLayout
{
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
Children =
{
new Label
{
Text = "This is First Page",
}
}
};
}
}

public class Issue33158SecondPage : ContentPage
{
public Issue33158SecondPage()
{
Content = new StackLayout
{
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
Children =
{
new Label
{
Text = "This is Second Page",
AutomationId = "SecondPageLabel"
}
}
};
}
}
public class Issue33158ThirdPage : ContentPage
{
public Issue33158ThirdPage()
{
var label = new Label
{
Text = "This is Third Page",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
AutomationId = "ThirdPageLabel"
};

var button = new Button
{
Text = "Enable SecondTab",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
AutomationId = "EnableSecondTab"
};
button.Clicked += OnButtonClicked;
Content = new StackLayout
{
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
Children =
{
label,
button
}
};
}

private void OnButtonClicked(object sender, EventArgs e)
{
if (Application.Current?.Windows.Count > 0 &&
Application.Current.Windows[0].Page is Shell shell)
{
var secondTab = shell.CurrentItem?.Items[1];
if (secondTab is not null)
secondTab.IsEnabled = true;
}
else
{
System.Diagnostics.Debug.WriteLine("Shell not found!");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#if TEST_FAILS_ON_WINDOWS // Existing PR for windows - https://github.com/dotnet/maui/pull/26728
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue33158 : _IssuesUITest
{
public Issue33158(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "IsEnabledProperty should work on Tabs";

[Test]
[Category(UITestCategories.Shell)]
public void Issue33158CheckIsEnabled()
{
App.WaitForElement("ThirdTab");
App.Tap("ThirdTab");
App.WaitForElement("ThirdPageLabel");
App.Tap("SecondTab");
App.WaitForNoElement("SecondPageLabel");
App.Tap("EnableSecondTab");
App.Tap("SecondTab");
App.WaitForElement("SecondPageLabel");
}
}
#endif
Loading