Skip to content

Commit 578bdc7

Browse files
committed
Merge branch 'release/11.2' into release/11.2.2
2 parents 43753b8 + 35f6d73 commit 578bdc7

File tree

3 files changed

+65
-14
lines changed

3 files changed

+65
-14
lines changed

native/Avalonia.Native/src/OSX/StorageProvider.mm

+3-6
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ virtual void SelectFolderDialog (IAvnWindow* parentWindowHandle,
173173
if(initialDirectory != nullptr)
174174
{
175175
auto directoryString = [NSString stringWithUTF8String:initialDirectory];
176-
panel.directoryURL = [NSURL fileURLWithPath:directoryString
177-
isDirectory:true];
176+
panel.directoryURL = [NSURL URLWithString:directoryString];
178177
}
179178

180179
auto handler = ^(NSModalResponse result) {
@@ -239,8 +238,7 @@ virtual void OpenFileDialog (IAvnWindow* parentWindowHandle,
239238
if(initialDirectory != nullptr)
240239
{
241240
auto directoryString = [NSString stringWithUTF8String:initialDirectory];
242-
panel.directoryURL = [NSURL fileURLWithPath:directoryString
243-
isDirectory:true];
241+
panel.directoryURL = [NSURL URLWithString:directoryString];
244242
}
245243

246244
if(initialFile != nullptr)
@@ -309,8 +307,7 @@ virtual void SaveFileDialog (IAvnWindow* parentWindowHandle,
309307
if(initialDirectory != nullptr)
310308
{
311309
auto directoryString = [NSString stringWithUTF8String:initialDirectory];
312-
panel.directoryURL = [NSURL fileURLWithPath:directoryString
313-
isDirectory:true];
310+
panel.directoryURL = [NSURL URLWithString:directoryString];
314311
}
315312

316313
if(initialFile != nullptr)

src/Avalonia.Base/Layout/LayoutManager.cs

+3-6
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,7 @@ public void Dispose()
213213
void ILayoutManager.RegisterEffectiveViewportListener(Layoutable control)
214214
{
215215
_effectiveViewportChangedListeners ??= new List<EffectiveViewportChangedListener>();
216-
_effectiveViewportChangedListeners.Add(new EffectiveViewportChangedListener(
217-
control,
218-
CalculateEffectiveViewport(control)));
216+
_effectiveViewportChangedListeners.Add(new EffectiveViewportChangedListener(control));
219217
}
220218

221219
void ILayoutManager.UnregisterEffectiveViewportListener(Layoutable control)
@@ -438,14 +436,13 @@ private void CalculateEffectiveViewport(Visual target, Visual control, ref Rect
438436

439437
private class EffectiveViewportChangedListener
440438
{
441-
public EffectiveViewportChangedListener(Layoutable listener, Rect viewport)
439+
public EffectiveViewportChangedListener(Layoutable listener)
442440
{
443441
Listener = listener;
444-
Viewport = viewport;
445442
}
446443

447444
public Layoutable Listener { get; }
448-
public Rect Viewport { get; set; }
445+
public Rect? Viewport { get; set; }
449446
}
450447

451448
private enum ArrangeResult

tests/Avalonia.Base.UnitTests/Layout/LayoutableTests_EffectiveViewportChanged.cs

+59-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Avalonia.Base.UnitTests.Layout
1414
public class LayoutableTests_EffectiveViewportChanged
1515
{
1616
[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()
1818
{
1919
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
2020
await RunOnUIThread.Execute(async () =>
@@ -34,6 +34,60 @@ await RunOnUIThread.Execute(async () =>
3434
Assert.Equal(0, raised);
3535
});
3636
}
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+
}
3791

3892
[Fact]
3993
public async Task EffectiveViewportChanged_Raised_Before_LayoutUpdated()
@@ -268,8 +322,11 @@ await RunOnUIThread.Execute(async () =>
268322

269323
root.Child = parent;
270324

271-
await ExecuteInitialLayoutPass(root);
272325
target.EffectiveViewportChanged += (s, e) => ++raised;
326+
await ExecuteInitialLayoutPass(root);
327+
328+
raised = 0; // The initial layout pass is expected to raise.
329+
273330
target.RenderTransform = new TranslateTransform { X = 8 };
274331
target.InvalidateMeasure();
275332
await ExecuteLayoutPass(root);

0 commit comments

Comments
 (0)