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

Update to work with preview9 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 10 additions & 1 deletion src/BlazorVirtualScrolling.App/App.razor
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
<Router AppAssembly="typeof(Program).Assembly" />
<Router AppAssembly="typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview4-19216-03" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview4-19216-03" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.0.0-preview4-19216-03" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview9.19424.4" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview9.19424.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.0.0-preview9.19424.4" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/BlazorVirtualScrolling.App/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
The <code>VirtualScroll</code> displays large lists of elements performantly by only rendering the items that fit on-screen. Loading hundreds of elements can be slow in any browser; virtual scrolling enables a performant way to simulate all items being rendered by making the height of the container element the same as the height of total number of elements to be rendered, and then only rendering the items in view.
</p>

<h4>VirtualScroll with @items.Count() items</h4>
<h4>VirtualScroll with @Items.Count() items</h4>


<VirtualScroll style="height: 500px;" ItemType="string" Items="@items" ItemHeight="50">
<VirtualScroll style="height: 500px;" ItemType="string" Items="@Items" ItemHeight="50">
<div>@context</div>
</VirtualScroll>

@functions
{
public IEnumerable<string> items = Enumerable.Range(0, 333000).Select(i => i.ToString()).ToArray();
public IEnumerable<string> Items = Enumerable.Range(0, 333000).Select(i => i.ToString()).ToArray();
}


Expand Down
9 changes: 4 additions & 5 deletions src/BlazorVirtualScrolling.App/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
@using Microsoft.AspNetCore.Components
@inherits LayoutComponentBase
@inject IUriHelper Url


<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
<a class="navbar-brand" href="@Url.ToAbsoluteUri("").AbsoluteUri">BlazorVirtualScrolling</a>
<a class="navbar-brand" href="/">BlazorVirtualScrolling</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="@Url.ToAbsoluteUri("").AbsoluteUri">Home <span class="sr-only">(current)</span></a>
<a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/SamProf/BlazorVirtualScrolling">GitHUB</a>
Expand All @@ -23,8 +22,8 @@
<li class="nav-item">
<a class="nav-link" href="https://www.samprof.com/">SamProf</a>
</li>
</ul>
</ul>

</div>
</nav>

Expand Down
2 changes: 1 addition & 1 deletion src/BlazorVirtualScrolling.App/_Imports.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@using System.Net.Http
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Layouts
@using Microsoft.AspNetCore.Components
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.JSInterop
@using BlazorVirtualScrolling.App
Expand Down
6 changes: 4 additions & 2 deletions src/BlazorVirtualScrolling/BlazorVirtualScrolling.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
Expand Down Expand Up @@ -32,7 +32,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Browser" Version="3.0.0-preview4-19216-03" />
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview9.19424.4" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview9.19424.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.0.0-preview9.19424.4" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class BaseVirtualScroll<ItemType> : ComponentBase, IVirtualScroll
[Parameter]
public int ItemHeight { get; set; } = 50;

public ElementRef Ref { get; set; }
public ElementReference Ref { get; set; }

[Parameter]
public RenderFragment<ItemType> ChildContent { get; set; }
Expand All @@ -29,21 +29,18 @@ public class BaseVirtualScroll<ItemType> : ComponentBase, IVirtualScroll

[Inject]
public IJSRuntime JsRuntime { get; set; }

private bool isFirstRender = true;

protected override async Task OnAfterRenderAsync()

protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync();
if (isFirstRender)
await base.OnAfterRenderAsync(firstRender);
if (firstRender)
{
this.JsHelper = new VirtualScrollJsHelper(this);
var scrollView = await JsRuntime.InvokeAsync<ScrollView>("blazorVirtualScrolling.init", Ref, new DotNetObjectRef(JsHelper));
this.SetScrollView(scrollView);
isFirstRender = false;
var scrollView = await JsRuntime.InvokeAsync<ScrollView>("blazorVirtualScrolling.init", Ref, DotNetObjectReference.Create(JsHelper));
this.SetScrollView(scrollView);
}
}

public VirtualScrollJsHelper JsHelper { get; set; }

public void VirtualScrollingSetView(ScrollView scrollView)
Expand Down
2 changes: 1 addition & 1 deletion src/BlazorVirtualScrolling/VirtualScroll.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@using Microsoft.AspNetCore.Components
@inherits BaseVirtualScroll<ItemType>

<div class="@(Class) blazor-virtual-scroll" style="@Style" ref="Ref">
<div class="@(Class) blazor-virtual-scroll" style="@Style" @ref="Ref">
@if (ScrollViewResult != null)
{

Expand Down