Skip to content

Commit

Permalink
Merge pull request #19362 from unoplatform/dev/dr/hrUpdates
Browse files Browse the repository at this point in the history
fix(hr): Fix Frame stack cache update on HR
  • Loading branch information
jeromelaban authored Jan 29, 2025
2 parents 1d090f0 + b9402ba commit 54ffcdc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 22 deletions.
61 changes: 39 additions & 22 deletions src/Uno.UI/UI/Xaml/Controls/Frame/Frame.HotReload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
using Uno.Foundation.Logging;
using Uno.UI.Helpers;

[assembly: ElementMetadataUpdateHandlerAttribute(typeof(Microsoft.UI.Xaml.Controls.Frame), typeof(Microsoft.UI.Xaml.Controls.FrameElementMetadataUpdateHandler))]
[assembly: ElementMetadataUpdateHandlerAttribute(typeof(Microsoft.UI.Xaml.Controls.Frame), typeof(Microsoft.UI.Xaml.Controls.Frame.FrameElementMetadataUpdateHandler))]

namespace Microsoft.UI.Xaml.Controls
namespace Microsoft.UI.Xaml.Controls;

partial class Frame
{
internal static partial class FrameElementMetadataUpdateHandler
{
Expand All @@ -20,36 +22,51 @@ public static void ElementUpdate(FrameworkElement element, Type[] updatedTypes)
{
typeof(FrameElementMetadataUpdateHandler).Log().LogWarning($"AfterElementReplaced should only be called with Frame instances");
}

return;
}

foreach (var entry in frame.BackStack)
if (frame._useWinUIBehavior)
{
var expectedType = entry.SourcePageType.GetReplacementType();
if (entry.Instance is not null &&
entry.Instance.GetType() != expectedType)
foreach (var type in updatedTypes)
{
if (typeof(FrameElementMetadataUpdateHandler).Log().IsEnabled(LogLevel.Trace))
{
typeof(FrameElementMetadataUpdateHandler).Log().Trace($"Backstack entry instance {entry.Instance.GetType().Name} replaced by instance of {expectedType.Name}");
}
var dc = entry.Instance.DataContext;
entry.Instance = Activator.CreateInstance(expectedType) as Page;
if (entry.Instance is not null)
// Note: Does not support CNOMUA
frame.RemovePageFromCache(type.FullName);
frame.RemovePageFromCache(type.AssemblyQualifiedName);
}
}
else // Uno's legacy implementation
{
foreach (var entry in frame.BackStack)
{
var expectedType = entry.SourcePageType.GetReplacementType();
if (entry.Instance is not null &&
entry.Instance.GetType() != expectedType)
{
entry.Instance.Frame = frame;
entry.Instance.DataContext = dc;
if (typeof(FrameElementMetadataUpdateHandler).Log().IsEnabled(LogLevel.Trace))
{
typeof(FrameElementMetadataUpdateHandler).Log().Trace($"Backstack entry instance {entry.Instance.GetType().Name} replaced by instance of {expectedType.Name}");
}

var dc = entry.Instance.DataContext;
entry.Instance = Activator.CreateInstance(expectedType) as Page;
if (entry.Instance is not null)
{
entry.Instance.Frame = frame;
entry.Instance.DataContext = dc;
}
}
}

if (entry.SourcePageType is not null &&
entry.SourcePageType != expectedType)
{
if (typeof(FrameElementMetadataUpdateHandler).Log().IsEnabled(LogLevel.Trace))
if (entry.SourcePageType is not null &&
entry.SourcePageType != expectedType)
{
typeof(FrameElementMetadataUpdateHandler).Log().Trace($"Backstack entry SourcePageType changed from {entry.SourcePageType.Name} to {expectedType.Name}");
if (typeof(FrameElementMetadataUpdateHandler).Log().IsEnabled(LogLevel.Trace))
{
typeof(FrameElementMetadataUpdateHandler).Log().Trace($"Backstack entry SourcePageType changed from {entry.SourcePageType.Name} to {expectedType.Name}");
}

entry.SourcePageType = expectedType;
}
entry.SourcePageType = expectedType;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Uno.UI/UI/Xaml/Navigation/PageStackEntry.Uno.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ namespace Microsoft.UI.Xaml.Navigation;

partial class PageStackEntry
{
// Note: LEGACY, not used by MUX (_useWinUIBehavior)
internal Page Instance { get; set; }
}

0 comments on commit 54ffcdc

Please sign in to comment.