-
Notifications
You must be signed in to change notification settings - Fork 144
virtual
Improvements (Dynamic Item Sizes, Fix Broken Reactivity)
#803
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
base: main
Are you sure you want to change the base?
virtual
Improvements (Dynamic Item Sizes, Fix Broken Reactivity)
#803
Conversation
|
I tried to provide a way to access type VirtualListProps<T extends readonly any[], U extends JSX.Element> = {
// ...
setScrollToItem: (scrollToItem: (itemIndex: number) => void) => void;
};
// Inside `VirtualList`
let scrollContainer!: HTMLDivElement; // Attached Ref
props.setScrollToItem((itemIndex: number) => scrollToItem(itemIndex, scrollContainer)); In Use: let scrollToItem!: (itemIndex: number) => void;
// ...
<VirtualList
// ...
setScrollToItem={fn => (scrollToItem = fn)}
// ...
>
{/* ... */}
</VirtualList> Broken Reactivity *Now Fixed by this PR*Also, reactivity seems to be broken for the |
Alright, I fixed the issue with reactivity being broken by not unwrapping accessors at the top level of Would still like some help with exposing |
virtual
Improvements (Dynamic Item Sizes)virtual
Improvements (Dynamic Item Sizes, Fix Broken Reactivity)
callback indexes more useful
overscanCount?: MaybeAccessor<number>; | ||
rowHeight: MaybeAccessor<number | ((row: T[number], index: number) => number)>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An accessor that returns a function is a bit stupid. Shouldn't it be MaybeAccessor<number> | ((row: T[number], index: number) => number)
?
}); | ||
}); | ||
|
||
// Binary Search for performance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole function is already pretty complex without the binary search being included inside. I would like to ask you to extract from the function and use offsets as another parameter.
This adds support for dynamic item sizes in the
virtual
package.This is accomplished by adding
| (row: T[number], index: number) => number)
to therowHeight
parameter, and type-checking for either case withincreateVirtualList
.I also added
scrollToItem
toVirtualListReturn
as a utility function for scrolling to a specified item index.I'm implementing this because I need it for use in another project, so if I end up needing more features I'll implement them (but I'm also happy to work on other stuff if it's requested). This is an early stage PR and my first crack back at SolidJS in almost half a year after working on other projects, so I'm very rusty and probably didn't implement all of this idiomatically—please correct me if necessary.
(Also contains a small patch to add
type
to an import insite/src/primitives/DocumentHydrationHelper.tsx
, since the dev server would not run without that change)