mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
optimize home page load speed
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Markup;
|
||||
using Microsoft.UI.Xaml.Navigation;
|
||||
using Snap.Hutao.Service.Navigation;
|
||||
using Snap.Hutao.View.Helper;
|
||||
@@ -37,6 +38,11 @@ internal class ScopedPage : Page
|
||||
extra.NotifyNavigationCompleted();
|
||||
}
|
||||
|
||||
public virtual void UnloadObjectOverride(DependencyObject unloadableObject)
|
||||
{
|
||||
XamlMarkupHelper.UnloadObject(unloadableObject);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化
|
||||
/// 应当在 InitializeComponent() 前调用
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<TransitionCollection x:Key="ContentThemeTransitions">
|
||||
<ContentThemeTransition/>
|
||||
</TransitionCollection>
|
||||
@@ -20,4 +20,4 @@
|
||||
<TransitionCollection x:Key="NavigationThemeTransitions">
|
||||
<NavigationThemeTransition/>
|
||||
</TransitionCollection>
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary>
|
||||
@@ -340,7 +340,7 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Snap.Hutao.SourceGeneration" Version="1.0.9">
|
||||
<PackageReference Include="Snap.Hutao.SourceGeneration" Version="1.0.11">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Markup;
|
||||
using Snap.Hutao.Control;
|
||||
|
||||
namespace Snap.Hutao.View.Helper;
|
||||
|
||||
@@ -11,14 +13,28 @@ internal sealed class DeferContentLoader : IDeferContentLoader
|
||||
|
||||
public DeferContentLoader(FrameworkElement element)
|
||||
{
|
||||
this.reference.SetTarget(element);
|
||||
reference.SetTarget(element);
|
||||
}
|
||||
|
||||
public void Load(string name)
|
||||
public DependencyObject? Load(string name)
|
||||
{
|
||||
if (reference.TryGetTarget(out FrameworkElement? element))
|
||||
{
|
||||
element.FindName(name);
|
||||
return element.FindName(name) as DependencyObject;
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
public void Unload(DependencyObject @object)
|
||||
{
|
||||
if (reference.TryGetTarget(out FrameworkElement? element) && element is ScopedPage scopedPage)
|
||||
{
|
||||
scopedPage.UnloadObjectOverride(@object);
|
||||
}
|
||||
else
|
||||
{
|
||||
XamlMarkupHelper.UnloadObject(@object);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.UI.Xaml;
|
||||
|
||||
namespace Snap.Hutao.View.Helper;
|
||||
|
||||
internal interface IDeferContentLoader
|
||||
{
|
||||
void Load(string name);
|
||||
DependencyObject? Load(string name);
|
||||
|
||||
void Unload(DependencyObject @object);
|
||||
}
|
||||
@@ -7,6 +7,7 @@ using Snap.Hutao.Service.Announcement;
|
||||
using Snap.Hutao.Service.Hutao;
|
||||
using Snap.Hutao.View.Card;
|
||||
using Snap.Hutao.View.Card.Primitive;
|
||||
using Snap.Hutao.View.Page;
|
||||
using Snap.Hutao.Web.Hoyolab.Hk4e.Common.Announcement;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user