feat(view): add smooth scroll animation for keyboard navigation in NListView and NGridView

This commit is contained in:
tibssy
2026-03-26 02:17:31 +00:00
parent 01744222c4
commit c524c9611f
2 changed files with 64 additions and 0 deletions
+32
View File
@@ -112,6 +112,20 @@ Item {
wheelScrollAnimation.restart();
}
function animateToContentY(targetY) {
const clampedY = root.clampScrollY(targetY);
if (!Settings.data.general.smoothScrollEnabled || Settings.data.general.animationDisabled || gridView.dragging || gridView.flicking) {
gridView.contentY = clampedY;
root._wheelTargetY = clampedY;
return;
}
root._wheelTargetY = clampedY;
wheelScrollAnimation.to = clampedY;
wheelScrollAnimation.restart();
}
// Track selection index for gradient visibility (set externally)
property int trackedSelectionIndex: -1
@@ -155,7 +169,25 @@ Item {
// Forward GridView methods
function positionViewAtIndex(index, mode) {
const shouldAnimate = mode === GridView.Contain;
if (!shouldAnimate) {
gridView.positionViewAtIndex(index, mode);
root._wheelTargetY = gridView.contentY;
return;
}
const previousY = gridView.contentY;
gridView.positionViewAtIndex(index, mode);
const targetY = root.clampScrollY(gridView.contentY);
if (Math.abs(targetY - previousY) < 0.5) {
root._wheelTargetY = targetY;
return;
}
gridView.contentY = previousY;
root._wheelTargetY = previousY;
root.animateToContentY(targetY);
}
function positionViewAtBeginning() {
+32
View File
@@ -100,9 +100,41 @@ Item {
wheelScrollAnimation.restart();
}
function animateToContentY(targetY) {
const clampedY = root.clampScrollY(targetY);
if (!Settings.data.general.smoothScrollEnabled || Settings.data.general.animationDisabled || listView.dragging || listView.flicking) {
listView.contentY = clampedY;
root._wheelTargetY = clampedY;
return;
}
root._wheelTargetY = clampedY;
wheelScrollAnimation.to = clampedY;
wheelScrollAnimation.restart();
}
// Forward ListView methods
function positionViewAtIndex(index, mode) {
const shouldAnimate = mode === ListView.Contain;
if (!shouldAnimate) {
listView.positionViewAtIndex(index, mode);
root._wheelTargetY = listView.contentY;
return;
}
const previousY = listView.contentY;
listView.positionViewAtIndex(index, mode);
const targetY = root.clampScrollY(listView.contentY);
if (Math.abs(targetY - previousY) < 0.5) {
root._wheelTargetY = targetY;
return;
}
listView.contentY = previousY;
root._wheelTargetY = previousY;
root.animateToContentY(targetY);
}
function positionViewAtBeginning() {