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

TabView.ItemChanged Event Fix #8420

Merged
merged 9 commits into from
Apr 25, 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
49 changes: 35 additions & 14 deletions dev/TabView/InteractionTests/TabViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,6 @@ public void HandleItemCloseRequestedTest()
[TestMethod]
public void DragBetweenTabViewsTest()
{
if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5))
{
// TODO 19727004: Re-enable this on versions below RS5 after fixing the bug where mouse click-and-drag doesn't work.
Log.Warning("This test relies on touch input, the injection of which is only supported in RS5 and up. Test is disabled.");
return;
}

using (var setup = new TestSetupHelper("TabView Tests"))
{
UIObject firstTab = FindElement.ByName("FirstTab");
Expand Down Expand Up @@ -361,13 +354,6 @@ public void DragBetweenTabViewsTest()
[TestMethod]
public void ReorderItemsTest()
{
if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5))
{
// TODO 19727004: Re-enable this on versions below RS5 after fixing the bug where mouse click-and-drag doesn't work.
Log.Warning("This test relies on touch input, the injection of which is only supported in RS5 and up. Test is disabled.");
return;
}

using (var setup = new TestSetupHelper("TabView Tests"))
{
Button tabItemsSourcePageButton = FindElement.ByName<Button>("TabViewTabItemsSourcePageButton");
Expand Down Expand Up @@ -405,6 +391,41 @@ public void ReorderItemsTest()
}
}

[TestMethod]
public void ItemChangedEventOnDragTest()
{
using (var setup = new TestSetupHelper("TabView Tests"))
{
Button addButton = FindElement.ByName<Button>("Add New Tab");
Verify.IsNotNull(addButton);

Log.Comment("Add tab so scroll buttons appear.");
addButton.InvokeAndWait();

Verify.IsTrue(AreScrollButtonsVisible(), "Scroll buttons should appear");

UIObject sourceTab = FindElement.ByName("FirstTab");

Verify.IsNotNull(sourceTab);

UIObject dropTab = FindElement.ByName("LastTab");
Verify.IsNotNull(dropTab);

Log.Comment("Dragging tab to the last overflow tab...");
InputHelper.DragToTarget(sourceTab, dropTab, 40);
Wait.ForIdle();
ElementCache.Refresh();

Log.Comment("...reordering done. Expecting a TabView.TabItemsChanged event to be raised with CollectionChange=ItemInserted and Index=5.");

TextBlock tabsItemChangedEventArgsTextBlock = FindElement.ByName<TextBlock>("TabsItemChangedEventArgsTextBlock");
Verify.AreEqual("ItemInserted", tabsItemChangedEventArgsTextBlock.DocumentText);

TextBlock tabsItemChangedEventArgsIndexTextBlock = FindElement.ByName<TextBlock>("TabsItemChangedEventArgsIndexTextBlock");
Verify.AreEqual("5", tabsItemChangedEventArgsIndexTextBlock.DocumentText);
}
}

[TestMethod]
public void AddButtonTest()
{
Expand Down
9 changes: 3 additions & 6 deletions dev/TabView/TabView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,11 +720,6 @@ void TabView::BringSelectedTabIntoView()

void TabView::OnItemsChanged(winrt::IInspectable const& item)
{
if (m_isDragging)
{
return;
}

if (auto args = item.as<winrt::IVectorChangedEventArgs>())
{
m_tabItemsChangedEventSource(*this, args);
Expand Down Expand Up @@ -863,11 +858,13 @@ void TabView::OnListViewDragItemsCompleted(const winrt::IInspectable& sender, co
{
m_isDragging = false;

// Selection change was disabled during drag, update SelectedIndex now
// Selection may have changed during drag if dragged outside, so we update SelectedIndex again.
if (auto&& listView = m_listView.get())
{
SelectedIndex(listView.SelectedIndex());
SelectedItem(listView.SelectedItem());

BringSelectedTabIntoView();
}

auto item = args.Items().GetAt(0);
Expand Down
5 changes: 5 additions & 0 deletions dev/TabView/TestUI/TabViewPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@
<Button x:Name="GetScrollIncreaseButtonToolTipButton" AutomationProperties.Name="GetScrollIncreaseButtonToolTipButton" Content="TooltipScrollIncreaseButton" Click="GetScrollIncreaseButtonToolTipButton_Click"/>
<TextBlock x:Name="ScrollIncreaseButtonToolTipTextBlock" AutomationProperties.Name="ScrollIncreaseButtonToolTipTextBlock" Margin="4,0,0,0" Text=""/>
</StackPanel>

<StackPanel Orientation="Horizontal" Margin="0,0,0,8">
<TextBlock x:Name="TabsItemChangedEventArgsTextBlock" AutomationProperties.Name="TabsItemChangedEventArgsTextBlock" Margin="4,0,0,0" Text="" />
<TextBlock x:Name="TabsItemChangedEventArgsIndexTextBlock" AutomationProperties.Name="TabsItemChangedEventArgsIndexTextBlock" Margin="4,0,0,0" Text="" />
</StackPanel>
</StackPanel>
</ScrollViewer>

Expand Down
8 changes: 8 additions & 0 deletions dev/TabView/TestUI/TabViewPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public TabViewPage()
_iconSource = new SymbolIconSource();
_iconSource.Symbol = Symbol.Placeholder;

Tabs.TabItemsChanged += Tabs_TabItemsChanged;

ObservableCollection<TabDataItem> itemSource = new ObservableCollection<TabDataItem>();
for (int i = 0; i < 5; i++)
{
Expand All @@ -63,6 +65,12 @@ public TabViewPage()
CacheFirstTabSelectedBackgroundPathFill();
}

private void Tabs_TabItemsChanged(TabView sender, Windows.Foundation.Collections.IVectorChangedEventArgs args)
{
TabsItemChangedEventArgsTextBlock.Text = args.CollectionChange.ToString();
TabsItemChangedEventArgsIndexTextBlock.Text = args.Index.ToString();
}

private Brush backgroundColorCache;
private Brush activeTabSelectedBackgroundPathBrushCache;
private Brush activeTabContentBackgroundBrushCache;
Expand Down