Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
4ab29de6
Unverified
Commit
4ab29de6
authored
Jul 20, 2021
by
Casey Rogers
Committed by
GitHub
Jul 20, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cancel DraggableScrollableSheet ballistic animation if a new activity begins (#86614)
parent
3d47dd85
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
1 deletion
+50
-1
draggable_scrollable_sheet.dart
...s/flutter/lib/src/widgets/draggable_scrollable_sheet.dart
+16
-1
draggable_scrollable_sheet_test.dart
...flutter/test/widgets/draggable_scrollable_sheet_test.dart
+34
-0
No files found.
packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart
View file @
4ab29de6
...
...
@@ -10,6 +10,7 @@ import 'framework.dart';
import
'inherited_notifier.dart'
;
import
'layout_builder.dart'
;
import
'notification_listener.dart'
;
import
'scroll_activity.dart'
;
import
'scroll_context.dart'
;
import
'scroll_controller.dart'
;
import
'scroll_notification.dart'
;
...
...
@@ -431,9 +432,17 @@ class _DraggableScrollableSheetScrollPosition
);
VoidCallback
?
_dragCancelCallback
;
VoidCallback
?
_ballisticCancelCallback
;
final
_DraggableSheetExtent
extent
;
bool
get
listShouldScroll
=>
pixels
>
0.0
;
@override
void
beginActivity
(
ScrollActivity
?
newActivity
)
{
// Cancel the running ballistic simulation, if there is one.
_ballisticCancelCallback
?.
call
();
super
.
beginActivity
(
newActivity
);
}
@override
bool
applyContentDimensions
(
double
minScrollExtent
,
double
maxScrollExtent
)
{
// We need to provide some extra extent if we haven't yet reached the max or
...
...
@@ -481,6 +490,9 @@ class _DraggableScrollableSheetScrollPosition
debugLabel:
objectRuntimeType
(
this
,
'_DraggableScrollableSheetPosition'
),
vsync:
context
.
vsync
,
);
// Stop the ballistic animation if a new activity starts.
// See: [beginActivity].
_ballisticCancelCallback
=
ballisticController
.
stop
;
double
lastDelta
=
0
;
void
_tick
()
{
final
double
delta
=
ballisticController
.
value
-
lastDelta
;
...
...
@@ -501,7 +513,10 @@ class _DraggableScrollableSheetScrollPosition
ballisticController
..
addListener
(
_tick
)
..
animateWith
(
simulation
).
whenCompleteOrCancel
(
ballisticController
.
dispose
,
()
{
_ballisticCancelCallback
=
null
;
ballisticController
.
dispose
();
},
);
}
...
...
packages/flutter/test/widgets/draggable_scrollable_sheet_test.dart
View file @
4ab29de6
...
...
@@ -264,6 +264,40 @@ void main() {
expect
(
find
.
text
(
'Item 70'
),
findsNothing
);
},
variant:
TargetPlatformVariant
.
all
());
testWidgets
(
'Ballistic animation on fling can be interrupted'
,
(
WidgetTester
tester
)
async
{
int
taps
=
0
;
await
tester
.
pumpWidget
(
_boilerplate
(()
=>
taps
++));
expect
(
find
.
text
(
'TapHere'
),
findsOneWidget
);
await
tester
.
tap
(
find
.
text
(
'TapHere'
));
expect
(
taps
,
1
);
expect
(
find
.
text
(
'Item 1'
),
findsOneWidget
);
expect
(
find
.
text
(
'Item 31'
),
findsNothing
);
expect
(
find
.
text
(
'Item 70'
),
findsNothing
);
await
tester
.
fling
(
find
.
text
(
'Item 1'
),
const
Offset
(
0
,
-
200
),
2000
);
// Don't pump and settle because we want to interrupt the ballistic scrolling animation.
expect
(
find
.
text
(
'TapHere'
),
findsOneWidget
);
await
tester
.
tap
(
find
.
text
(
'TapHere'
),
warnIfMissed:
false
);
expect
(
taps
,
2
);
expect
(
find
.
text
(
'Item 1'
),
findsOneWidget
);
expect
(
find
.
text
(
'Item 31'
),
findsOneWidget
);
expect
(
find
.
text
(
'Item 70'
),
findsNothing
);
// Use `dragFrom` here because calling `drag` on a list item without
// first calling `pumpAndSettle` fails with a hit test error.
await
tester
.
dragFrom
(
const
Offset
(
0
,
200
),
const
Offset
(
0
,
200
));
await
tester
.
pumpAndSettle
();
// Verify that the ballistic animation has canceled and the sheet has
// returned to it's original position.
await
tester
.
tap
(
find
.
text
(
'TapHere'
));
expect
(
taps
,
3
);
expect
(
find
.
text
(
'Item 1'
),
findsOneWidget
);
expect
(
find
.
text
(
'Item 31'
),
findsNothing
);
expect
(
find
.
text
(
'Item 70'
),
findsNothing
);
},
variant:
TargetPlatformVariant
.
all
());
debugDefaultTargetPlatformOverride
=
null
;
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment