mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-25 21:34:28 +08:00
fix(ui): 修复UiRouterBase弹出栈时目标UI键可空性问题
- 将topUiKey重命名为leavingUiKey以提高代码可读性 - 修改nextUiKey逻辑使其在栈中只有一个元素时返回null而非抛出异常 - 更新CreateEvent方法参数toUiKey为可空字符串类型 - 调整UiTransitionEvent中的ToUiKey属性为可空字符串类型 - 添加注释说明nextUiKey现在是可选的 - 格式化代码缩进和换行以提高可读性
This commit is contained in:
parent
039152438b
commit
5ef6145688
@ -22,7 +22,7 @@ public sealed class UiTransitionEvent
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 目标UI的标识符,切换后的UI key
|
/// 目标UI的标识符,切换后的UI key
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string ToUiKey { get; init; } = string.Empty;
|
public string? ToUiKey { get; init; } = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// UI切换类型
|
/// UI切换类型
|
||||||
|
|||||||
@ -14,6 +14,16 @@ public abstract class UiRouterBase : AbstractSystem, IUiRouter
|
|||||||
{
|
{
|
||||||
private static readonly ILogger Log = LoggerFactoryResolver.Provider.CreateLogger("UiRouterBase");
|
private static readonly ILogger Log = LoggerFactoryResolver.Provider.CreateLogger("UiRouterBase");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 路由守卫列表
|
||||||
|
/// </summary>
|
||||||
|
private readonly List<IUiRouteGuard> _guards = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 层级管理(非栈层级),用于Overlay、Modal、Toast等浮层
|
||||||
|
/// </summary>
|
||||||
|
private readonly Dictionary<UiLayer, Dictionary<string, IUiPageBehavior>> _layers = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// UI切换处理器管道
|
/// UI切换处理器管道
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -24,11 +34,6 @@ public abstract class UiRouterBase : AbstractSystem, IUiRouter
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly Stack<IUiPageBehavior> _stack = new();
|
private readonly Stack<IUiPageBehavior> _stack = new();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 层级管理(非栈层级),用于Overlay、Modal、Toast等浮层
|
|
||||||
/// </summary>
|
|
||||||
private readonly Dictionary<UiLayer, Dictionary<string, IUiPageBehavior>> _layers = new();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// UI工厂实例,用于创建UI相关的对象
|
/// UI工厂实例,用于创建UI相关的对象
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -36,11 +41,6 @@ public abstract class UiRouterBase : AbstractSystem, IUiRouter
|
|||||||
|
|
||||||
private IUiRoot _uiRoot = null!;
|
private IUiRoot _uiRoot = null!;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 路由守卫列表
|
|
||||||
/// </summary>
|
|
||||||
private readonly List<IUiRouteGuard> _guards = new();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 注册UI切换处理器
|
/// 注册UI切换处理器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -143,19 +143,23 @@ public abstract class UiRouterBase : AbstractSystem, IUiRouter
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var topUiKey = _stack.Peek().Key;
|
var leavingUiKey = _stack.Peek().Key;
|
||||||
|
|
||||||
// 执行离开守卫
|
if (!ExecuteLeaveGuardsAsync(leavingUiKey).GetAwaiter().GetResult())
|
||||||
if (!ExecuteLeaveGuardsAsync(topUiKey).GetAwaiter().GetResult())
|
|
||||||
{
|
{
|
||||||
Log.Warn("Pop blocked by guard: {0}", topUiKey);
|
Log.Warn("Pop blocked by guard: {0}", leavingUiKey);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ⚠️ 注意:nextUiKey 现在是可选的
|
||||||
var nextUiKey = _stack.Count > 1
|
var nextUiKey = _stack.Count > 1
|
||||||
? _stack.ElementAt(1).Key // 使用 Key 而不是 View.GetType().Name
|
? _stack.ElementAt(1).Key
|
||||||
: throw new InvalidOperationException("Stack is empty");
|
: null;
|
||||||
var @event = CreateEvent(nextUiKey, UiTransitionType.Pop);
|
|
||||||
|
var @event = CreateEvent(
|
||||||
|
nextUiKey,
|
||||||
|
type: UiTransitionType.Pop
|
||||||
|
);
|
||||||
|
|
||||||
BeforeChange(@event);
|
BeforeChange(@event);
|
||||||
|
|
||||||
@ -164,6 +168,7 @@ public abstract class UiRouterBase : AbstractSystem, IUiRouter
|
|||||||
AfterChange(@event);
|
AfterChange(@event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 替换当前所有页面为新页面(基于uiKey)
|
/// 替换当前所有页面为新页面(基于uiKey)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -312,7 +317,7 @@ public abstract class UiRouterBase : AbstractSystem, IUiRouter
|
|||||||
/// 创建UI切换事件
|
/// 创建UI切换事件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private UiTransitionEvent CreateEvent(
|
private UiTransitionEvent CreateEvent(
|
||||||
string toUiKey,
|
string? toUiKey,
|
||||||
UiTransitionType type,
|
UiTransitionType type,
|
||||||
UiTransitionPolicy? policy = null,
|
UiTransitionPolicy? policy = null,
|
||||||
IUiPageEnterParam? param = null
|
IUiPageEnterParam? param = null
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user