Improve hit testing
Now a RenderBox is considered hit if one of its children are hit or it itself decides that it's hit. In particular, empty space inside a flex won't be hit because none of the children are located there and a RenderFlex doesn't consider itself hittable. Fixes #53 Fixes #1221
This commit is contained in:
@@ -5,8 +5,14 @@ import 'rendering_tester.dart';
|
||||
|
||||
void main() {
|
||||
test('Should be able to hit with negative scroll offset', () {
|
||||
RenderBox green = new RenderDecoratedBox(
|
||||
decoration: new BoxDecoration(
|
||||
backgroundColor: const Color(0xFF00FF00)
|
||||
));
|
||||
|
||||
RenderBox size = new RenderConstrainedBox(
|
||||
additionalConstraints: new BoxConstraints.tight(const Size(100.0, 100.0)));
|
||||
additionalConstraints: new BoxConstraints.tight(const Size(100.0, 100.0)),
|
||||
child: green);
|
||||
|
||||
RenderBox red = new RenderDecoratedBox(
|
||||
decoration: new BoxDecoration(
|
||||
@@ -21,10 +27,10 @@ void main() {
|
||||
|
||||
result = new HitTestResult();
|
||||
renderView.hitTest(result, position: new Point(15.0, 0.0));
|
||||
expect(result.path.first.target, equals(viewport));
|
||||
expect(result.path.first.target.runtimeType, equals(TestRenderView));
|
||||
|
||||
result = new HitTestResult();
|
||||
renderView.hitTest(result, position: new Point(15.0, 15.0));
|
||||
expect(result.path.first.target, equals(size));
|
||||
expect(result.path.first.target, equals(green));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -23,7 +23,11 @@ void main() {
|
||||
onVerticalDragEnd: (Offset velocity) {
|
||||
didEndDrag = true;
|
||||
},
|
||||
child: new Container()
|
||||
child: new Container(
|
||||
decoration: const BoxDecoration(
|
||||
backgroundColor: const Color(0xFF00FF00)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
tester.pumpWidget(widget);
|
||||
@@ -70,7 +74,11 @@ void main() {
|
||||
onVerticalDragEnd: (Offset velocity) { gestureCount += 1; },
|
||||
onHorizontalDragUpdate: (_) { fail("gesture should not match"); },
|
||||
onHorizontalDragEnd: (Offset velocity) { fail("gesture should not match"); },
|
||||
child: new Container()
|
||||
child: new Container(
|
||||
decoration: const BoxDecoration(
|
||||
backgroundColor: const Color(0xFF00FF00)
|
||||
)
|
||||
)
|
||||
);
|
||||
tester.pumpWidget(widget);
|
||||
|
||||
@@ -106,7 +114,11 @@ void main() {
|
||||
onPanEnd: (_) {
|
||||
didEndPan = true;
|
||||
},
|
||||
child: new Container()
|
||||
child: new Container(
|
||||
decoration: const BoxDecoration(
|
||||
backgroundColor: const Color(0xFF00FF00)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -21,9 +21,14 @@ void main() {
|
||||
content: new Text(helloSnackBar)
|
||||
);
|
||||
},
|
||||
child: new Center(
|
||||
key: tapTarget,
|
||||
child: new Placeholder(key: placeholderKey)
|
||||
child: new Container(
|
||||
decoration: const BoxDecoration(
|
||||
backgroundColor: const Color(0xFF00FF00)
|
||||
),
|
||||
child: new Center(
|
||||
key: tapTarget,
|
||||
child: new Placeholder(key: placeholderKey)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,11 @@ void main() {
|
||||
onTap: () {
|
||||
didReceiveTap = true;
|
||||
},
|
||||
child: new Container()
|
||||
child: new Container(
|
||||
decoration: new BoxDecoration(
|
||||
backgroundColor: new Color(0xFF00FFFF)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -78,7 +82,11 @@ void main() {
|
||||
onTap: () {
|
||||
didReceiveTap = true;
|
||||
},
|
||||
child: new Container()
|
||||
child: new Container(
|
||||
decoration: new BoxDecoration(
|
||||
backgroundColor: new Color(0xFF00FFFF)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -124,7 +132,11 @@ void main() {
|
||||
onTap: () {
|
||||
didReceiveTap = true;
|
||||
},
|
||||
child: new Container()
|
||||
child: new Container(
|
||||
decoration: new BoxDecoration(
|
||||
backgroundColor: new Color(0xFF00FFFF)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user