Skip to content

Commit

Permalink
Merge pull request #8672 from unoplatform/dev/dr/disableLVDnD
Browse files Browse the repository at this point in the history
fix(dragdrop): Make sure to disable dragging on LV's ItemContainer
  • Loading branch information
dr1rrb authored May 10, 2022
2 parents 6d7f534 + b7b421e commit 3fe3862
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
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

0 comments on commit 3fe3862

Please sign in to comment.