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
ff6aa928
Unverified
Commit
ff6aa928
authored
Sep 19, 2022
by
Taha Tesser
Committed by
GitHub
Sep 19, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix `Scrollbar` thumb drag behavior on desktop. (#111250)
parent
f4c2ace9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
161 additions
and
1 deletion
+161
-1
scrollbar.dart
packages/flutter/lib/src/widgets/scrollbar.dart
+23
-1
scrollbar_test.dart
packages/flutter/test/widgets/scrollbar_test.dart
+138
-0
No files found.
packages/flutter/lib/src/widgets/scrollbar.dart
View file @
ff6aa928
...
...
@@ -1447,6 +1447,7 @@ class RawScrollbar extends StatefulWidget {
/// scrollbar track.
class
RawScrollbarState
<
T
extends
RawScrollbar
>
extends
State
<
T
>
with
TickerProviderStateMixin
<
T
>
{
Offset
?
_dragScrollbarAxisOffset
;
late
double
?
_thumbPress
;
ScrollController
?
_currentController
;
Timer
?
_fadeoutTimer
;
late
AnimationController
_fadeoutAnimationController
;
...
...
@@ -1785,6 +1786,9 @@ class RawScrollbarState<T extends RawScrollbar> extends State<T> with TickerProv
_fadeoutTimer
?.
cancel
();
_fadeoutAnimationController
.
forward
();
_dragScrollbarAxisOffset
=
localPosition
;
_thumbPress
=
direction
==
Axis
.
vertical
?
localPosition
.
dy
-
scrollbarPainter
.
_thumbOffset
:
localPosition
.
dx
-
scrollbarPainter
.
_thumbOffset
;
}
/// Handler called when a currently active long press gesture moves.
...
...
@@ -1802,10 +1806,28 @@ class RawScrollbarState<T extends RawScrollbar> extends State<T> with TickerProv
if
(
direction
==
null
)
{
return
;
}
_updateScrollPosition
(
localPosition
);
switch
(
position
.
axisDirection
)
{
case
AxisDirection
.
up
:
case
AxisDirection
.
down
:
if
(
_canDragThumb
(
_dragScrollbarAxisOffset
!.
dy
,
position
.
viewportDimension
,
_thumbPress
!))
{
_updateScrollPosition
(
localPosition
);
}
break
;
case
AxisDirection
.
left
:
case
AxisDirection
.
right
:
if
(
_canDragThumb
(
_dragScrollbarAxisOffset
!.
dx
,
position
.
viewportDimension
,
_thumbPress
!))
{
_updateScrollPosition
(
localPosition
);
}
break
;
}
_dragScrollbarAxisOffset
=
localPosition
;
}
bool
_canDragThumb
(
double
dragOffset
,
double
viewport
,
double
thumbPress
)
{
return
dragOffset
>=
thumbPress
&&
dragOffset
<=
viewport
-
(
scrollbarPainter
.
_thumbExtent
-
thumbPress
);
}
/// Handler called when a long press has ended.
@protected
@mustCallSuper
...
...
packages/flutter/test/widgets/scrollbar_test.dart
View file @
ff6aa928
...
...
@@ -2717,4 +2717,142 @@ void main() {
expect
(
scrollController
.
offset
,
0.0
);
});
testWidgets
(
'Scrollbar thumb can only be dragged from long press point'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/107765
final
ScrollController
scrollController
=
ScrollController
();
final
UniqueKey
uniqueKey
=
UniqueKey
();
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
MediaQuery
(
data:
const
MediaQueryData
(),
child:
ScrollConfiguration
(
behavior:
const
ScrollBehavior
().
copyWith
(
scrollbars:
false
,
),
child:
PrimaryScrollController
(
controller:
scrollController
,
child:
RawScrollbar
(
isAlwaysShown:
true
,
controller:
scrollController
,
child:
CustomScrollView
(
primary:
true
,
slivers:
<
Widget
>[
SliverToBoxAdapter
(
child:
Container
(
height:
600.0
,
),
),
SliverToBoxAdapter
(
key:
uniqueKey
,
child:
Container
(
height:
600.0
,
),
),
SliverToBoxAdapter
(
child:
Container
(
height:
600.0
,
),
),
],
),
),
),
),
),
),
);
await
tester
.
pumpAndSettle
();
expect
(
scrollController
.
offset
,
0.0
);
expect
(
find
.
byType
(
RawScrollbar
),
paints
..
rect
(
rect:
const
Rect
.
fromLTRB
(
794.0
,
0.0
,
800.0
,
600.0
))
..
rect
(
rect:
const
Rect
.
fromLTRB
(
794.0
,
0.0
,
800.0
,
200.0
),
color:
const
Color
(
0x66BCBCBC
),
),
);
// Long press on the thumb in the center and drag down to the bottom.
const
double
scrollAmount
=
400.0
;
final
TestGesture
dragScrollbarGesture
=
await
tester
.
startGesture
(
const
Offset
(
797.0
,
100.0
));
await
tester
.
pumpAndSettle
();
await
dragScrollbarGesture
.
moveBy
(
const
Offset
(
0.0
,
scrollAmount
));
await
tester
.
pumpAndSettle
();
// Drag down past the long press point.
await
dragScrollbarGesture
.
moveBy
(
const
Offset
(
0.0
,
100
));
await
tester
.
pumpAndSettle
();
// Drag up without reaching press point on the thumb.
await
dragScrollbarGesture
.
moveBy
(
const
Offset
(
0.0
,
-
50
));
await
tester
.
pumpAndSettle
();
// Thumb should not move yet.
expect
(
find
.
byType
(
RawScrollbar
),
paints
..
rect
(
rect:
const
Rect
.
fromLTRB
(
794.0
,
0.0
,
800.0
,
600.0
))
..
rect
(
rect:
const
Rect
.
fromLTRB
(
794.0
,
400.0
,
800.0
,
600.0
),
color:
const
Color
(
0x66BCBCBC
),
),
);
// Drag up to reach press point on the thumb.
await
dragScrollbarGesture
.
moveBy
(
const
Offset
(
0.0
,
-
50
));
await
tester
.
pumpAndSettle
();
// Drag up.
await
dragScrollbarGesture
.
moveBy
(
const
Offset
(
0.0
,
-
300
));
await
tester
.
pumpAndSettle
();
// Thumb should be moved.
expect
(
find
.
byType
(
RawScrollbar
),
paints
..
rect
(
rect:
const
Rect
.
fromLTRB
(
794.0
,
0.0
,
800.0
,
600.0
))
..
rect
(
rect:
const
Rect
.
fromLTRB
(
794.0
,
100.0
,
800.0
,
300.0
),
color:
const
Color
(
0x66BCBCBC
),
),
);
// Drag up to reach the top and exceed the long press point.
await
dragScrollbarGesture
.
moveBy
(
const
Offset
(
0.0
,
-
200
));
await
tester
.
pumpAndSettle
();
// Drag down to reach the long press point.
await
dragScrollbarGesture
.
moveBy
(
const
Offset
(
0.0
,
100
));
await
tester
.
pumpAndSettle
();
// Thumb should not move yet.
expect
(
find
.
byType
(
RawScrollbar
),
paints
..
rect
(
rect:
const
Rect
.
fromLTRB
(
794.0
,
0.0
,
800.0
,
600.0
))
..
rect
(
rect:
const
Rect
.
fromLTRB
(
794.0
,
0.0
,
800.0
,
200.0
),
color:
const
Color
(
0x66BCBCBC
),
),
);
// Drag down past the long press point.
await
dragScrollbarGesture
.
moveBy
(
const
Offset
(
0.0
,
100
));
await
tester
.
pumpAndSettle
();
// Thumb should be moved.
expect
(
find
.
byType
(
RawScrollbar
),
paints
..
rect
(
rect:
const
Rect
.
fromLTRB
(
794.0
,
0.0
,
800.0
,
600.0
))
..
rect
(
rect:
const
Rect
.
fromLTRB
(
794.0
,
100.0
,
800.0
,
300.0
),
color:
const
Color
(
0x66BCBCBC
),
),
);
},
variant:
TargetPlatformVariant
.
desktop
());
}
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