Use StackView activation callbacks to perform init and cleanup since visibility callbacks aren't guaranteed to run in any order

This commit is contained in:
Cameron Gutman
2019-02-22 22:14:06 -08:00
parent 754a14941b
commit 8037fb76fc
7 changed files with 62 additions and 105 deletions

View File

@@ -20,35 +20,27 @@ GridView {
anchors.bottomMargin: 5
cellWidth: 225; cellHeight: 385;
// The StackView will trigger a visibility change when
// we're pushed onto it, causing our onVisibleChanged
// routine to run, but only if we start as invisible
visible: false
function computerLost()
{
// Go back to the PC view on PC loss
stackView.pop()
}
Component.onCompleted: {
// Don't show any highlighted item until interacting with them
currentIndex = -1
}
SdlGamepadKeyNavigation {
id: gamepadKeyNav
}
onVisibleChanged: {
if (visible) {
appModel.computerLost.connect(computerLost)
gamepadKeyNav.enable()
}
else {
appModel.computerLost.disconnect(computerLost)
gamepadKeyNav.disable()
}
StackView.onActivated: {
appModel.computerLost.connect(computerLost)
gamepadKeyNav.enable()
// Don't show any highlighted item until interacting with them
currentIndex = -1
}
StackView.onDeactivating: {
appModel.computerLost.disconnect(computerLost)
gamepadKeyNav.disable()
}
function createModel()