|
1 | 1 | import 'package:checks/checks.dart';
|
2 |
| -// ignore: undefined_hidden_name // anticipates https://github.com/flutter/flutter/pull/164818 |
3 |
| -import 'package:flutter/rendering.dart' hide SliverPaintOrder; |
4 |
| -// ignore: undefined_hidden_name // anticipates https://github.com/flutter/flutter/pull/164818 |
5 |
| -import 'package:flutter/widgets.dart' hide SliverPaintOrder; |
| 2 | +import 'package:flutter/widgets.dart'; |
6 | 3 | import 'package:flutter_test/flutter_test.dart';
|
7 | 4 | import 'package:zulip/widgets/scrolling.dart';
|
8 | 5 |
|
9 | 6 | import '../flutter_checks.dart';
|
10 | 7 |
|
11 | 8 | void main() {
|
12 |
| - group('CustomPaintOrderScrollView paint order', () { |
13 |
| - final paintLog = <int>[]; |
14 |
| - |
15 |
| - Widget makeSliver(int i) { |
16 |
| - return SliverToBoxAdapter( |
17 |
| - key: ValueKey(i), |
18 |
| - child: CustomPaint( |
19 |
| - painter: TestCustomPainter() |
20 |
| - ..onPaint = (_, _) => paintLog.add(i), |
21 |
| - child: Text('Item $i'))); |
22 |
| - } |
23 |
| - |
24 |
| - testWidgets('firstIsTop', (tester) async { |
25 |
| - addTearDown(paintLog.clear); |
26 |
| - await tester.pumpWidget(Directionality(textDirection: TextDirection.ltr, |
27 |
| - child: CustomPaintOrderScrollView( |
28 |
| - paintOrder: SliverPaintOrder.firstIsTop, |
29 |
| - center: ValueKey(2), anchor: 0.5, |
30 |
| - slivers: List.generate(5, makeSliver)))); |
31 |
| - |
32 |
| - // First sliver paints last, over other slivers; last sliver paints first. |
33 |
| - check(paintLog).deepEquals([4, 3, 2, 1, 0]); |
34 |
| - }); |
35 |
| - |
36 |
| - testWidgets('lastIsTop', (tester) async { |
37 |
| - addTearDown(paintLog.clear); |
38 |
| - await tester.pumpWidget(Directionality(textDirection: TextDirection.ltr, |
39 |
| - child: CustomPaintOrderScrollView( |
40 |
| - paintOrder: SliverPaintOrder.lastIsTop, |
41 |
| - center: ValueKey(2), anchor: 0.5, |
42 |
| - slivers: List.generate(5, makeSliver)))); |
43 |
| - |
44 |
| - // Last sliver paints last, over other slivers; first sliver paints first. |
45 |
| - check(paintLog).deepEquals([0, 1, 2, 3, 4]); |
46 |
| - }); |
47 |
| - |
48 |
| - testWidgets('centerTopFirstBottom', (tester) async { |
49 |
| - addTearDown(paintLog.clear); |
50 |
| - await tester.pumpWidget(Directionality(textDirection: TextDirection.ltr, |
51 |
| - child: CustomPaintOrderScrollView( |
52 |
| - paintOrder: SliverPaintOrder.centerTopFirstBottom, |
53 |
| - center: ValueKey(2), anchor: 0.5, |
54 |
| - slivers: List.generate(5, makeSliver)))); |
55 |
| - |
56 |
| - // The particular order CustomScrollView paints in. |
57 |
| - check(paintLog).deepEquals([0, 1, 4, 3, 2]); |
58 |
| - |
59 |
| - // Check that CustomScrollView indeed paints in the same order. |
60 |
| - final result = paintLog.toList(); |
61 |
| - paintLog.clear(); |
62 |
| - await tester.pumpWidget(Directionality(textDirection: TextDirection.ltr, |
63 |
| - child: CustomScrollView( |
64 |
| - center: ValueKey(2), anchor: 0.5, |
65 |
| - slivers: List.generate(5, makeSliver)))); |
66 |
| - check(paintLog).deepEquals(result); |
67 |
| - }, skip: true, // TODO(upstream): once PR 164818 lands, cut our CustomPaintOrderScrollView |
68 |
| - // in favor of CustomScrollView; this test was checking that |
69 |
| - // the former matched the latter's old default behavior. |
70 |
| - ); |
71 |
| - }); |
72 |
| - |
73 |
| - group('CustomPaintOrderScrollView hit-test order', () { |
74 |
| - Widget makeSliver(int i) { |
75 |
| - return _AllOverlapSliver(key: ValueKey<int>(i), id: i); |
76 |
| - } |
77 |
| - |
78 |
| - List<int> sliverIds(Iterable<HitTestEntry> path) => [ |
79 |
| - for (final e in path) |
80 |
| - if (e.target case _RenderAllOverlapSliver(:final id)) |
81 |
| - id, |
82 |
| - ]; |
83 |
| - |
84 |
| - testWidgets('firstIsTop', (WidgetTester tester) async { |
85 |
| - await tester.pumpWidget(Directionality(textDirection: TextDirection.ltr, |
86 |
| - child: CustomPaintOrderScrollView( |
87 |
| - paintOrder: SliverPaintOrder.firstIsTop, |
88 |
| - center: const ValueKey(2), anchor: 0.5, |
89 |
| - slivers: List.generate(5, makeSliver)))); |
90 |
| - |
91 |
| - final result = tester.hitTestOnBinding(const Offset(400, 300)); |
92 |
| - check(sliverIds(result.path)).deepEquals([0, 1, 2, 3, 4]); |
93 |
| - }); |
94 |
| - |
95 |
| - testWidgets('lastIsTop', (WidgetTester tester) async { |
96 |
| - await tester.pumpWidget(Directionality(textDirection: TextDirection.ltr, |
97 |
| - child: CustomPaintOrderScrollView( |
98 |
| - paintOrder: SliverPaintOrder.lastIsTop, |
99 |
| - center: const ValueKey(2), anchor: 0.5, |
100 |
| - slivers: List.generate(5, makeSliver)))); |
101 |
| - |
102 |
| - final result = tester.hitTestOnBinding(const Offset(400, 300)); |
103 |
| - check(sliverIds(result.path)).deepEquals([4, 3, 2, 1, 0]); |
104 |
| - }); |
105 |
| - |
106 |
| - testWidgets('centerTopFirstBottom', (tester) async { |
107 |
| - await tester.pumpWidget(Directionality(textDirection: TextDirection.ltr, |
108 |
| - child: CustomPaintOrderScrollView( |
109 |
| - paintOrder: SliverPaintOrder.centerTopFirstBottom, |
110 |
| - center: const ValueKey(2), anchor: 0.5, |
111 |
| - slivers: List.generate(5, makeSliver)))); |
112 |
| - |
113 |
| - final result = tester.hitTestOnBinding(const Offset(400, 300)); |
114 |
| - // The particular order CustomScrollView hit-tests in. |
115 |
| - check(sliverIds(result.path)).deepEquals([2, 3, 4, 1, 0]); |
116 |
| - |
117 |
| - // Check that CustomScrollView indeed hit-tests in the same order. |
118 |
| - await tester.pumpWidget(Directionality(textDirection: TextDirection.ltr, |
119 |
| - child: CustomScrollView( |
120 |
| - center: const ValueKey(2), anchor: 0.5, |
121 |
| - slivers: List.generate(5, makeSliver)))); |
122 |
| - check(sliverIds(tester.hitTestOnBinding(const Offset(400, 300)).path)) |
123 |
| - .deepEquals(sliverIds(result.path)); |
124 |
| - }, skip: true, // TODO(upstream): once PR 164818 lands, cut our CustomPaintOrderScrollView |
125 |
| - // in favor of CustomScrollView; this test was checking that |
126 |
| - // the former matched the latter's old default behavior. |
127 |
| - ); |
128 |
| - }); |
129 |
| - |
130 | 9 | group('MessageListScrollView', () {
|
131 | 10 | Widget buildList({
|
132 | 11 | MessageListScrollController? controller,
|
@@ -309,64 +188,3 @@ void main() {
|
309 | 188 | });
|
310 | 189 | });
|
311 | 190 | }
|
312 |
| - |
313 |
| -class TestCustomPainter extends CustomPainter { |
314 |
| - void Function(Canvas canvas, Size size)? onPaint; |
315 |
| - |
316 |
| - @override |
317 |
| - void paint(Canvas canvas, Size size) { |
318 |
| - if (onPaint != null) onPaint!(canvas, size); |
319 |
| - } |
320 |
| - |
321 |
| - @override |
322 |
| - bool shouldRepaint(covariant CustomPainter oldDelegate) { |
323 |
| - return true; |
324 |
| - } |
325 |
| -} |
326 |
| - |
327 |
| -/// A sliver that overlaps with other slivers as far as possible, |
328 |
| -/// and does nothing else. |
329 |
| -class _AllOverlapSliver extends LeafRenderObjectWidget { |
330 |
| - const _AllOverlapSliver({super.key, required this.id}); |
331 |
| - |
332 |
| - final int id; |
333 |
| - |
334 |
| - @override |
335 |
| - RenderObject createRenderObject(BuildContext context) => _RenderAllOverlapSliver(id); |
336 |
| -} |
337 |
| - |
338 |
| -class _RenderAllOverlapSliver extends RenderSliver { |
339 |
| - _RenderAllOverlapSliver(this.id); |
340 |
| - |
341 |
| - final int id; |
342 |
| - |
343 |
| - @override |
344 |
| - void performLayout() { |
345 |
| - geometry = SliverGeometry( |
346 |
| - paintExtent: constraints.remainingPaintExtent, |
347 |
| - maxPaintExtent: constraints.remainingPaintExtent, |
348 |
| - layoutExtent: 0.0, |
349 |
| - ); |
350 |
| - } |
351 |
| - |
352 |
| - @override |
353 |
| - bool hitTest( |
354 |
| - SliverHitTestResult result, { |
355 |
| - required double mainAxisPosition, |
356 |
| - required double crossAxisPosition, |
357 |
| - }) { |
358 |
| - if (mainAxisPosition >= 0.0 && |
359 |
| - mainAxisPosition < geometry!.hitTestExtent && |
360 |
| - crossAxisPosition >= 0.0 && |
361 |
| - crossAxisPosition < constraints.crossAxisExtent) { |
362 |
| - result.add( |
363 |
| - SliverHitTestEntry( |
364 |
| - this, |
365 |
| - mainAxisPosition: mainAxisPosition, |
366 |
| - crossAxisPosition: crossAxisPosition, |
367 |
| - ), |
368 |
| - ); |
369 |
| - } |
370 |
| - return false; |
371 |
| - } |
372 |
| -} |
0 commit comments