Skip to content

Commit

Permalink
Merge pull request #15672 from ramezgerges/deferloadstrategy
Browse files Browse the repository at this point in the history
fix: DeferLoadStrategy should work even if no visibility is set
  • Loading branch information
jeromelaban authored Dec 5, 2024
2 parents e7be5d8 + fa1013f commit 4dabe7d
Show file tree
Hide file tree
Showing 40 changed files with 988 additions and 261 deletions.
6 changes: 5 additions & 1 deletion doc/articles/migrating-from-previous-releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ uid: Uno.Development.MigratingFromPreviousReleases

# Migrating from Previous Releases of Uno Platform

This article details the migration steps required to migrate from one version to the next when breaking changes are being introduced.
## Uno Platform 5.6

### Lazy loading

To align the behavior with WinUI, lazy loading using `x:Load="False"` and `x:DeferLoadStrategy="lazy"` is no longer affected with changes to the visibility of the lazily-loaded element. Previously, binding the `Visibility` property of the lazily-loaded element and then updating the source of the binding to make the element visible would cause the element to materialize (i.e. load). This is no longer the case. To load the element, add an `x:Name` to the element and call `FindName` with th given name.

## Uno Platform 5.5

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Testing;
using Uno.UI.SourceGenerators.Tests.Verifiers;

namespace Uno.UI.SourceGenerators.Tests.XamlCodeGeneratorTests;

using Verify = XamlSourceGeneratorVerifier;

[TestClass]
public class Given_LazyLoading
{
[TestMethod]
public async Task When_DeferLoadStrategy_No_Visibility_Set()
{
var xamlFile = new XamlFile("MainPage.xaml",
"""
<Page
x:Class="TestRepro.MainPage"
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel>
<TextBlock Text="Immediate content"/>
<Border x:Name="LazyLoadedBorder" x:DeferLoadStrategy="Lazy">
<TextBlock Text="Lazy Content" />
</Border>
</StackPanel>
</Page>
""");

var test = new Verify.Test(xamlFile)
{
TestState =
{
Sources =
{
"""
using System;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
namespace TestRepro
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
}
}
"""
}
},
ReferenceAssemblies = ReferenceAssemblies.Net.Net70.AddPackages(ImmutableArray.Create(new PackageIdentity("Uno.WinUI", "5.0.118"))),
DisableBuildReferences = true,
}.AddGeneratedSources();

await test.RunAsync();
}

[TestMethod]
public async Task When_xLoad_Child_Has_xBind()
{
var xamlFile = new XamlFile("MainPage.xaml",
"""
<Page
x:Class="TestRepro.MainPage"
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<ContentControl x:Name="topLevelContent" x:FieldModifier="public" x:Load="false">
<TextBlock x:Name="innerTextBlock" x:FieldModifier="public" Text="{x:Bind InnerText, Mode=OneWay}" />
</ContentControl>
</Page>
""");

var test = new Verify.Test(xamlFile)
{
TestState =
{
Sources =
{
"""
using System;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
namespace TestRepro
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
public string InnerText
{
get { return (string)GetValue(InnerTextProperty); }
set { SetValue(InnerTextProperty, value); }
}
public static readonly DependencyProperty InnerTextProperty =
DependencyProperty.Register("InnerText", typeof(string), typeof(MainPage), new PropertyMetadata("My inner text"));
}
}
"""
}
},
ReferenceAssemblies = ReferenceAssemblies.Net.Net70.AddPackages(ImmutableArray.Create(new PackageIdentity("Uno.WinUI", "5.0.118"))),
DisableBuildReferences = true,
}.AddGeneratedSources();

await test.RunAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,8 @@ void IMainPage_Bindings.Update()
void IMainPage_Bindings.UpdateResources()
{
var owner = Owner;
owner._component_0.UpdateResourceBindings(resourceContextProvider: null);
owner._component_1.UpdateResourceBindings(resourceContextProvider: null);
owner._component_0.UpdateResourceBindings();
owner._component_1.UpdateResourceBindings();
}
void IMainPage_Bindings.StopTracking()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ void IMainPage_Bindings.Update()
void IMainPage_Bindings.UpdateResources()
{
var owner = Owner;
owner._component_0.UpdateResourceBindings(resourceContextProvider: null);
owner._component_0.UpdateResourceBindings();
}
void IMainPage_Bindings.StopTracking()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void IMainPage_Bindings.Update()
void IMainPage_Bindings.UpdateResources()
{
var owner = Owner;
owner._component_0.UpdateResourceBindings(resourceContextProvider: null);
owner._component_0.UpdateResourceBindings();
}
void IMainPage_Bindings.StopTracking()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void IMainPage_Bindings.Update()
void IMainPage_Bindings.UpdateResources()
{
var owner = Owner;
owner._component_0.UpdateResourceBindings(resourceContextProvider: null);
owner._component_0.UpdateResourceBindings();
}
void IMainPage_Bindings.StopTracking()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ void IMainPage_Bindings.Update()
void IMainPage_Bindings.UpdateResources()
{
var owner = Owner;
owner._component_0.UpdateResourceBindings(resourceContextProvider: null);
owner._component_1.UpdateResourceBindings(resourceContextProvider: null);
owner._component_0.UpdateResourceBindings();
owner._component_1.UpdateResourceBindings();
}
void IMainPage_Bindings.StopTracking()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void IMainPage_Bindings.Update()
void IMainPage_Bindings.UpdateResources()
{
var owner = Owner;
owner._component_0.UpdateResourceBindings(resourceContextProvider: null);
owner._component_0.UpdateResourceBindings();
}
void IMainPage_Bindings.StopTracking()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void IMainPage_Bindings.Update()
void IMainPage_Bindings.UpdateResources()
{
var owner = Owner;
owner._component_0.UpdateResourceBindings(resourceContextProvider: null);
owner._component_0.UpdateResourceBindings();
}
void IMainPage_Bindings.StopTracking()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,10 @@ void IMainPage_Bindings.Update()
void IMainPage_Bindings.UpdateResources()
{
var owner = Owner;
owner._component_0.UpdateResourceBindings(resourceContextProvider: null);
owner._component_1.UpdateResourceBindings(resourceContextProvider: null);
owner._component_2.UpdateResourceBindings(resourceContextProvider: null);
owner._component_3.UpdateResourceBindings(resourceContextProvider: null);
owner._component_0.UpdateResourceBindings();
owner._component_1.UpdateResourceBindings();
owner._component_2.UpdateResourceBindings();
owner._component_3.UpdateResourceBindings();
}
void IMainPage_Bindings.StopTracking()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void IMainPage_Bindings.Update()
void IMainPage_Bindings.UpdateResources()
{
var owner = Owner;
owner._component_0.UpdateResourceBindings(resourceContextProvider: null);
owner._component_0.UpdateResourceBindings();
}
void IMainPage_Bindings.StopTracking()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void IMainWindow_Bindings.Update()
void IMainWindow_Bindings.UpdateResources()
{
var owner = Owner;
owner._component_0.UpdateResourceBindings(resourceContextProvider: null);
owner._component_0.UpdateResourceBindings();
}
void IMainWindow_Bindings.StopTracking()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,9 @@ void IMainPage_Bindings.Update()
void IMainPage_Bindings.UpdateResources()
{
var owner = Owner;
owner._component_0.UpdateResourceBindings(resourceContextProvider: null);
owner._component_1.UpdateResourceBindings(resourceContextProvider: null);
owner._component_2.UpdateResourceBindings(resourceContextProvider: null);
owner._component_0.UpdateResourceBindings();
owner._component_1.UpdateResourceBindings();
owner._component_2.UpdateResourceBindings();
}
void IMainPage_Bindings.StopTracking()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void IMainPage_Bindings.Update()
void IMainPage_Bindings.UpdateResources()
{
var owner = Owner;
owner._component_0.UpdateResourceBindings(resourceContextProvider: null);
owner._component_0.UpdateResourceBindings();
}
void IMainPage_Bindings.StopTracking()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,8 @@ void IMainPage_Bindings.Update()
void IMainPage_Bindings.UpdateResources()
{
var owner = Owner;
owner._component_0.UpdateResourceBindings(resourceContextProvider: null);
owner._component_1.UpdateResourceBindings(resourceContextProvider: null);
owner._component_0.UpdateResourceBindings();
owner._component_1.UpdateResourceBindings();
}
void IMainPage_Bindings.StopTracking()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ void IMainPage_Bindings.Update()
void IMainPage_Bindings.UpdateResources()
{
var owner = Owner;
owner._component_0.UpdateResourceBindings(resourceContextProvider: null);
owner._component_1.UpdateResourceBindings(resourceContextProvider: null);
owner._component_0.UpdateResourceBindings();
owner._component_1.UpdateResourceBindings();
}
void IMainPage_Bindings.StopTracking()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,9 @@ void IMainPage_Bindings.Update()
void IMainPage_Bindings.UpdateResources()
{
var owner = Owner;
owner._component_0.UpdateResourceBindings(resourceContextProvider: null);
owner._component_1.UpdateResourceBindings(resourceContextProvider: null);
owner._component_2.UpdateResourceBindings(resourceContextProvider: null);
owner._component_0.UpdateResourceBindings();
owner._component_1.UpdateResourceBindings();
owner._component_2.UpdateResourceBindings();
}
void IMainPage_Bindings.StopTracking()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void IMainPage_Bindings.Update()
void IMainPage_Bindings.UpdateResources()
{
var owner = Owner;
owner._component_0.UpdateResourceBindings(resourceContextProvider: null);
owner._component_0.UpdateResourceBindings();
}
void IMainPage_Bindings.StopTracking()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// <autogenerated />
namespace MyProject
{
/// <summary>
/// Contains all the static resources defined for the application
/// </summary>
public sealed partial class GlobalStaticResources
{
static bool _initialized;
private static bool _stylesRegistered;
private static bool _dictionariesRegistered;
internal static global::Uno.UI.Xaml.XamlParseContext __ParseContext_ { get; } = new global::Uno.UI.Xaml.XamlParseContext()
{
AssemblyName = "TestProject",
}
;

static GlobalStaticResources()
{
Initialize();
}
public static void Initialize()
{
if (!_initialized)
{
_initialized = true;
global::Uno.UI.GlobalStaticResources.Initialize();
global::Uno.UI.Toolkit.GlobalStaticResources.Initialize();
global::Uno.UI.GlobalStaticResources.RegisterDefaultStyles();
global::Uno.UI.Toolkit.GlobalStaticResources.RegisterDefaultStyles();
global::Uno.UI.GlobalStaticResources.RegisterResourceDictionariesBySource();
global::Uno.UI.Toolkit.GlobalStaticResources.RegisterResourceDictionariesBySource();
}
}
public static void RegisterDefaultStyles()
{
if(!_stylesRegistered)
{
_stylesRegistered = true;
RegisterDefaultStyles_MainPage_d6cd66944958ced0c513e0a04797b51d();
}
}
// Register ResourceDictionaries using ms-appx:/// syntax, this is called for external resources
public static void RegisterResourceDictionariesBySource()
{
if(!_dictionariesRegistered)
{
_dictionariesRegistered = true;
}
}
// Register ResourceDictionaries using ms-resource:/// syntax, this is called for local resources
internal static void RegisterResourceDictionariesBySourceLocal()
{
}
static partial void RegisterDefaultStyles_MainPage_d6cd66944958ced0c513e0a04797b51d();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// <auto-generated />
[assembly: global::System.Reflection.AssemblyMetadata("UnoHasLocalizationResources", "False")]
Loading

0 comments on commit 4dabe7d

Please sign in to comment.