-
Notifications
You must be signed in to change notification settings - Fork 28.7k
Added boundary feature to ReorderableList. #146182
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
Conversation
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.
Hi @yiiim! Thanks for your patience, and thanks for the PR!
/// When this widget wraps a [ReorderableList], the drag boundary of the [ReorderableList] is confined within this widget. | ||
/// If the [dragBoundingRect] property is provided, the drag boundary is limited to the rectangle returned by [dragBoundingRect]. | ||
/// The boundary is specified in global coordinates. | ||
class ReorderableDragBoundary extends InheritedWidget { |
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.
This is a really neat concept! I just came across #146749 and wondered if this might be beneficial as a generic drag gesture bounding widget, not just for ReorderableList. WDYT?
}); | ||
|
||
/// Return the drag boundary of [ReorderableList]. | ||
final Rect Function(SliverReorderableListState reorderableListCurrentState)? dragBoundingRect; |
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.
This could benefit from typedef-ing the function signature.
/// The [dragBoundingRect] needs to return a rectangle in global coordinates. | ||
const ReorderableDragBoundary({ | ||
required super.child, | ||
this.dragBoundingRect, |
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.
This feels a bit difficult for users to define. Say the user wants to stick within the bounds of the Viewport, since a Viewport will expand to fill all of the available space, how does the user know what that rect is?
I implemented a generic drag gesture boundary here: #147521. This PR needs to be reimplemented after it. |
(triage): We are still waiting on #147521 before we can make progress here. |
(triage) converting to draft for now until the other pr is merged. Feel free to convert back once this is ready for review |
(triage) still waiting for the other pr to merge |
Inspired by the review on #146182. This PR adds boundary feature to the drag gestures, including `MultiDragGestureRecognizer` and `DragGestureRecognizer`. The `GestureDetector` widget will also benefit from this.
22bfa28
to
ce14b02
Compare
ce14b02
to
1ee40b3
Compare
dragOffset = itemRenderBox.globalToLocal(initialPosition); | ||
itemSize = item.context.size!; | ||
_rawDragPosition = initialPosition; | ||
boundary = listState.widget.dragBoundaryProvider?.call(listState.context); |
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.
Have you considered having ReorderableList
inherit the drag boundary through forRectMaybeOf
by default instead of passing it down as a parameter? Or maybe it should do both, inherit by default, and have a parameter that overrides the default inherited provider.
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.
I'm also curious if there is any native behavior we have to compare to on other platforms (if a similar component exists).
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.
Modified to default to using DragBoundary.forRectMaybeOf
.
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.
LGTM
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.
LGTM, thank you for the contribution!
Fixes: #146112
Code sample
DragBoundary
DragBoundary
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.