Skip to content

Commit

Permalink
Add push and remove to pager
Browse files Browse the repository at this point in the history
  • Loading branch information
vicr123 committed Nov 8, 2024
1 parent d15ee22 commit 5902f7d
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 96 deletions.
28 changes: 23 additions & 5 deletions controls/com/vicr123/Contemporary/Pager.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ContemporaryStackView {

default property list<Item> pages
property int currentIndex
property var defaultItem: Item { }
property var defaultItem: Item {}

initialItem: defaultItem
currentAnimation: ContemporaryStackView.Animation.SlideHorizontal
Expand All @@ -20,17 +20,35 @@ ContemporaryStackView {

onCurrentIndexChanged: {
d.animBackward = root.currentIndex >= d.oldIndex;
d.oldIndex = root.currentIndex
replacePage()
d.oldIndex = root.currentIndex;
replacePage();
}

Component.onCompleted: replacePage()

onPagesChanged: () => {
if (root.currentItem === defaultItem) replacePage()
if (root.currentItem === defaultItem)
replacePage();
}

function replacePage() {
root.replace(null, pages[currentIndex] ?? defaultItem, {}, d.animBackward ? StackView.PopTransition : StackView.PushTransition);
const newPage = pages[currentIndex] ?? defaultItem;
if (root.currentItem === newPage)
return;
root.replace(null, newPage, {}, d.animBackward ? StackView.PopTransition : StackView.PushTransition);
}

function push(page) {
pages.push(page);
replacePage();
}

function remove(page) {
pages = Array.from(pages).filter(p => p !== page);
if (pages.length <= currentIndex && pages.length !== 0) {
currentIndex = pages.length - 1;
return;
}
replacePage();
}
}
Loading

0 comments on commit 5902f7d

Please sign in to comment.