Lomiri
Loading...
Searching...
No Matches
PullToRefreshScopeStyle.qml
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17import QtQuick 2.12
18import Lomiri.Components 1.3
19import Lomiri.Components.Styles 1.3
20
21/**
22 * TODO: Once the SDK version of PullToRefreshStyle doesn't have bug 1375799
23 * (https://launchpad.net/bugs/1375799) anymore, we should switch to using a
24 * a subclass of the Ambiance version with a hidden ActivityIndicator.
25 */
26PullToRefreshStyle {
27 releaseToRefresh: styledItem.target.originY - styledItem.target.contentY > activationThreshold
28
29 Connections {
30 property bool willRefresh: false
31
32 target: styledItem.target
33 onDraggingChanged: {
34 if (!styledItem.target.dragging && releaseToRefresh) {
35 willRefresh = true
36 }
37 }
38 onContentYChanged: {
39 if (styledItem.target.originY - styledItem.target.contentY == 0 && willRefresh) {
40 styledItem.refresh()
41 willRefresh = false
42 }
43 }
44 }
45
46 Label {
47 id: pullLabel
48 anchors.horizontalCenter: parent.horizontalCenter
49 horizontalAlignment: Text.AlignHCenter
50 verticalAlignment: Text.AlignVCenter
51 color: styledItem.pullLabelColor
52 states: [
53 State {
54 name: "pulling"
55 when: styledItem.target.dragging && !releaseToRefresh
56 PropertyChanges { target: pullLabel; text: i18n.tr("Pull to refresh…") }
57 },
58 State {
59 name: "releasable"
60 when: styledItem.target.dragging && releaseToRefresh
61 PropertyChanges { target: pullLabel; text: i18n.tr("Release to refresh…") }
62 }
63 ]
64 transitions: Transition {
65 SequentialAnimation {
66 LomiriNumberAnimation {
67 target: pullLabel
68 property: "opacity"
69 to: 0.0
70 }
71 PropertyAction {
72 target: pullLabel
73 property: "text"
74 }
75 LomiriNumberAnimation {
76 target: pullLabel
77 property: "opacity"
78 to: 1.0
79 }
80 }
81 }
82 }
83}