Skip to content

Commit

Permalink
Merge pull request #3728 from unoplatform/dev/dr/SkiaLoad
Browse files Browse the repository at this point in the history
fix: View not removed and Unloaded event not raised
  • Loading branch information
dr1rrb authored Sep 17, 2020
2 parents 5a09ff7 + 2d10b14 commit 4511160
Show file tree
Hide file tree
Showing 21 changed files with 579 additions and 609 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ namespace SampleControl.Presentation

public partial class SampleChooserViewModel
{
#if DEBUG
private const int _numberOfRecentSamplesVisible = 10;
#else
private const int _numberOfRecentSamplesVisible = 0;
#endif
private List<SampleChooserCategory> _categories;

private readonly Uno.Threading.AsyncLock _fileLock = new Uno.Threading.AsyncLock();
Expand Down Expand Up @@ -543,7 +547,11 @@ private static Assembly[] GetAllAssembies()
private List<SampleChooserCategory> GetSamples()
{
var categories =
#if !__WASM__
from assembly in GetAllAssembies().AsParallel()
#else
from assembly in GetAllAssembies()
#endif
from type in FindDefinedAssemblies(assembly)
let sampleAttribute = FindSampleAttribute(type)
where sampleAttribute != null
Expand All @@ -553,7 +561,7 @@ group content by category into contentByCategory
orderby contentByCategory.Key.ToLower(CultureInfo.CurrentUICulture)
select new SampleChooserCategory(contentByCategory);

return categories.AsParallel().ToList();
return categories.ToList();

SampleChooserContent GetContent(TypeInfo type, SampleAttribute attribute)
=> new SampleChooserContent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,117 @@ public async Task When_Negative_Margin_Zero_Size()

Assert.AreEqual(0d, Math.Round(SUT.DesiredSize.Height));
}

[TestMethod]
[RunsOnUIThread]
public async Task When_Add_Element_Then_Load_Raised()
{
var sut = new Border();
var hostPanel = new Grid();

TestServices.WindowHelper.WindowContent = hostPanel;
await TestServices.WindowHelper.WaitForIdle();

int loadingCount = 0, loadedCount = 0;
sut.Loading += (snd, e) => loadingCount++;
sut.Loaded += (snd, e) => loadedCount++;

hostPanel.Children.Add(sut);

Assert.AreEqual(1, loadingCount, "loading");
Assert.AreEqual(1, loadedCount, "loaded");
}

[TestMethod]
[RunsOnUIThread]
public async Task When_Add_Element_Then_Unload_Raised()
{
var sut = new Border();
var hostPanel = new Grid {Children = {sut}};

TestServices.WindowHelper.WindowContent = hostPanel;
await TestServices.WindowHelper.WaitForIdle();

var unloadCount = 0;
sut.Unloaded += (snd, e) => unloadCount++;

hostPanel.Children.Remove(sut);

Assert.AreEqual(1, unloadCount);
#if NETSTANDARD2_0
Assert.IsFalse(hostPanel._children.Contains(sut));
#endif
}

#if NETSTANDARD2_0
// Those tests only validate the current behavior which should be reviewed by https://github.com/unoplatform/uno/issues/2895
// (cf. notes in the tests)

[TestMethod]
[RunsOnUIThread]
public async Task When_Add_Element_While_Parent_Loading_Then_Load_Raised()
{
var sut = new Border();
var hostPanel = new Grid();

int loadingCount = 0, loadedCount = 0;
var success = false;
sut.Loading += (snd, e) => loadingCount++;
sut.Loaded += (snd, e) => loadedCount++;

hostPanel.Loading += (snd, e) =>
{
hostPanel.Children.Add(sut);
// Note: This is NOT the case on UWP. Loading and Loaded event are raised on the child (aka. 'sut'')
// only after the completion of the current handler.
Assert.AreEqual(1, loadingCount, "loading");
Assert.AreEqual(0, loadedCount, "loaded");
success = true;
};

TestServices.WindowHelper.WindowContent = hostPanel;
await TestServices.WindowHelper.WaitForIdle();

Assert.IsTrue(success);
Assert.AreEqual(1, loadingCount, "loading");
Assert.AreEqual(1, loadedCount, "loaded");
}

[TestMethod]
[RunsOnUIThread]
public async Task When_Add_Element_While_Parent_Loaded_Then_Load_Raised()
{
var sut = new Border();
var hostPanel = new Grid();

int loadingCount = 0, loadedCount = 0;
var success = false;
sut.Loading += (snd, e) => loadingCount++;
sut.Loaded += (snd, e) => loadedCount++;

hostPanel.Loaded += (snd, e) =>
{
hostPanel.Children.Add(sut);
// Note: This is NOT the case on UWP. Loading and Loaded event are raised on the child (aka. 'sut'')
// only after the completion of the current handler.
// Note 2: On UWP, when adding a child to the parent while in the parent's loading event handler (i.e. this case)
// the child will receive the Loaded ** BEFORE ** the Loading event.
Assert.AreEqual(1, loadingCount, "loading");
Assert.AreEqual(1, loadedCount, "loaded");
success = true;
};

TestServices.WindowHelper.WindowContent = hostPanel;
await TestServices.WindowHelper.WaitForIdle();

Assert.IsTrue(success);
Assert.AreEqual(1, loadingCount, "loading");
Assert.AreEqual(1, loadedCount, "loaded");
}
#endif
}

public partial class MyControl01 : FrameworkElement
Expand Down
16 changes: 8 additions & 8 deletions src/Uno.UI/UI/Xaml/Controls/Panel/Panel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private void UpdateTransitions(IFrameworkElement element)

public UIElementCollection Children => _children;

#region ChildrenTransitions Dependency Property
#region ChildrenTransitions Dependency Property

public TransitionCollection ChildrenTransitions
{
Expand Down Expand Up @@ -143,7 +143,7 @@ public Thickness Padding

#endregion

#region BorderThickness DependencyProperty
#region BorderThickness DependencyProperty

public Thickness BorderThickness
{
Expand All @@ -163,9 +163,9 @@ public Thickness BorderThickness
)
);

#endregion
#endregion

#region BorderBrush Dependency Property
#region BorderBrush Dependency Property

#if XAMARIN_ANDROID
private Brush _borderBrushStrongReference;
Expand Down Expand Up @@ -195,9 +195,9 @@ public Brush BorderBrush
propertyChangedCallback: (s, e) => ((Panel)s).OnBorderBrushChanged((Brush)e.OldValue, (Brush)e.NewValue)
)
);
#endregion
#endregion

#region CornerRadius DependencyProperty
#region CornerRadius DependencyProperty

public CornerRadius CornerRadius
{
Expand All @@ -217,9 +217,9 @@ public CornerRadius CornerRadius
)
);

#endregion
#endregion

#region IsItemsHost DependencyProperty
#region IsItemsHost DependencyProperty
public static DependencyProperty IsItemsHostProperty { get ; } = DependencyProperty.Register(
"IsItemsHost", typeof(bool), typeof(Panel), new FrameworkPropertyMetadata(default(bool)));

Expand Down
Loading

0 comments on commit 4511160

Please sign in to comment.