Unverified Commit 2f521a21 authored by chunhtai's avatar chunhtai Committed by GitHub

Increases the eyeballed value of auto scroll velocity scalar (#127410)

A previous pr fixed an bug in the autoscalar's speed calculation. The calculation would produce much lower speed after the fix. This pr raised the default scalar value for reorderable list.

fixes https://github.com/flutter/flutter/issues/121603
parent bbecb038
......@@ -273,6 +273,8 @@ class ReorderableListView extends StatefulWidget {
final Widget? prototypeItem;
/// {@macro flutter.widgets.EdgeDraggingAutoScroller.velocityScalar}
///
/// {@macro flutter.widgets.SliverReorderableList.autoScrollerVelocityScalar.default}
final double? autoScrollerVelocityScalar;
@override
......
......@@ -257,6 +257,8 @@ class ReorderableList extends StatefulWidget {
final Widget? prototypeItem;
/// {@macro flutter.widgets.EdgeDraggingAutoScroller.velocityScalar}
///
/// {@macro flutter.widgets.SliverReorderableList.autoScrollerVelocityScalar.default}
final double? autoScrollerVelocityScalar;
/// The state from the closest instance of this class that encloses the given
......@@ -450,13 +452,17 @@ class SliverReorderableList extends StatefulWidget {
this.itemExtent,
this.prototypeItem,
this.proxyDecorator,
this.autoScrollerVelocityScalar,
}) : assert(itemCount >= 0),
double? autoScrollerVelocityScalar,
}) : autoScrollerVelocityScalar = autoScrollerVelocityScalar ?? _kDefaultAutoScrollVelocityScalar,
assert(itemCount >= 0),
assert(
itemExtent == null || prototypeItem == null,
'You can only pass itemExtent or prototypeItem, not both',
);
// An eyeballed value for a smooth scrolling experience.
static const double _kDefaultAutoScrollVelocityScalar = 50;
/// {@macro flutter.widgets.reorderable_list.itemBuilder}
final IndexedWidgetBuilder itemBuilder;
......@@ -485,7 +491,11 @@ class SliverReorderableList extends StatefulWidget {
final Widget? prototypeItem;
/// {@macro flutter.widgets.EdgeDraggingAutoScroller.velocityScalar}
final double? autoScrollerVelocityScalar;
///
/// {@template flutter.widgets.SliverReorderableList.autoScrollerVelocityScalar.default}
/// Defaults to 50 if not set or set to null.
/// {@endtemplate}
final double autoScrollerVelocityScalar;
@override
SliverReorderableListState createState() => SliverReorderableListState();
......
......@@ -158,11 +158,8 @@ class EdgeDraggingAutoScroller {
EdgeDraggingAutoScroller(
this.scrollable, {
this.onScrollViewScrolled,
double? velocityScalar,
}): velocityScalar = velocityScalar ?? _kDefaultAutoScrollVelocityScalar;
// An eyeballed value for a smooth scrolling experience.
static const double _kDefaultAutoScrollVelocityScalar = 7;
required this.velocityScalar,
});
/// The [Scrollable] this auto scroller is scrolling.
final ScrollableState scrollable;
......@@ -179,8 +176,6 @@ class EdgeDraggingAutoScroller {
///
/// It represents how the velocity scale with the over scroll distance. The
/// auto-scroll velocity = <distance of overscroll> * velocityScalar.
///
/// Defaults to 7 if not set or set to null.
/// {@endtemplate}
final double velocityScalar;
......
......@@ -474,6 +474,45 @@ void main() {
expect(customController.offset, 120.0);
});
testWidgets('ReorderableList auto scrolling is fast enough', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/121603.
final ScrollController controller = ScrollController();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: ReorderableListView.builder(
scrollController: controller,
itemCount: 100,
itemBuilder: (BuildContext context, int index) {
return Text('data', key: ValueKey<int>(index));
},
onReorder: (int oldIndex, int newIndex) {},
),
),
),
);
// Start gesture on first item.
final TestGesture drag = await tester.startGesture(tester.getCenter(find.byKey(const ValueKey<int>(0))));
await tester.pump(kLongPressTimeout + kPressTimeout);
final Offset bottomRight = tester.getBottomRight(find.byType(ReorderableListView));
// Drag enough for move to start.
await drag.moveTo(Offset(bottomRight.dx / 2, bottomRight.dy));
await tester.pump();
// Use a fixed value to make sure the default velocity scalar is bigger
// than a certain amount.
const double kMinimumAllowedAutoScrollDistancePer5ms = 1.7;
await tester.pump(const Duration(milliseconds: 5));
expect(controller.offset, greaterThan(kMinimumAllowedAutoScrollDistancePer5ms));
await tester.pump(const Duration(milliseconds: 5));
expect(controller.offset, greaterThan(kMinimumAllowedAutoScrollDistancePer5ms * 2));
await tester.pump(const Duration(milliseconds: 5));
expect(controller.offset, greaterThan(kMinimumAllowedAutoScrollDistancePer5ms * 3));
await tester.pump(const Duration(milliseconds: 5));
expect(controller.offset, greaterThan(kMinimumAllowedAutoScrollDistancePer5ms * 4));
});
testWidgets('Still builds when no PrimaryScrollController is available', (WidgetTester tester) async {
final Widget reorderableList = ReorderableListView(
children: const <Widget>[
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment