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
a30d816a
Unverified
Commit
a30d816a
authored
Oct 25, 2022
by
youssef ali
Committed by
GitHub
Oct 25, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix stretch effect with rtl support (#113214)
parent
e76f8831
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
139 additions
and
8 deletions
+139
-8
overscroll_indicator.dart
packages/flutter/lib/src/widgets/overscroll_indicator.dart
+6
-6
overscroll_stretch_indicator_test.dart
...utter/test/widgets/overscroll_stretch_indicator_test.dart
+133
-2
No files found.
packages/flutter/lib/src/widgets/overscroll_indicator.dart
View file @
a30d816a
...
...
@@ -744,7 +744,7 @@ class _StretchingOverscrollIndicatorState extends State<StretchingOverscrollIndi
return
false
;
}
Alignment
Directional
_getAlignmentForAxisDirection
(
double
overscroll
)
{
Alignment
Geometry
_getAlignmentForAxisDirection
(
double
overscroll
)
{
// Accounts for reversed scrollables by checking the AxisDirection
switch
(
widget
.
axisDirection
)
{
case
AxisDirection
.
up
:
...
...
@@ -753,16 +753,16 @@ class _StretchingOverscrollIndicatorState extends State<StretchingOverscrollIndi
:
AlignmentDirectional
.
bottomCenter
;
case
AxisDirection
.
right
:
return
overscroll
>
0
?
Alignment
Directional
.
centerEnd
:
Alignment
Directional
.
centerStar
t
;
?
Alignment
.
centerRight
:
Alignment
.
centerLef
t
;
case
AxisDirection
.
down
:
return
overscroll
>
0
?
AlignmentDirectional
.
bottomCenter
:
AlignmentDirectional
.
topCenter
;
case
AxisDirection
.
left
:
return
overscroll
>
0
?
Alignment
Directional
.
centerStar
t
:
Alignment
Directional
.
centerEnd
;
?
Alignment
.
centerLef
t
:
Alignment
.
centerRight
;
}
}
...
...
@@ -796,7 +796,7 @@ class _StretchingOverscrollIndicatorState extends State<StretchingOverscrollIndi
break
;
}
final
Alignment
Directional
alignment
=
_getAlignmentForAxisDirection
(
final
Alignment
Geometry
alignment
=
_getAlignmentForAxisDirection
(
_lastOverscrollNotification
?.
overscroll
??
0.0
);
...
...
packages/flutter/test/widgets/overscroll_stretch_indicator_test.dart
View file @
a30d816a
...
...
@@ -18,11 +18,16 @@ void main() {
ScrollController
controller
,
{
Axis
axis
=
Axis
.
vertical
,
bool
reverse
=
false
,
TextDirection
textDirection
=
TextDirection
.
ltr
,
})
{
final
AxisDirection
axisDirection
;
switch
(
axis
)
{
case
Axis
.
horizontal
:
axisDirection
=
reverse
?
AxisDirection
.
left
:
AxisDirection
.
right
;
if
(
textDirection
==
TextDirection
.
rtl
)
{
axisDirection
=
reverse
?
AxisDirection
.
right
:
AxisDirection
.
left
;
}
else
{
axisDirection
=
reverse
?
AxisDirection
.
left
:
AxisDirection
.
right
;
}
break
;
case
Axis
.
vertical
:
axisDirection
=
reverse
?
AxisDirection
.
up
:
AxisDirection
.
down
;
...
...
@@ -30,7 +35,7 @@ void main() {
}
return
Directionality
(
textDirection:
TextDirection
.
ltr
,
textDirection:
textDirection
,
child:
MediaQuery
(
data:
const
MediaQueryData
(
size:
Size
(
800.0
,
600.0
)),
child:
ScrollConfiguration
(
...
...
@@ -218,6 +223,92 @@ void main() {
);
});
testWidgets
(
'Stretch overscroll works in reverse - horizontal - RTL'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
box1Key
=
GlobalKey
();
final
GlobalKey
box2Key
=
GlobalKey
();
final
GlobalKey
box3Key
=
GlobalKey
();
final
ScrollController
controller
=
ScrollController
();
await
tester
.
pumpWidget
(
buildTest
(
box1Key
,
box2Key
,
box3Key
,
controller
,
axis:
Axis
.
horizontal
,
reverse:
true
,
textDirection:
TextDirection
.
rtl
,
)
);
expect
(
find
.
byType
(
StretchingOverscrollIndicator
),
findsOneWidget
);
expect
(
find
.
byType
(
GlowingOverscrollIndicator
),
findsNothing
);
final
RenderBox
box1
=
tester
.
renderObject
(
find
.
byKey
(
box1Key
));
final
RenderBox
box2
=
tester
.
renderObject
(
find
.
byKey
(
box2Key
));
final
RenderBox
box3
=
tester
.
renderObject
(
find
.
byKey
(
box3Key
));
expect
(
controller
.
offset
,
0.0
);
expect
(
box1
.
localToGlobal
(
Offset
.
zero
),
Offset
.
zero
);
expect
(
box2
.
localToGlobal
(
Offset
.
zero
),
const
Offset
(
300.0
,
0.0
));
expect
(
box3
.
localToGlobal
(
Offset
.
zero
),
const
Offset
(
600.0
,
0.0
));
await
expectLater
(
find
.
byType
(
CustomScrollView
),
matchesGoldenFile
(
'overscroll_stretch.horizontal.reverse.rtl.start.png'
),
);
TestGesture
gesture
=
await
tester
.
startGesture
(
tester
.
getCenter
(
find
.
byType
(
CustomScrollView
)));
// Overscroll the start
await
gesture
.
moveBy
(
const
Offset
(
200.0
,
0.0
));
await
tester
.
pumpAndSettle
();
expect
(
box1
.
localToGlobal
(
Offset
.
zero
),
Offset
.
zero
);
expect
(
box2
.
localToGlobal
(
Offset
.
zero
).
dx
,
greaterThan
(
305.0
));
expect
(
box3
.
localToGlobal
(
Offset
.
zero
).
dx
,
greaterThan
(
610.0
));
await
expectLater
(
find
.
byType
(
CustomScrollView
),
matchesGoldenFile
(
'overscroll_stretch.horizontal.reverse.rtl.start.stretched.png'
),
);
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
// Stretch released back to the start
expect
(
box1
.
localToGlobal
(
Offset
.
zero
),
Offset
.
zero
);
expect
(
box2
.
localToGlobal
(
Offset
.
zero
),
const
Offset
(
300.0
,
0.0
));
expect
(
box3
.
localToGlobal
(
Offset
.
zero
),
const
Offset
(
600.0
,
0.0
));
// Jump to end of the list
controller
.
jumpTo
(
controller
.
position
.
maxScrollExtent
);
await
tester
.
pumpAndSettle
();
expect
(
controller
.
offset
,
100.0
);
expect
(
box1
.
localToGlobal
(
Offset
.
zero
).
dx
,
-
100.0
);
expect
(
box2
.
localToGlobal
(
Offset
.
zero
).
dx
,
200.0
);
expect
(
box3
.
localToGlobal
(
Offset
.
zero
).
dx
,
500.0
);
await
expectLater
(
find
.
byType
(
CustomScrollView
),
matchesGoldenFile
(
'overscroll_stretch.horizontal.reverse.rtl.end.png'
),
);
gesture
=
await
tester
.
startGesture
(
tester
.
getCenter
(
find
.
byType
(
CustomScrollView
)));
// Overscroll the end
await
gesture
.
moveBy
(
const
Offset
(-
200.0
,
0.0
));
await
tester
.
pumpAndSettle
();
expect
(
box1
.
localToGlobal
(
Offset
.
zero
).
dx
,
lessThan
(-
116.0
));
expect
(
box2
.
localToGlobal
(
Offset
.
zero
).
dx
,
lessThan
(
190.0
));
expect
(
box3
.
localToGlobal
(
Offset
.
zero
).
dx
,
lessThan
(
500.0
));
await
expectLater
(
find
.
byType
(
CustomScrollView
),
matchesGoldenFile
(
'overscroll_stretch.horizontal.reverse.rtl.end.stretched.png'
),
);
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
// Stretch released back
expect
(
box1
.
localToGlobal
(
Offset
.
zero
).
dx
,
-
100.0
);
expect
(
box2
.
localToGlobal
(
Offset
.
zero
).
dx
,
200.0
);
expect
(
box3
.
localToGlobal
(
Offset
.
zero
).
dx
,
500.0
);
});
testWidgets
(
'Stretch overscroll horizontally'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
box1Key
=
GlobalKey
();
final
GlobalKey
box2Key
=
GlobalKey
();
...
...
@@ -295,6 +386,46 @@ void main() {
expect
(
box3
.
localToGlobal
(
Offset
.
zero
).
dx
,
500.0
);
});
testWidgets
(
'Stretch overscroll horizontally RTl'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
box1Key
=
GlobalKey
();
final
GlobalKey
box2Key
=
GlobalKey
();
final
GlobalKey
box3Key
=
GlobalKey
();
final
ScrollController
controller
=
ScrollController
();
await
tester
.
pumpWidget
(
buildTest
(
box1Key
,
box2Key
,
box3Key
,
controller
,
axis:
Axis
.
horizontal
,
textDirection:
TextDirection
.
rtl
,
)
);
expect
(
find
.
byType
(
StretchingOverscrollIndicator
),
findsOneWidget
);
expect
(
find
.
byType
(
GlowingOverscrollIndicator
),
findsNothing
);
final
RenderBox
box1
=
tester
.
renderObject
(
find
.
byKey
(
box1Key
));
final
RenderBox
box2
=
tester
.
renderObject
(
find
.
byKey
(
box2Key
));
final
RenderBox
box3
=
tester
.
renderObject
(
find
.
byKey
(
box3Key
));
expect
(
controller
.
offset
,
0.0
);
expect
(
box1
.
localToGlobal
(
Offset
.
zero
),
const
Offset
(
500.0
,
0.0
));
expect
(
box2
.
localToGlobal
(
Offset
.
zero
),
const
Offset
(
200.0
,
0.0
));
expect
(
box3
.
localToGlobal
(
Offset
.
zero
),
const
Offset
(-
100.0
,
0.0
));
final
TestGesture
gesture
=
await
tester
.
startGesture
(
tester
.
getCenter
(
find
.
byType
(
CustomScrollView
)));
// Overscroll
await
gesture
.
moveBy
(
const
Offset
(-
200.0
,
0.0
));
await
tester
.
pumpAndSettle
();
expect
(
box1
.
localToGlobal
(
Offset
.
zero
).
dx
,
lessThan
(
500.0
));
expect
(
box2
.
localToGlobal
(
Offset
.
zero
).
dx
,
lessThan
(
200.0
));
expect
(
box3
.
localToGlobal
(
Offset
.
zero
).
dx
,
lessThan
(-
100.0
));
await
expectLater
(
find
.
byType
(
CustomScrollView
),
matchesGoldenFile
(
'overscroll_stretch.horizontal.rtl.png'
),
);
});
testWidgets
(
'Disallow stretching overscroll'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
box1Key
=
GlobalKey
();
final
GlobalKey
box2Key
=
GlobalKey
();
...
...
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