Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions samples/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
<ItemGroup>
<PackageVersion Include="Uno.Core.Extensions.Compatibility" Version="4.0.1" />
<PackageVersion Include="Xamarin.TestCloud.Agent" Version="0.23.2" />
<PackageVersion Include="Uno.WinUI.DevServer" Version="6.2.58" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@

<ItemGroup>
<PackageReference Include="Uno.Core.Extensions.Compatibility" />
<PackageReference Include="Uno.WinUI.DevServer" />
</ItemGroup>

<ItemGroup Condition="('$(Configuration)'=='Debug' or '$(IsUiAutomationMappingEnabled)'=='True') and $(IsIOS) and !$(RuntimeIdentifier.Contains('arm64'))">
Expand Down
5 changes: 3 additions & 2 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@
<PackageVersion Include="Uno.UITest.Helpers" Version="1.1.0-dev.82" />
<PackageVersion Include="Uno.UITest.Selenium" Version="1.1.0-dev.82" />
<PackageVersion Include="Uno.UITest.Xamarin" Version="1.1.0-dev.82" />
<PackageVersion Include="Xamarin.AndroidX.Core.SplashScreen" Version="1.0.1.6" />
<PackageVersion Include="Uno.WinUI.DevServer" Version="6.2.58" />
<PackageVersion Include="Xamarin.AndroidX.Core.SplashScreen" Version="1.0.1.6" />
<PackageVersion Include="Xamarin.UITest" Version="4.4.0" />
<PackageVersion Include="MSTest.TestFramework" Version="2.1.2" />
<PackageVersion Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0" />
</ItemGroup>
</Project>
</Project>
65 changes: 65 additions & 0 deletions src/Uno.Toolkit.RuntimeTests/Tests/HotReload/LoadingViewHRTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using FluentAssertions;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Threading;
using System.Threading.Tasks;
using Uno.Toolkit.RuntimeTests.Tests.TestPages;
using Uno.Toolkit.UI;
using Uno.UI.RuntimeTests;
using Windows.Foundation;

namespace Uno.Toolkit.RuntimeTests.Tests.HotReload
{
// Keep ignored in CI; run locally in Debug without a debugger attached.
// Temporarily disabled: Sample app auto-exits and test fails.
//Tracking with https://github.com/unoplatform/uno.toolkit.ui/issues/1480
[Ignore]
[TestClass]
[RunsInSecondaryApp(ignoreIfNotSupported: true)]
public class LoadingViewHrTest
{
[TestMethod]
public async Task HR_keeps_Loaded_state_by_preserving_Source(CancellationToken ct)
{
await UIHelper.Load(new LoadingViewPage(), ct);

var lv = UIHelper.GetChild<LoadingView>(name: "LV");
var marker = UIHelper.GetChild<TextBlock>(name: "Marker");

lv.Source = new TestLoadable(isExecuting: false);

lv.Content = new Border();

Assert.IsNotNull(lv.Source);
Assert.IsFalse(lv.Source!.IsExecuting);
Assert.AreEqual("Original marker", marker.Text);

await using (await HotReloadHelper.UpdateSourceFile<LoadingViewPage>(originalText: "Original marker", replacementText: "Updated marker", ct))
{
await TestHelper.WaitFor(() =>
UIHelper.GetChild<TextBlock>(name: "Marker").Text == "Updated marker", ct);
}

var lvAfter = UIHelper.GetChild<LoadingView>(name: "LV");

Assert.IsNotNull(lvAfter.Source);
Assert.IsFalse(lvAfter.Source.IsExecuting);

Assert.IsNotNull(lvAfter.Content);
}
}

internal sealed class TestLoadable(bool isExecuting = false) : ILoadable
{
public event EventHandler? IsExecutingChanged;

bool _isExecuting = isExecuting;
public bool IsExecuting
{
get => _isExecuting;
set { if (_isExecuting != value) { _isExecuting = value; IsExecutingChanged?.Invoke(this, EventArgs.Empty); } }
}
}
}
24 changes: 24 additions & 0 deletions src/Uno.Toolkit.RuntimeTests/Tests/TestPages/LoadingViewPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Page
x:Class="Uno.Toolkit.RuntimeTests.Tests.TestPages.LoadingViewPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Uno.Toolkit.RuntimeTests.Tests.TestPages"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:utu="using:Uno.Toolkit.UI"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
Tag="Page Tag"
mc:Ignorable="d">

<Grid Padding="12">
<TextBlock
x:Name="Marker"
Margin="0,0,0,12"
Text="Original marker" />
<utu:LoadingView x:Name="LV">
<utu:LoadingView.LoadingContent>
<TextBlock Text="Loading…" />
</utu:LoadingView.LoadingContent>
</utu:LoadingView>
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Uno.Toolkit.RuntimeTests.Tests.TestPages
{
public sealed partial class LoadingViewPage : Page
{
public LoadingViewPage()
{
this.InitializeComponent();
}
}
}
3 changes: 2 additions & 1 deletion src/Uno.Toolkit.RuntimeTests/Uno.Toolkit.RuntimeTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Uno.UI.RuntimeTests.Engine" />
<PackageReference Include="MSTest.TestFramework" />
<PackageReference Include="Uno.WinUI.DevServer" />
<PackageReference Include="MSTest.TestFramework" />
<PackageReference Include="FluentAssertions" />
</ItemGroup>
<ItemGroup>
Expand Down
44 changes: 44 additions & 0 deletions src/Uno.Toolkit.UI/Controls/LoadingView/LoadingView.HotReload.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#if IS_WINUI
using System;
using System.Collections.Generic;
using System.Reflection.Metadata;
using System.Threading.Tasks;
using Microsoft.UI.Xaml;
using Uno.Toolkit.UI;

[assembly: ElementMetadataUpdateHandlerAttribute(typeof(LoadingView), typeof(LoadingViewElementMetadataUpdateHandler))]

namespace Uno.Toolkit.UI;

internal static class LoadingViewElementMetadataUpdateHandler
{
private const string SourceKey = nameof(LoadingView) + "." + nameof(LoadingView.Source);
private const string ContentKey = nameof(LoadingView) + "." + nameof(LoadingView.Content);

public static void CaptureState(FrameworkElement element, IDictionary<string, object> stateDictionary, Type[]? updatedTypes)
{
if (element is LoadingView lv)
{
stateDictionary[SourceKey] = lv.Source;
stateDictionary[ContentKey] = lv.Content;
}
}

public static Task RestoreState(FrameworkElement element, IDictionary<string, object> state, Type[]? updatedTypes)
{
if (element is LoadingView lv)
{
if (lv.Source is null && lv.GetBindingExpression(LoadingView.SourceProperty) is null && state.TryGetValue(SourceKey, out var savedSrc) && savedSrc is ILoadable src)
{
lv.Source = src;
}
if (lv.Content is null && lv.GetBindingExpression(LoadingView.ContentProperty) is null && state.TryGetValue(ContentKey, out var savedContent) && savedContent is { } content)
{
lv.Content = content;
}
}

return Task.CompletedTask;
}
}
#endif
Loading