Unity 8
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 
17 import QtQuick 2.4
18 import Ubuntu.Components 1.3
19 import Ubuntu.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  */
26 PullToRefreshStyle {
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  states: [
52  State {
53  name: "pulling"
54  when: styledItem.target.dragging && !releaseToRefresh
55  PropertyChanges { target: pullLabel; text: i18n.tr("Pull to refresh…") }
56  },
57  State {
58  name: "releasable"
59  when: styledItem.target.dragging && releaseToRefresh
60  PropertyChanges { target: pullLabel; text: i18n.tr("Release to refresh…") }
61  }
62  ]
63  transitions: Transition {
64  SequentialAnimation {
65  UbuntuNumberAnimation {
66  target: pullLabel
67  property: "opacity"
68  to: 0.0
69  }
70  PropertyAction {
71  target: pullLabel
72  property: "text"
73  }
74  UbuntuNumberAnimation {
75  target: pullLabel
76  property: "opacity"
77  to: 1.0
78  }
79  }
80  }
81  }
82 }