Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small performance update for rendering list items #1476

Merged
merged 5 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:err
dotnet_style_require_accessibility_modifiers = for_non_interface_members:error

# Require var all the time.
csharp_style_var_for_built_in_types = true:error
csharp_style_var_when_type_is_apparent = true:error
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
csharp_style_var_elsewhere = true:suggestion

# Expression-level preferences
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@
List<Option<int>> intOptions = new()
{
{ new Option<int> { Value = 1, Text = 1, Disabled = true, Icon = (new Icons.Regular.Size24.NumberCircle1(), Color.Neutral, "start" ) } },
{ new Option<int> { Value = 2, Text = 2, Icon = (new Icons.Regular.Size24.NumberCircle2(), Color.Neutral, "start" ) } },
{ new Option<int> { Value = 2, Text = 2, Icon = (new Icons.Regular.Size24.NumberCircle2(), Color.Neutral, "end" ) } },
{ new Option<int> { Value = 3, Text = 3, Icon = (new Icons.Regular.Size24.NumberCircle3(), Color.Neutral, "start" ) } }

};
}
}
8 changes: 8 additions & 0 deletions src/Core/Components/List/IOptionIcon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// ------------------------------------------------------------------------
// MIT License - Copyright (c) Microsoft Corporation. All rights reserved.
// ------------------------------------------------------------------------
namespace Microsoft.FluentUI.AspNetCore.Components;
internal interface IOptionIcon
{
(Icon Value, Color? Color, string? Slot)? Icon { get; set; }
}
33 changes: 16 additions & 17 deletions src/Core/Components/List/ListComponentBase.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@

@code
{

private void RenderOptions(RenderTreeBuilder __builder)
{

if (Items is null)
{
@ChildContent
}
else
{
foreach (TOption item in Items)
bool optionItems = typeof(TOption).IsGenericType && typeof(TOption).GetGenericTypeDefinition() == typeof(Option<>);

@foreach (TOption item in Items)
{
<FluentOption TOption="TOption"
Value="@GetOptionValue(item)"
Expand All @@ -30,26 +34,21 @@
{
@GetOptionText(item)
}

@{
Type t = item.GetType();

}
@if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Option<>))

@if (optionItems)
{
PropertyInfo? prop = t.GetProperty("Icon");

if (prop is not null)
var optionIcon = (IOptionIcon)item;
var value = optionIcon.Icon;

if (value.HasValue)
{
(Icon Value, Color? Color, string? Slot) = ((Icon Value, Color? Color, string? Slot)) prop.GetValue(item)!;
if (Value != null)
{
<FluentIcon Value="@Value" Color="@Color" Slot="@Slot" />
}
var icon = value.Value;
<FluentIcon Value="@icon.Value" Color="@icon.Color" Slot="@icon.Slot" />
}
}

}
</FluentOption>
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/Core/Components/List/ListComponentBase.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ protected virtual async Task OnKeydownHandlerAsync(KeyboardEventArgs e)
// This delay is needed for WASM to be able to get the updated value of the active descendant.
// Without it, the value sometimes lags behind and you then need two keypresses to move to the next/prev option.
await Task.Delay(1);
string? id = await Module!.InvokeAsync<string>("getAriaActiveDescendant", Id);
var id = await Module!.InvokeAsync<string>("getAriaActiveDescendant", Id);

FluentOption<TOption> item = _internalListContext.Options.First(i => i.Id == id);

Expand Down
4 changes: 2 additions & 2 deletions src/Core/Components/List/Option.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
namespace Microsoft.FluentUI.AspNetCore.Components;

public class Option<TType>
public class Option<TType> : IOptionIcon
{
public TType? Value { get; set; }

public TType? Text { get; set; }

public (Icon Value, Color? Color, string? Slot) Icon { get; set; }
public (Icon Value, Color? Color, string? Slot)? Icon { get; set; }

public bool Disabled { get; set; } = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

<h1>Hello, world!</h1>

Welcome to your new Fluent Blazor app.
Welcome to your new Fluent Blazor app.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.FluentUI.AspNetCore.Components" Version="4.*-* " />
<PackageReference Include="Microsoft.FluentUI.AspNetCore.Components.Icons" Version="4.*-* " />
<PackageReference Include="Microsoft.FluentUI.AspNetCore.Components.Icons" Version="4.*-* " />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\..\src\Core\Microsoft.FluentUI.AspNetCore.Components.csproj" />
</ItemGroup>
</Project>
Loading
Loading