@@ -14,7 +14,7 @@ namespace Avalonia.Base.UnitTests.Layout
14
14
public class LayoutableTests_EffectiveViewportChanged
15
15
{
16
16
[ Fact ]
17
- public async Task EffectiveViewportChanged_Not_Raised_When_Control_Added_To_Tree ( )
17
+ public async Task EffectiveViewportChanged_Not_Raised_When_Control_Added_To_Tree_And_Layout_Pass_Has_Not_Run ( )
18
18
{
19
19
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
20
20
await RunOnUIThread . Execute ( async ( ) =>
@@ -34,6 +34,60 @@ await RunOnUIThread.Execute(async () =>
34
34
Assert . Equal ( 0 , raised ) ;
35
35
} ) ;
36
36
}
37
+
38
+ [ Fact ]
39
+ public async Task EffectiveViewportChanged_Raised_When_Control_Added_To_Tree_And_Layout_Pass_Has_Run ( )
40
+ {
41
+ #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
42
+ await RunOnUIThread . Execute ( async ( ) =>
43
+ #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
44
+ {
45
+ var root = CreateRoot ( ) ;
46
+ var target = new Canvas ( ) ;
47
+ var raised = 0 ;
48
+
49
+ target . EffectiveViewportChanged += ( s , e ) =>
50
+ {
51
+ ++ raised ;
52
+ } ;
53
+
54
+ root . Child = target ;
55
+
56
+ Assert . Equal ( 0 , raised ) ;
57
+
58
+ await ExecuteInitialLayoutPass ( root ) ;
59
+
60
+ Assert . Equal ( 1 , raised ) ;
61
+ } ) ;
62
+ }
63
+
64
+ [ Fact ]
65
+ public async Task EffectiveViewportChanged_Raised_When_Root_LayedOut_And_Then_Control_Added_To_Tree_And_Layout_Pass_Runs ( )
66
+ {
67
+ #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
68
+ await RunOnUIThread . Execute ( async ( ) =>
69
+ #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
70
+ {
71
+ var root = CreateRoot ( ) ;
72
+ var target = new Canvas ( ) ;
73
+ var raised = 0 ;
74
+
75
+ target . EffectiveViewportChanged += ( s , e ) =>
76
+ {
77
+ ++ raised ;
78
+ } ;
79
+
80
+ await ExecuteInitialLayoutPass ( root ) ;
81
+
82
+ root . Child = target ;
83
+
84
+ Assert . Equal ( 0 , raised ) ;
85
+
86
+ await ExecuteInitialLayoutPass ( root ) ;
87
+
88
+ Assert . Equal ( 1 , raised ) ;
89
+ } ) ;
90
+ }
37
91
38
92
[ Fact ]
39
93
public async Task EffectiveViewportChanged_Raised_Before_LayoutUpdated ( )
@@ -268,8 +322,11 @@ await RunOnUIThread.Execute(async () =>
268
322
269
323
root . Child = parent ;
270
324
271
- await ExecuteInitialLayoutPass ( root ) ;
272
325
target . EffectiveViewportChanged += ( s , e ) => ++ raised ;
326
+ await ExecuteInitialLayoutPass ( root ) ;
327
+
328
+ raised = 0 ; // The initial layout pass is expected to raise.
329
+
273
330
target . RenderTransform = new TranslateTransform { X = 8 } ;
274
331
target . InvalidateMeasure ( ) ;
275
332
await ExecuteLayoutPass ( root ) ;
0 commit comments