Skip to content

Commit

Permalink
Merge pull request unoplatform#16545 from unoplatform/dev/xygu/202405…
Browse files Browse the repository at this point in the history
…01/droid-combo-flyout-scroll-reset

fix(droid): ComboBox flyout scroll reset on arrange
  • Loading branch information
Xiaoy312 authored May 8, 2024
2 parents 5b870f1 + 80877e8 commit fb7bf3c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
using Windows.UI.Input.Preview.Injection;
using static Private.Infrastructure.TestServices;




#if WINAPPSDK
using Uno.UI.Extensions;
#elif __IOS__
Expand Down Expand Up @@ -1261,6 +1258,40 @@ public async Task When_Customized_Popup_Placement(PopupPlacementMode mode, doubl
}
}

#if HAS_UNO
[TestMethod]
[RunsOnUIThread]
public async Task When_ComboPopup_Rearrange_ScrollShouldNotReset()
{
var SUT = new ComboBox()
{
ItemsSource = Enumerable.Range(0, 50).Select(x => $"Item {x}").ToArray(),
SelectedIndex = 0,
};
await UITestHelper.Load(SUT);

// open down-drop
SUT.IsDropDownOpen = true;
var host = SUT.GetTemplateChild<Border>("PopupBorder") ?? throw new InvalidOperationException("Failed to find Border#PopupBorder");
await WindowHelper.WaitForLoaded(host);
await UITestHelper.WaitForIdle();

// scroll to 2 screens away
var sv = host.Child as ScrollViewer ?? throw new InvalidOperationException("Failed to find Border#PopupBorder>ScrollViewer");
var origin = sv.VerticalOffset;
var destination = origin + sv.ViewportHeight * 2;
sv.ChangeView(null, verticalOffset: destination, null, disableAnimation: true);
await UITestHelper.WaitForIdle();
Assert.IsTrue(Math.Abs(destination - sv.VerticalOffset) < 1.0, $"Expect sv.VerticalOffset to be near {destination:0.##}, got: {sv.VerticalOffset:0.##}");

// force an arrange
var cbi = sv.FindFirstChild<ComboBoxItem>();
cbi.InvalidateArrange();
await UITestHelper.WaitForIdle();
Assert.IsTrue(Math.Abs(destination - sv.VerticalOffset) < 1.0, $"Expect sv.VerticalOffset to be still near {destination:0.##}, got: {sv.VerticalOffset:0.##}");
}
#endif

#if __SKIA__ // Requires input injection
[TestMethod]
[RequiresFullWindow]
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/UIElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ public void Arrange(Rect finalRect)
}

var layouter = ((ILayouterElement)fwe).Layouter;
layouter.Arrange(finalRect);
layouter.Arrange(finalRect.DeflateBy(fwe.Margin));
layouter.ArrangeChild(fwe, finalRect);
#endif
}
Expand Down

0 comments on commit fb7bf3c

Please sign in to comment.