Maybe fix the DelegateModel + ListView.add bug

This commit is contained in:
miruka 2020-05-01 02:12:58 -04:00
parent bf20b7864d
commit c352275089
4 changed files with 43 additions and 25 deletions

View File

@ -4,7 +4,6 @@
- add account number binds - add account number binds
- rename goto*account → scrollto*account - rename goto*account → scrollto*account
- fix interrupted transitions
- fix back/front buttons in small window - fix back/front buttons in small window
- fix message delegate too tall - fix message delegate too tall
- fix left rooms opacity - fix left rooms opacity

View File

@ -29,39 +29,34 @@ ListView {
// property bool debug: false // property bool debug: false
// Make sure to handle when a previous transition gets interrupted // https://doc.qt.io/qt-5/qml-qtquick-viewtransition.html
// #handling-interrupted-animations
// XXX: add transitions are buggy when using DelegateModel, `add` should be
// set to `null` and delegates should have `ListView.onAdd: ...` instead.
add: Transition { add: Transition {
ParallelAnimation { // ScriptAction { script: if (listView.debug) print("add") }
// ScriptAction { script: if (listView.debug) print("add") } HNumberAnimation { property: "opacity"; from: 0; to: 1 }
HNumberAnimation { property: "opacity"; from: 0; to: 1 } HNumberAnimation { property: "scale"; from: 0; to: 1 }
HNumberAnimation { property: "scale"; from: 0; to: 1 }
}
} }
move: Transition { move: Transition {
ParallelAnimation { // ScriptAction { script: if (listView.debug) print("move") }
// ScriptAction { script: if (listView.debug) print("move") } HNumberAnimation { property: "opacity"; to: 1 }
HNumberAnimation { property: "opacity"; to: 1 } HNumberAnimation { property: "scale"; to: 1 }
HNumberAnimation { property: "scale"; to: 1 } HNumberAnimation { properties: "x,y" }
HNumberAnimation { properties: "x,y" }
}
} }
remove: Transition { remove: Transition {
ParallelAnimation { // ScriptAction { script: if (listView.debug) print("remove") }
// ScriptAction { script: if (listView.debug) print("remove") } HNumberAnimation { property: "opacity"; to: 0 }
HNumberAnimation { property: "opacity"; to: 0 } HNumberAnimation { property: "scale"; to: 0 }
HNumberAnimation { property: "scale"; to: 0 }
}
} }
displaced: Transition { displaced: Transition {
ParallelAnimation { // ScriptAction { script: if (listView.debug) print("displaced") }
// ScriptAction { script: if (listView.debug) print("displaced") } HNumberAnimation { property: "opacity"; to: 1 }
HNumberAnimation { property: "opacity"; to: 1 } HNumberAnimation { property: "scale"; to: 1 }
HNumberAnimation { property: "scale"; to: 1 } HNumberAnimation { properties: "x,y" }
HNumberAnimation { properties: "x,y" }
}
} }
onSelectedCountChanged: if (! selectedCount) lastCheckedDelegateIndex = 0 onSelectedCountChanged: if (! selectedCount) lastCheckedDelegateIndex = 0

View File

@ -7,14 +7,25 @@ import "../Base"
HListView { HListView {
id: roomList id: roomList
add: null // See the XXX comment in HListView.qml
model: HStringFilterModel { model: HStringFilterModel {
id: filterModel id: filterModel
sourceModel: ModelStore.get("every_room") sourceModel: ModelStore.get("every_room")
field: "display_name" field: "display_name"
delegate: Room { delegate: Room {
id: room
width: roomList.width width: roomList.width
onActivated: showRoomAtIndex(model.index) onActivated: showRoomAtIndex(model.index)
ListView.onAdd: ParallelAnimation {
HNumberAnimation {
target: room; property: "opacity"; from: 0; to: 1;
}
HNumberAnimation {
target: room; property: "scale"; from: 0; to: 1;
}
}
} }
} }

View File

@ -12,12 +12,25 @@ HColumnLayout {
HListView { HListView {
id: memberList id: memberList
clip: true clip: true
add: null // See the XXX comment in HListView.qml
model: HStringFilterModel { model: HStringFilterModel {
sourceModel: ModelStore.get(chat.userId, chat.roomId, "members") sourceModel: ModelStore.get(chat.userId, chat.roomId, "members")
field: "display_name" field: "display_name"
filter: filterField.text filter: filterField.text
delegate: MemberDelegate { width: memberList.width }
delegate: MemberDelegate {
id: member
width: memberList.width
ListView.onAdd: ParallelAnimation {
HNumberAnimation {
target: member; property: "opacity"; from: 0; to: 1;
}
HNumberAnimation {
target: member; property: "scale"; from: 0; to: 1;
}
}
}
} }
Layout.fillWidth: true Layout.fillWidth: true