on xenial help sign in
Add pull-to-refresh functionality to scopes
commit6a490343561807e92f800a400200067fa5d12d98 authorMichael Terry <michael.terry@canonical.com> dateFri 26 Sep 2014, 15:47 (12 years ago) parentff9936d
4 files changed+106−2
qml/Dash/GenericScopeView.qml+81−1 tests/mocks/Unity/fake_scope.cpp+1−1 tests/mocks/Unity/fake_scope.h+3 tests/qmltests/Dash/tst_GenericScopeView.qml+21
qml/Dash/GenericScopeView.qml+81−1
@@ -15,7 +15,8 @@
1515 */
1616
1717import QtQuick 2.0
18−import Ubuntu.Components 0.1
18+import Ubuntu.Components 1.1
19+import Ubuntu.Components.Styles 1.1
1920import Utils 0.1
2021import Unity 0.2
2122import Dash 0.1
@@ -496,6 +497,85 @@ FocusScope {
496497 }
497498 }
498499
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+
499579 AbstractButton {
500580 id: floatingSeeLess
501581 objectName: "floatingSeeLess"
tests/mocks/Unity/fake_scope.cpp+1−1
@@ -266,7 +266,7 @@ QVariantMap Scope::customizations() const
266266
267267void Scope::refresh()
268268{
269− qDebug() << "Scope::refresh is currently not implmented in the fake scopes plugin";
269+ Q_EMIT refreshed();
270270}
271271
272272unity::shell::scopes::NavigationInterface* Scope::getNavigation(const QString& id)
tests/mocks/Unity/fake_scope.h+3
@@ -79,6 +79,9 @@ public:
7979
8080 Q_INVOKABLE void refresh() override;
8181
82+Q_SIGNALS:
83+ void refreshed(); // This is not in the Interface, here for testing benefits
84+
8285protected:
8386
8487 QString m_id;
tests/qmltests/Dash/tst_GenericScopeView.qml+21
@@ -581,6 +581,27 @@ Item {
581581
582582 genericScopeView.scope = !genericScopeView.scope;
583583 }
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+ }
584605 }
585606 }
586607}