misc: update virtual list overscan logic
This commit is contained in:
5 files changed
+13
-7
No files matched your search
@@ -9,7 +9,6 @@
|
|||||||
import { Badge } from 'mono-svelte'
|
import { Badge } from 'mono-svelte'
|
||||||
import { Icon, ServerStack } from 'svelte-hero-icons'
|
import { Icon, ServerStack } from 'svelte-hero-icons'
|
||||||
import Link from '../input/Link.svelte'
|
import Link from '../input/Link.svelte'
|
||||||
import Entity from '../ui/Entity.svelte'
|
|
||||||
import Expandable from '../ui/Expandable.svelte'
|
import Expandable from '../ui/Expandable.svelte'
|
||||||
import LabelStat from '../ui/LabelStat.svelte'
|
import LabelStat from '../ui/LabelStat.svelte'
|
||||||
import ItemList from './generic/ItemList.svelte'
|
import ItemList from './generic/ItemList.svelte'
|
||||||
|
|||||||
@@ -42,8 +42,8 @@
|
|||||||
{#if offsetEl}
|
{#if offsetEl}
|
||||||
<VirtualList
|
<VirtualList
|
||||||
class="divide-y divide-slate-200 dark:divide-zinc-800 w-full"
|
class="divide-y divide-slate-200 dark:divide-zinc-800 w-full"
|
||||||
overscan={1000}
|
overscan={2}
|
||||||
estimatedHeight={300}
|
estimatedHeight={2000}
|
||||||
items={nodes}
|
items={nodes}
|
||||||
{initialOffset}
|
{initialOffset}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -174,7 +174,8 @@
|
|||||||
class="divide-y -mx-4 sm:-mx-6 divide-slate-200 dark:divide-zinc-900"
|
class="divide-y -mx-4 sm:-mx-6 divide-slate-200 dark:divide-zinc-900"
|
||||||
items={posts}
|
items={posts}
|
||||||
{initialOffset}
|
{initialOffset}
|
||||||
overscan={1000}
|
overscan={3}
|
||||||
|
estimatedHeight={settings.view == 'cozy' ? 500 : 150}
|
||||||
bind:restore={postFeeds.value[feedId].clientData}
|
bind:restore={postFeeds.value[feedId].clientData}
|
||||||
bind:this={listComp}
|
bind:this={listComp}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -112,13 +112,19 @@
|
|||||||
|
|
||||||
const firstIndex = findFirstVisibleIndex(scrollTop, cumulativeItemHeights)
|
const firstIndex = findFirstVisibleIndex(scrollTop, cumulativeItemHeights)
|
||||||
|
|
||||||
let i = firstIndex
|
const startIndex = Math.max(0, firstIndex - overscan)
|
||||||
|
|
||||||
|
let i = startIndex
|
||||||
let offset = i == 0 ? 0 : cumulativeItemHeights[i - 1]
|
let offset = i == 0 ? 0 : cumulativeItemHeights[i - 1]
|
||||||
|
|
||||||
while (i < items.length && offset < scrollTop + viewportHeight + overscan) {
|
while (i < items.length) {
|
||||||
newVisibleItems.push({ index: i, offset: offset })
|
newVisibleItems.push({ index: i, offset: offset })
|
||||||
const height = itemHeights[i] || estimatedHeight
|
const height = itemHeights[i] || estimatedHeight
|
||||||
offset += height
|
offset += height
|
||||||
|
|
||||||
|
if (offset > scrollTop + viewportHeight + overscan * estimatedHeight)
|
||||||
|
break
|
||||||
|
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -102,7 +102,7 @@
|
|||||||
<CommentForm
|
<CommentForm
|
||||||
postId={post.post_view.post.id}
|
postId={post.post_view.post.id}
|
||||||
oncomment={comment => {
|
oncomment={comment => {
|
||||||
comments.comments = [comment.comment_view, ...comments.comments]
|
comments.comments.push(comment.comment_view)
|
||||||
}}
|
}}
|
||||||
onfocus={() => (commenting = true)}
|
onfocus={() => (commenting = true)}
|
||||||
tools={commenting}
|
tools={commenting}
|
||||||
|
|||||||
Reference in new issue
Block a user