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

fix(dragdrop): Make sure to disable dragging on LV's ItemContainer #8672

Merged
merged 2 commits into from
May 10, 2022
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 @@ -15,10 +15,39 @@ namespace SamplesApp.UITests.Windows_UI_Xaml.DragAndDropTests
public partial class DragDrop_ListViewReorder_Automated : SampleControlUITestBase
{
private static readonly string[] _items = new[] { "#FF0018", "#FFA52C", "#FFFF41", "#008018", "#0000F9", "#86007D" };
private const int _itemHeight = 100;
private const int _itemHeight = 90;

private static float Item(IAppRect sut, int index) => sut.Y + (index * _itemHeight) + 25;

[Test]
[AutoRetry]
[ActivePlatforms(Platform.Browser)] // TODO: support drag-and-drop testing on mobile https://github.com/unoplatform/Uno.UITest/issues/31
public void When_Disabled()
{
Run("UITests.Windows_UI_Xaml.DragAndDrop.DragDrop_ListView", skipInitialScreenshot: true);

var sut = _app.Marked("SUT");
var mode = _app.Marked("DragMode");

mode.SetDependencyPropertyValue("IsChecked", "False");

var before = TakeScreenshot("Before", ignoreInSnapshotCompare: true);

// Attempt to re-order
var sutBounds = _app.Query(sut).Single().Rect;
var x = sutBounds.X + 50;
var srcY = Item(sutBounds, 1);
var dstY = Item(sutBounds, 3);

_app.DragCoordinates(x, srcY, x, dstY);

var after = TakeScreenshot("After", ignoreInSnapshotCompare: true);

// note: we test only 100 pixels width to avoid failure due to scrollbar being visible in "after" screenshot
var testBounds = new Rectangle((int)sutBounds.X, (int)sutBounds.Y, 100, (int)sutBounds.Height);
ImageAssert.AreEqual(before, after, testBounds);
}

[Test]
[AutoRetry]
[ActivePlatforms(Platform.Browser)] // TODO: support drag-and-drop testing on mobile https://github.com/unoplatform/Uno.UITest/issues/31
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,25 @@
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ListView
CanDragItems="True"
CanReorderItems="True"
AllowDrop="True"
CanDragItems="{Binding IsChecked, ElementName=DragMode}"
CanReorderItems="{Binding IsChecked, ElementName=DragMode}"
AllowDrop="{Binding IsChecked, ElementName=DragMode}"
SelectionMode="Multiple"
MinHeight="300"
x:Name="SUT">
<ListView.ItemTemplate>
<DataTemplate>
<Border Background="{Binding}" Width="300" Height="100">
<Border Background="{Binding}" Width="300" Height="90">
<TextBlock Text="{Binding}" Foreground="Black" />
</Border>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

<TextBlock x:Name="Operation" Text="--none--" Grid.Row="1" />
<StackPanel Grid.Row="1" Orientation="Horizontal">
<CheckBox x:Name="DragMode" IsThreeState="False" IsChecked="True" Content="Allow reorder" Margin="0,0,10,0" />
<TextBlock Text="Drag operation: " />
<TextBlock x:Name="Operation" Text="--none--" />
</StackPanel>
</Grid>
</Page>
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ private static void ClearContainerForDragDrop(UIElement itemContainer)
return;
}

itemContainer.CanDrag = false;
itemContainer.DragStarting -= OnItemContainerDragStarting;
itemContainer.DropCompleted -= OnItemContainerDragCompleted;

Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/DragDrop/DragDropManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public DataPackageOperation ProcessAborted(IDragEventSource src)
=> FindOperation(src)?.Aborted(src) ?? DataPackageOperation.None;

private DragOperation? FindOperation(IDragEventSource src)
=> _dragOperations.FirstOrDefault(drag => drag.Info.SourceId == src.Id);
=> _dragOperations.FirstOrDefault(drag => drag.Info.SourceId == src.Id);

private void RegisterWindowHandlers()
{
Expand Down