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: CalendarView maxdate scrolling #18987

Merged
merged 4 commits into from
Dec 9, 2024
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 @@ -24,6 +24,8 @@
[RunsOnUIThread]
public class Given_CalendarView
{
const int DEFAULT_MIN_MAX_DATE_YEAR_OFFSET = 100;

[TestMethod]
[UnoWorkItem("https://github.com/unoplatform/uno/issues/16123")]
[Ignore("Test is unstable on CI: https://github.com/unoplatform/uno/issues/16123")]
Expand Down Expand Up @@ -61,6 +63,42 @@
await UITestHelper.Load(calendarView);
}

[TestMethod]
public async Task When_Scroll_To_MaxDate()
{
var calendarView = new CalendarView()
{
DisplayMode = CalendarViewDisplayMode.Decade
};

await UITestHelper.Load(calendarView);

Type calendarViewType = typeof(CalendarView);
MethodInfo ChangeVisualStateInfo = calendarViewType.GetMethod("ChangeVisualState", BindingFlags.NonPublic | BindingFlags.Instance);

Check warning on line 77 in src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_CalendarView.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_CalendarView.cs#L77

Make sure that this accessibility bypass is safe here.

// Scroll to max date
calendarView.SetDisplayDate(calendarView.MaxDate);

// Switch to Year view
calendarView.DisplayMode = CalendarViewDisplayMode.Year;
ChangeVisualStateInfo.Invoke(calendarView, new object[] { false });
await TestServices.WindowHelper.WaitForIdle();

// Switch back to Decade view
calendarView.DisplayMode = CalendarViewDisplayMode.Decade;
ChangeVisualStateInfo.Invoke(calendarView, new object[] { false });
await TestServices.WindowHelper.WaitForIdle();

// Decade viewport should be full of items (no missing row)
calendarView.GetActiveGeneratorHost(out var pHost);
var maxDecadeIndex = DEFAULT_MIN_MAX_DATE_YEAR_OFFSET * 2;
var maxDisplayedItems = pHost.Panel.Rows * pHost.Panel.Cols;

// The first visible index should be less than the max possible index minus the max items we can display
// Worst case scenario is that the last row only has 1 item
Assert.IsTrue(pHost.Panel.FirstVisibleIndex <= maxDecadeIndex - (maxDisplayedItems - pHost.Panel.Rows - 1));
}

#if __WASM__
[TestMethod]
[Ignore("Fails on Fluent styles #17272")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,21 @@ internal void ScrollItemIntoView(int index, ScrollIntoViewAlignment alignment, d
// then it will request GetContainerFromIndex and tries to focus it.
// So here we prepare the _effectiveViewport (which will most probably be re-updated by the ChangeView below),
// and then force a base_Measure()
_effectiveViewport.Y += newOffset - currentOffset;

#if HAS_UNO
// Scrolling to the MaxDate and switching between Decade/Year/Month views keeps increasing the _effectiveViewport.Y
// even though there's no more items to show after MaxDate, causing empty rows in the viewport
if (newOffset >= sv.ScrollableHeight)
rajamatt marked this conversation as resolved.
Show resolved Hide resolved
{
_effectiveViewport.Y = currentOffset;
}
else
{
_effectiveViewport.Y += newOffset - currentOffset;
}
#else
_effectiveViewport.Y += newOffset - currentOffset;
#endif

sv.ChangeView(
horizontalOffset: null,
Expand Down
Loading