-
Notifications
You must be signed in to change notification settings - Fork 90
WIP feat: close the bottom sheet on a swipe down #19109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
caybro
wants to merge
1
commit into
master
Choose a base branch
from
feat/swipe-to-close-dialog-bottomSheet
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
ui/StatusQ/src/StatusQ/Components/private/StatusBottomSheetDragHandle.qml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import QtQuick | ||
|
|
||
| import StatusQ.Core.Theme | ||
|
|
||
| Rectangle { | ||
| id: root | ||
|
|
||
| // To be used together with components deriving from QQC2.Popup | ||
|
|
||
| // required to provide the drag/swipe functionality (must have a contentItem to parent to) | ||
| // if not provided, acts just like a visual indicator | ||
| property var dragObjectRoot | ||
|
|
||
| // threshold in pixels after which the closeRequested() signal is emitted | ||
| property int dragToCloseThreshold: 100 | ||
|
|
||
| // returns whether the drag operation is currently active | ||
| readonly property bool active: dragHandler.active | ||
|
|
||
| // emitted when dragToCloseThreshold has been reached | ||
| signal closeRequested() | ||
|
|
||
| // required to setup the "original" Y position, e.g. when switching to the `bottomSheet` mode | ||
| // to be able to return to bounds if dropped when the dragToCloseThreshold hasn't been reached | ||
| function setOriginalYPos(oldY) { | ||
| d.accuY = 0 | ||
| d.oldY = oldY | ||
| } | ||
|
|
||
| implicitWidth: 64 | ||
| implicitHeight: 4 | ||
| radius: 2 | ||
| color: Theme.palette.baseColor1 | ||
|
|
||
| QtObject { | ||
| id: d | ||
| property int oldY | ||
|
|
||
| property real accuY | ||
| onAccuYChanged: if (accuY > dragToCloseThreshold) root.closeRequested() | ||
| } | ||
|
|
||
| Connections { | ||
| target: root.dragObjectRoot ?? null | ||
| function onOpened() { // reset the accumulated drag, and sets | ||
| setOriginalYPos(root.dragObjectRoot.y) | ||
| } | ||
| } | ||
|
|
||
| DragHandler { | ||
| id: dragHandler | ||
| target: null | ||
|
|
||
| margin: 20 | ||
| onActiveChanged: { | ||
| if (active) { | ||
| root.dragObjectRoot.anchors.centerIn = undefined // tear out, start moving | ||
| } else { | ||
| root.dragObjectRoot.y = d.oldY // return to bounds | ||
| d.accuY = 0 | ||
| } | ||
| } | ||
|
|
||
| xAxis.enabled: false | ||
| yAxis.enabled: true | ||
| yAxis.minimum: d.oldY | ||
| yAxis.onActiveValueChanged: function(value) { | ||
| if (value > 0) { // can't drag up | ||
| root.dragObjectRoot.y += value | ||
| d.accuY += value | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,12 +1,11 @@ | ||||||
| import QtQuick | ||||||
| import QtQuick.Controls | ||||||
| import QtQuick.Window | ||||||
| import QtQuick.Layouts | ||||||
| import QtQml.Models | ||||||
| import QtQml | ||||||
|
|
||||||
| import StatusQ.Core | ||||||
| import StatusQ.Controls | ||||||
| import StatusQ.Components.private | ||||||
| import StatusQ.Core.Theme | ||||||
|
|
||||||
| Dialog { | ||||||
|
|
@@ -41,6 +40,7 @@ Dialog { | |||||
|
|
||||||
| readonly property bool bottomSheet: d.windowHeight > d.windowWidth | ||||||
| && d.windowWidth <= Theme.portraitBreakpoint.width // The max width of a phone in portrait mode | ||||||
| onBottomSheetChanged: if (bottomSheet) Qt.callLater(() => d.dragHandle.setOriginalYPos(root.desiredY)) | ||||||
|
|
||||||
| readonly property real desiredY: root.bottomSheet ? d.windowHeight - root.height | ||||||
| : (root.Overlay.overlay.height - root.height) / 2 | ||||||
|
|
@@ -61,6 +61,18 @@ Dialog { | |||||
| property int windowHeight | ||||||
|
|
||||||
| readonly property real bottomSheetHeightRatio: 0.90 | ||||||
|
|
||||||
| // must not be a "visual" item, gets overwritten with contentItem or ScrollView's own contentItem | ||||||
| readonly property StatusBottomSheetDragHandle dragHandle: StatusBottomSheetDragHandle { | ||||||
| dragObjectRoot: root | ||||||
| onCloseRequested: root.closeHandler() | ||||||
|
|
||||||
| anchors.top: parent.top | ||||||
| anchors.horizontalCenter: parent.horizontalCenter | ||||||
| anchors.topMargin: Theme.halfPadding | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| visible: root.bottomSheet | ||||||
| parent: root.contentItem.parent | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| onAboutToShow: { | ||||||
|
|
@@ -145,6 +157,14 @@ Dialog { | |||||
| value: -1 | ||||||
| } | ||||||
|
|
||||||
| Binding { | ||||||
| target: header ?? null | ||||||
| when: !!header | ||||||
| property: "showDragHandle" | ||||||
| value: root.bottomSheet | ||||||
| delayed: true | ||||||
| } | ||||||
|
|
||||||
| parent: Overlay.overlay | ||||||
|
|
||||||
| modal: true | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,13 +4,15 @@ import Qt5Compat.GraphicalEffects | |||||
|
|
||||||
| import StatusQ.Core | ||||||
| import StatusQ.Core.Theme | ||||||
| import StatusQ.Components.private | ||||||
|
|
||||||
| Rectangle { | ||||||
| id: root | ||||||
|
|
||||||
| readonly property alias headline: headline | ||||||
| readonly property alias actions: actions | ||||||
| property bool dropShadowEnabled | ||||||
| property bool showDragHandle | ||||||
|
|
||||||
| property alias leftComponent: leftComponentLoader.sourceComponent | ||||||
|
|
||||||
|
|
@@ -105,4 +107,12 @@ Rectangle { | |||||
| active: root.internalPopupActive | ||||||
| sourceComponent: root.internalPopupComponent | ||||||
| } | ||||||
|
|
||||||
| // just a visual handle; the drag operation is done in StatusDialog | ||||||
| StatusBottomSheetDragHandle { | ||||||
| anchors.top: parent.top | ||||||
| anchors.topMargin: Theme.halfPadding | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| anchors.horizontalCenter: parent.horizontalCenter | ||||||
| visible: root.showDragHandle | ||||||
| } | ||||||
| } | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The padding is way too small on mobile