Add property autoResetScroll to FluScrollablePage

I use it in my app, I think it can be useful to integrate the featurein the main project. This property autoResetScroll  if true reset the scroll at the top when the StackView.onActivated is called.

So the first time a page is view but also when the user go back in the stack.
This commit is contained in:
Gaëtan Dezeiraud 2024-11-16 20:27:48 +01:00
parent d82e0ed529
commit 3eaaa228d8
2 changed files with 26 additions and 0 deletions

View File

@ -5,8 +5,11 @@ import QtQuick.Controls 2.15
import FluentUI 1.0 import FluentUI 1.0
FluPage { FluPage {
property bool autoResetScroll: false
default property alias content: container.data default property alias content: container.data
Flickable{ Flickable{
id: flickable
clip: true clip: true
anchors.fill: parent anchors.fill: parent
ScrollBar.vertical: FluScrollBar {} ScrollBar.vertical: FluScrollBar {}
@ -17,4 +20,14 @@ FluPage {
width: parent.width width: parent.width
} }
} }
function resetScroll() {
flickable.contentY = 0;
}
StackView.onActivated: {
if (autoResetScroll) {
resetScroll(); // Call this function to reset the scroll position to the top
}
}
} }

View File

@ -5,8 +5,11 @@ import QtQuick.Controls
import FluentUI import FluentUI
FluPage { FluPage {
property bool autoResetScroll: false
default property alias content: container.data default property alias content: container.data
Flickable{ Flickable{
id: flickable
clip: true clip: true
anchors.fill: parent anchors.fill: parent
ScrollBar.vertical: FluScrollBar {} ScrollBar.vertical: FluScrollBar {}
@ -17,4 +20,14 @@ FluPage {
width: parent.width width: parent.width
} }
} }
function resetScroll() {
flickable.contentY = 0;
}
StackView.onActivated: {
if (autoResetScroll) {
resetScroll(); // Call this function to reset the scroll position to the top
}
}
} }