Skip to content

Commit

Permalink
TabView.ItemChanged Event Fix (#8420)
Browse files Browse the repository at this point in the history
* re-enable OnItemsChanged OnDrag

* update testPage

* add test

* undo accidental change

* fix test

* add test

* remove outdated check

* fix test

* fix test

(cherry picked from commit c8d3b4a)
  • Loading branch information
karkarl authored and bkudiess committed May 1, 2023
1 parent 4a62e13 commit e75d9a4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 20 deletions.
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

0 comments on commit e75d9a4

Please sign in to comment.