Component {
id: searchHeader
Item {
id: searchRectangle
// Size
width: parent.width
height: (state == "visible") ? 70 : 0
TextField {
id: searchField
anchors.fill: parent
anchors.margins: 5
focus: false
onActiveFocusChanged: (searchField.activeFocus) ? autoHideTimer.stop() : autoHideTimer.restart()
placeholderText: "Search"
ToolIcon {
id: searchIcon
iconId: "toolbar-search";
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
}
}
// Make searchRectangle available to other items
Component.onCompleted: list.headerItem = searchRectangle
Component.onDestruction: list.headerItem = null
// Define initial status. States = [hidden, visible]
// At beginning header must to be visible to show cursor
// when input item receives the focus
state: "visible"
onStateChanged: console.log("STATE" + searchField.state)
// Autohide timer
Timer {
id: autoHideTimer
interval: 2000
onTriggered: searchRectangle.state = "hidden"
running: true
}
function startTimer(){
// Doesn't hide search field if it has focus
if (!searchField.activeFocus)
autoHideTimer.restart();
}
}
}
ListView {
anchors.fill: parent
id: list
model: 100
header: searchHeader
property Item headerItem: null
delegate: Rectangle {
width: list.width
height: 50
Text {
text: index
}
}
onMovementStarted: headerItem.state = "visible";
onMovementEnded: headerItem.startTimer();
}