Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 3 commits into from
Dec 6, 2024

Conversation

yiiim
Copy link
Member

@yiiim yiiim commented Apr 3, 2024

Fixes: #146112

Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(
    home: Scaffold(
      body: Center(
        child: Container(
          width: 200,
          color: Colors.green,
          child: DragBoundary(
            child: CustomScrollView(
              shrinkWrap: true,
              slivers: <Widget>[
                SliverReorderableList(
                  itemBuilder: (BuildContext context, int index) {
                    return ReorderableDragStartListener(
                      key: ValueKey<int>(index),
                      index: index,
                      child: Text('$index'),
                    );
                  },
                  itemCount: 5,
                  onReorder: (int fromIndex, int toIndex) {},
                ),
              ],
            ),
          ),
        ),
      ),
    ),
  ));
}
without DragBoundary with the DragBoundary
Screen Recording 2024-04-03 at 13 01 19 Screen Recording 2024-04-03 at 13 01 19

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Apr 3, 2024
@yiiim yiiim requested a review from Piinks April 4, 2024 07:57
Copy link
Contributor

@Piinks Piinks left a 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 {
Copy link
Contributor

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;
Copy link
Contributor

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,
Copy link
Contributor

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?

@Piinks Piinks added c: new feature Nothing broken; request for a new capability f: scrolling Viewports, list views, slivers, etc. labels Apr 17, 2024
@yiiim
Copy link
Member Author

yiiim commented Apr 29, 2024

I implemented a generic drag gesture boundary here: #147521. This PR needs to be reimplemented after it.

@goderbauer
Copy link
Member

(triage): We are still waiting on #147521 before we can make progress here.

@chunhtai chunhtai marked this pull request as draft July 30, 2024 22:08
@chunhtai
Copy link
Contributor

(triage) converting to draft for now until the other pr is merged. Feel free to convert back once this is ready for review

@chunhtai
Copy link
Contributor

chunhtai commented Oct 1, 2024

(triage) still waiting for the other pr to merge

auto-submit bot pushed a commit that referenced this pull request Oct 30, 2024
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.
@yiiim yiiim force-pushed the ReorderableDragBoundary branch from 22bfa28 to ce14b02 Compare November 9, 2024 07:35
@github-actions github-actions bot removed the f: scrolling Viewports, list views, slivers, etc. label Nov 9, 2024
@yiiim yiiim force-pushed the ReorderableDragBoundary branch from ce14b02 to 1ee40b3 Compare November 9, 2024 08:06
@github-actions github-actions bot added the f: material design flutter/packages/flutter/material repository. label Nov 9, 2024
@yiiim yiiim changed the title New Widget: ReorderableDragBoundary, used to define the drag boundaries of ReorderableList. Added boundary feature to ReorderableList. Nov 9, 2024
@yiiim yiiim marked this pull request as ready for review November 9, 2024 08:40
@yiiim yiiim requested a review from Piinks November 9, 2024 08:40
@Piinks Piinks requested review from Renzo-Olivares and dkwingsmt and removed request for Piinks November 13, 2024 23:15
dragOffset = itemRenderBox.globalToLocal(initialPosition);
itemSize = item.context.size!;
_rawDragPosition = initialPosition;
boundary = listState.widget.dragBoundaryProvider?.call(listState.context);
Copy link
Contributor

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.

Copy link
Contributor

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).

Copy link
Member Author

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.

Copy link
Contributor

@dkwingsmt dkwingsmt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@Renzo-Olivares Renzo-Olivares left a 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!

@yiiim yiiim added the autosubmit Merge PR when tree becomes green via auto submit App label Dec 6, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 8, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 9, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 9, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 9, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 9, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 10, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 10, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 10, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 10, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 10, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 10, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 11, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 11, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 11, 2024
@reidbaker reidbaker mentioned this pull request Dec 13, 2024
11 tasks
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 12, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: new feature Nothing broken; request for a new capability f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal to set boundary for the ReorderableListView when dragging item
6 participants