on xenial help sign in
Add pull-to-refresh functionality to scopes
6a49034Michael Terry
qml/Dash/GenericScopeView.qml+81−1
@@ -15,7 +15,8 @@
15 */
15 */
16
16
17import QtQuick 2.0
17import QtQuick 2.0
18−import Ubuntu.Components 0.1
18+import Ubuntu.Components 1.1
19+import Ubuntu.Components.Styles 1.1
19import Utils 0.1
20import Utils 0.1
20import Unity 0.2
21import Unity 0.2
21import Dash 0.1
22import Dash 0.1
@@ -496,6 +497,85 @@ FocusScope {
496 }
497 }
497 }
498 }
498
499
500+ Rectangle {
501+ id: pullToRefreshClippingRectangle
502+ anchors.left: parent.left
503+ anchors.right: parent.right
504+ anchors.bottom: parent.bottom
505+ height: parent.height - pullToRefresh.contentY + (pageHeaderLoader.item ? pageHeaderLoader.item.bottomItem[0].height - pageHeaderLoader.item.height : 0)
506+ clip: true
507+ color: "#00000000"
508+
509+ PullToRefresh {
510+ id: pullToRefresh
511+ objectName: "pullToRefresh"
512+ target: categoryView
513+
514+ readonly property real contentY: categoryView.contentY - categoryView.originY
515+ y: -contentY - units.gu(5)
516+
517+ onRefresh: {
518+ refreshing = true
519+ scopeView.scope.refresh()
520+ }
521+ anchors.left: parent.left
522+ anchors.right: parent.right
523+
524+ Connections {
525+ target: scopeView
526+ onProcessingChanged: if (!scopeView.processing) pullToRefresh.refreshing = false
527+ }
528+
529+ style: PullToRefreshStyle {
530+ anchors.fill: parent
531+ activationThreshold: units.gu(14)
532+ releaseToRefresh: -pullToRefresh.contentY > activationThreshold
533+
534+ Connections {
535+ target: categoryView
536+ onDraggingChanged: if (!categoryView.dragging && releaseToRefresh) pullToRefresh.refresh()
537+ }
538+
539+ Label {
540+ id: pullLabel
541+ anchors.horizontalCenter: parent.horizontalCenter
542+ horizontalAlignment: Text.AlignHCenter
543+ verticalAlignment: Text.AlignVCenter
544+ states: [
545+ State {
546+ name: "pulling"
547+ when: categoryView.dragging && !releaseToRefresh
548+ PropertyChanges { target: pullLabel; text: i18n.tr("Pull to refresh…") }
549+ },
550+ State {
551+ name: "releasable"
552+ when: categoryView.dragging && releaseToRefresh
553+ PropertyChanges { target: pullLabel; text: i18n.tr("Release to refresh…") }
554+ }
555+ ]
556+ transitions: Transition {
557+ SequentialAnimation {
558+ UbuntuNumberAnimation {
559+ target: pullLabel
560+ property: "opacity"
561+ to: 0.0
562+ }
563+ PropertyAction {
564+ target: pullLabel
565+ property: "text"
566+ }
567+ UbuntuNumberAnimation {
568+ target: pullLabel
569+ property: "opacity"
570+ to: 1.0
571+ }
572+ }
573+ }
574+ }
575+ }
576+ }
577+ }
578+
499 AbstractButton {
579 AbstractButton {
500 id: floatingSeeLess
580 id: floatingSeeLess
501 objectName: "floatingSeeLess"
581 objectName: "floatingSeeLess"
tests/mocks/Unity/fake_scope.cpp+1−1
@@ -266,7 +266,7 @@ QVariantMap Scope::customizations() const
266
266
267void Scope::refresh()
267void Scope::refresh()
268{
268{
269− qDebug() << "Scope::refresh is currently not implmented in the fake scopes plugin";
269+ Q_EMIT refreshed();
270}
270}
271
271
272unity::shell::scopes::NavigationInterface* Scope::getNavigation(const QString& id)
272unity::shell::scopes::NavigationInterface* Scope::getNavigation(const QString& id)
tests/mocks/Unity/fake_scope.h+3
@@ -79,6 +79,9 @@ public:
79
79
80 Q_INVOKABLE void refresh() override;
80 Q_INVOKABLE void refresh() override;
81
81
82+Q_SIGNALS:
83+ void refreshed(); // This is not in the Interface, here for testing benefits
84+
82protected:
85protected:
83
86
84 QString m_id;
87 QString m_id;
tests/qmltests/Dash/tst_GenericScopeView.qml+21
@@ -581,6 +581,27 @@ Item {
581
581
582 genericScopeView.scope = !genericScopeView.scope;
582 genericScopeView.scope = !genericScopeView.scope;
583 }
583 }
584+
585+ function test_pullToRefresh() {
586+ waitForRendering(genericScopeView)
587+
588+ mouseFlick(genericScopeView,
589+ genericScopeView.width/2, units.gu(10),
590+ genericScopeView.width/2, units.gu(80),
591+ true, false)
592+
593+ var pullToRefresh = findChild(genericScopeView, "pullToRefresh")
594+ tryCompare(pullToRefresh, "releaseToRefresh", true)
595+
596+ spy.target = genericScopeView.scope
597+ spy.signalName = "refreshed"
598+
599+ mouseRelease(genericScopeView)
600+ tryCompare(pullToRefresh, "releaseToRefresh", false)
601+
602+ spy.wait()
603+ compare(spy.count, 1)
604+ }
584 }
605 }
585 }
606 }
586}
607}