fix: scroll stutter on trackpads (#419)
* try: disable interaction observer * try: use an itemSizeCache to prevent stutter (maybe) * misc: decrease overscan * use virtualItemEls.length instead
This commit is contained in:
1 parent
4fa3b7d395
commit
5e45191565
1 file changed
+16
-30
@@ -51,12 +51,25 @@
|
|||||||
const virtualizer = createWindowVirtualizer({
|
const virtualizer = createWindowVirtualizer({
|
||||||
count: posts.length,
|
count: posts.length,
|
||||||
estimateSize: () => 150,
|
estimateSize: () => 150,
|
||||||
|
overscan: 5,
|
||||||
|
measureElement: (element, entry, instance) => {
|
||||||
|
const direction = instance.scrollDirection
|
||||||
|
if (direction === 'forward' || direction === null) {
|
||||||
|
return element.scrollHeight
|
||||||
|
} else {
|
||||||
|
const indexKey = Number(element.getAttribute('data-index'))
|
||||||
|
// didnt ask
|
||||||
|
// @ts-ignore
|
||||||
|
let cacheMeasurement = instance.itemSizeCache.get(indexKey)
|
||||||
|
return cacheMeasurement
|
||||||
|
}
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
$: items = $virtualizer.getVirtualItems()
|
$: items = $virtualizer.getVirtualItems()
|
||||||
$: {
|
|
||||||
if (virtualItemEls.length)
|
$: if (virtualItemEls.length) {
|
||||||
virtualItemEls.forEach((el) => $virtualizer.measureElement(el))
|
virtualItemEls.forEach($virtualizer.measureElement)
|
||||||
}
|
}
|
||||||
|
|
||||||
$: if (posts.length && virtualListEl)
|
$: if (posts.length && virtualListEl)
|
||||||
@@ -179,33 +192,6 @@
|
|||||||
await tick()
|
await tick()
|
||||||
$virtualizer.measure()
|
$virtualizer.measure()
|
||||||
})
|
})
|
||||||
|
|
||||||
// keyboard handling
|
|
||||||
// let selectedIndex = writable(-1)
|
|
||||||
|
|
||||||
// function handleKeydown(event: KeyboardEvent) {
|
|
||||||
// if (event.key === 'ArrowUp') {
|
|
||||||
// event.preventDefault()
|
|
||||||
// $selectedIndex = Math.max(0, $selectedIndex - 1)
|
|
||||||
// } else if (event.key === 'ArrowDown') {
|
|
||||||
// event.preventDefault()
|
|
||||||
// $selectedIndex = Math.min(posts.length - 1, $selectedIndex + 1)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// onMount(() => {
|
|
||||||
// selectedIndex.subscribe(focusItem)
|
|
||||||
// })
|
|
||||||
|
|
||||||
// function focusItem(index: number) {
|
|
||||||
// const el =
|
|
||||||
// virtualItemEls.find(
|
|
||||||
// (el) => Number(el?.getAttribute('data-index')) == index
|
|
||||||
// ) ?? virtualItemEls[1]
|
|
||||||
|
|
||||||
// $virtualizer.scrollToIndex(index, { align: 'center', behavior: 'auto' })
|
|
||||||
// el?.firstChild?.firstChild?.parentElement?.focus({})
|
|
||||||
// }
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- <svelte:window on:keydown={handleKeydown} /> -->
|
<!-- <svelte:window on:keydown={handleKeydown} /> -->
|
||||||
|
|||||||
Reference in new issue
Block a user