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
ca2abf86
Unverified
Commit
ca2abf86
authored
May 20, 2020
by
LongCatIsLooong
Committed by
GitHub
May 20, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avoid forceToPoint in hit-testing when possible (#57519)
parent
b70e7a9b
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
14 deletions
+84
-14
segmented_control.dart
packages/flutter/lib/src/cupertino/segmented_control.dart
+6
-7
sliding_segmented_control.dart
.../flutter/lib/src/cupertino/sliding_segmented_control.dart
+6
-7
segmented_control_test.dart
packages/flutter/test/cupertino/segmented_control_test.dart
+40
-0
sliding_segmented_control_test.dart
...lutter/test/cupertino/sliding_segmented_control_test.dart
+32
-0
No files found.
packages/flutter/lib/src/cupertino/segmented_control.dart
View file @
ca2abf86
...
...
@@ -718,13 +718,12 @@ class _RenderSegmentedControl<T> extends RenderBox
while
(
child
!=
null
)
{
final
_SegmentedControlContainerBoxParentData
childParentData
=
child
.
parentData
as
_SegmentedControlContainerBoxParentData
;
if
(
childParentData
.
surroundingRect
.
contains
(
position
))
{
final
Offset
center
=
(
Offset
.
zero
&
child
.
size
).
center
;
return
result
.
addWithRawTransform
(
transform:
MatrixUtils
.
forceToPoint
(
center
),
position:
center
,
hitTest:
(
BoxHitTestResult
result
,
Offset
position
)
{
assert
(
position
==
center
);
return
child
.
hitTest
(
result
,
position:
center
);
return
result
.
addWithPaintOffset
(
offset:
childParentData
.
offset
,
position:
position
,
hitTest:
(
BoxHitTestResult
result
,
Offset
localOffset
)
{
assert
(
localOffset
==
position
-
childParentData
.
offset
);
return
child
.
hitTest
(
result
,
position:
localOffset
);
},
);
}
...
...
packages/flutter/lib/src/cupertino/sliding_segmented_control.dart
View file @
ca2abf86
...
...
@@ -1025,13 +1025,12 @@ class _RenderSegmentedControl<T> extends RenderBox
final
_SegmentedControlContainerBoxParentData
childParentData
=
child
.
parentData
as
_SegmentedControlContainerBoxParentData
;
if
((
childParentData
.
offset
&
child
.
size
).
contains
(
position
))
{
final
Offset
center
=
(
Offset
.
zero
&
child
.
size
).
center
;
return
result
.
addWithRawTransform
(
transform:
MatrixUtils
.
forceToPoint
(
center
),
position:
center
,
hitTest:
(
BoxHitTestResult
result
,
Offset
position
)
{
assert
(
position
==
center
);
return
child
.
hitTest
(
result
,
position:
center
);
return
result
.
addWithPaintOffset
(
offset:
childParentData
.
offset
,
position:
position
,
hitTest:
(
BoxHitTestResult
result
,
Offset
localOffset
)
{
assert
(
localOffset
==
position
-
childParentData
.
offset
);
return
child
.
hitTest
(
result
,
position:
localOffset
);
},
);
}
...
...
packages/flutter/test/cupertino/segmented_control_test.dart
View file @
ca2abf86
...
...
@@ -926,6 +926,46 @@ void main() {
expect
(
sharedValue
,
0
);
});
testWidgets
(
'Hit-tests report accurate local position in segments'
,
(
WidgetTester
tester
)
async
{
final
Map
<
int
,
Widget
>
children
=
<
int
,
Widget
>{};
TapDownDetails
tapDownDetails
;
children
[
0
]
=
GestureDetector
(
behavior:
HitTestBehavior
.
opaque
,
onTapDown:
(
TapDownDetails
details
)
{
tapDownDetails
=
details
;
},
child:
const
SizedBox
(
width:
200
,
height:
200
),
);
children
[
1
]
=
const
Text
(
'Child 2'
);
int
sharedValue
=
1
;
await
tester
.
pumpWidget
(
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setState
)
{
return
boilerplate
(
child:
CupertinoSegmentedControl
<
int
>(
key:
const
ValueKey
<
String
>(
'Segmented Control'
),
children:
children
,
onValueChanged:
(
int
newValue
)
{
setState
(()
{
sharedValue
=
newValue
;
});
},
groupValue:
sharedValue
,
),
);
},
),
);
expect
(
sharedValue
,
1
);
final
Offset
segment0GlobalOffset
=
tester
.
getTopLeft
(
find
.
byWidget
(
children
[
0
]));
await
tester
.
tapAt
(
segment0GlobalOffset
+
const
Offset
(
7
,
11
));
expect
(
tapDownDetails
.
localPosition
,
const
Offset
(
7
,
11
));
expect
(
tapDownDetails
.
globalPosition
,
segment0GlobalOffset
+
const
Offset
(
7
,
11
));
});
testWidgets
(
'Segment still hittable with a child that has no hitbox'
,
(
WidgetTester
tester
)
async
{
...
...
packages/flutter/test/cupertino/sliding_segmented_control_test.dart
View file @
ca2abf86
...
...
@@ -783,6 +783,38 @@ void main() {
expect
(
groupValue
,
1
);
});
testWidgets
(
'Hit-tests report accurate local position in segments'
,
(
WidgetTester
tester
)
async
{
final
Map
<
int
,
Widget
>
children
=
<
int
,
Widget
>{};
TapDownDetails
tapDownDetails
;
children
[
0
]
=
GestureDetector
(
behavior:
HitTestBehavior
.
opaque
,
onTapDown:
(
TapDownDetails
details
)
{
tapDownDetails
=
details
;
},
child:
const
SizedBox
(
width:
200
,
height:
200
),
);
children
[
1
]
=
const
Text
(
'Child 2'
);
await
tester
.
pumpWidget
(
boilerplate
(
builder:
(
BuildContext
context
)
{
return
CupertinoSlidingSegmentedControl
<
int
>(
key:
const
ValueKey
<
String
>(
'Segmented Control'
),
children:
children
,
groupValue:
groupValue
,
onValueChanged:
defaultCallback
,
);
},
),
);
expect
(
groupValue
,
0
);
final
Offset
segment0GlobalOffset
=
tester
.
getTopLeft
(
find
.
byWidget
(
children
[
0
]));
await
tester
.
tapAt
(
segment0GlobalOffset
+
const
Offset
(
7
,
11
));
expect
(
tapDownDetails
.
localPosition
,
const
Offset
(
7
,
11
));
expect
(
tapDownDetails
.
globalPosition
,
segment0GlobalOffset
+
const
Offset
(
7
,
11
));
});
testWidgets
(
'Thumb animation is correct when the selected segment changes'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
setupSimpleSegmentedControl
());
...
...
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