Skip to content

Commit

Permalink
fix(Responsive): break point no value at first render (#2698)
Browse files Browse the repository at this point in the history
* doc: 更新示例代码

* feat: 增加首次值传递逻辑

* fix: 修复首次加载未获取值问题

* chore: bump version 8.0.7-beta03
  • Loading branch information
ArgoZhang authored Dec 29, 2023
1 parent b6626b4 commit 7ec4790
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
<h3>@Localizer["ResponsiveTitle"]</h3>
<h4>@Localizer["ResponsiveDescription"]</h4>

<DemoBlock Title="@Localizer["ResponsiveNormalTitle"]"
Introduction="@Localizer["ResponsiveNormalIntro"]"
Name="Normal">
<DemoBlock Title="@Localizer["ResponsiveNormalTitle"]" Introduction="@Localizer["ResponsiveNormalIntro"]" Name="Normal">
<div>@Localizer["ResponsiveNormalIntroCurrentText"] <code>Breakpoint</code>:@Size</div>
<Responsive OnBreakPointChanged="OnChanged" />
</DemoBlock>
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>8.0.7-beta02</Version>
<Version>8.0.7-beta03</Version>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,20 @@ public class ResizeNotificationService
/// <param name="target"></param>
public void Unsubscribe(object target) => Cache.TryRemove(target, out _);

/// <summary>
/// 获得 当前值
/// </summary>
public BreakPoint CurrentValue { get; private set; }

/// <summary>
/// 内部调用
/// </summary>
/// <param name="breakPoint"></param>
/// <returns></returns>
internal async Task InvokeAsync(BreakPoint breakPoint)
{
CurrentValue = breakPoint;

foreach (var cb in Cache.Values)
{
await cb(breakPoint);
Expand Down
16 changes: 16 additions & 0 deletions src/BootstrapBlazor/Components/ResizeNotification/Responsive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ protected override void OnInitialized()
ResizeService.Subscribe(this, OnResize);
}

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="firstRender"></param>
/// <returns></returns>
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
if (OnBreakPointChanged != null)
{
await OnBreakPointChanged(ResizeService.CurrentValue);
}
}
}

/// <summary>
/// 客户端通知断点已改变
/// </summary>
Expand Down

0 comments on commit 7ec4790

Please sign in to comment.