Skip to content

Commit 04559ed

Browse files
committed
Improvements to how scroll is triggered when keyboard keys are pressed on packages list
1 parent 9179c8a commit 04559ed

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion>
66
<!-- IF BUILD FAILS DUE TO MISSING Microsoft.Management.Deployment NAMESPACE,
77
TOGGLE THE LAST NUMBER OF THE LINE BELOW 1 UNIT UP OR DOWN, AND REBUILD-->
8-
<WindowsSdkPackageVersion>10.0.26100.57</WindowsSdkPackageVersion>
8+
<WindowsSdkPackageVersion>10.0.26100.56</WindowsSdkPackageVersion>
99

1010
<SdkVersion>8.0.407</SdkVersion>
1111
<Authors>Martí Climent and the contributors</Authors>

src/UniGetUI/Pages/SoftwarePages/AbstractPackagesPage.xaml.cs

+13-10
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
using Microsoft.UI;
2222
using Microsoft.UI.Xaml.Media;
2323
using Windows.UI;
24-
using ABI.Windows.Media.PlayTo;
2524
using Microsoft.UI.Xaml.Controls.Primitives;
2625

2726
// To learn more about WinUI, the WinUI project structure,
@@ -514,29 +513,33 @@ private void SelectAndScrollTo(int index, bool focus)
514513
CurrentPackageList.Select(index);
515514

516515
double position;
517-
if (CurrentPackageList.Layout is StackLayout sl)
516+
if (CurrentPackageList.Layout is StackLayout)
518517
{
519518
position = index * 39;
520519
}
521520
else if (CurrentPackageList.Layout is UniformGridLayout gl)
522521
{
523522
int columnCount = (int)((CurrentPackageList.ActualWidth - 8) / (gl.MinItemWidth + 8));
524-
int row = index / columnCount;
523+
int row = index / Math.Max(columnCount, 1);
525524
position = Math.Max(row - 1, 0) * (gl.MinItemHeight + 8);
526-
Debug.WriteLine($"pos: {position}, colCount:{columnCount}, {index / columnCount}");
525+
Debug.WriteLine($"pos: {position}, colCount:{columnCount}, {row}");
527526
}
528527
else
529528
{
530529
throw new InvalidCastException("The layout was not recognized");
531530
}
532531

533-
CurrentPackageList.ScrollView.ScrollTo(0, position, new ScrollingScrollOptions(
534-
ScrollingAnimationMode.Disabled,
535-
ScrollingSnapPointsMode.Ignore
536-
));
537532

538-
if (focus)
539-
Focus(FilteredPackages[index].Package);
533+
if (position < CurrentPackageList.ScrollView.VerticalOffset || position >
534+
CurrentPackageList.ScrollView.VerticalOffset + CurrentPackageList.ScrollView.ActualHeight)
535+
{
536+
CurrentPackageList.ScrollView.ScrollTo(0, position, new ScrollingScrollOptions(
537+
ScrollingAnimationMode.Disabled,
538+
ScrollingSnapPointsMode.Ignore
539+
));
540+
}
541+
542+
if (focus) Focus(FilteredPackages[index].Package);
540543
}
541544

542545
private void Focus(IPackage packageToFocus, int retryCount = 0)

0 commit comments

Comments
 (0)