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

Add getItemOffset to VirtualizerHandle #389

Merged
merged 1 commit into from
Feb 21, 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
6 changes: 6 additions & 0 deletions src/react/Virtualizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
* Get current offsetHeight or offsetWidth.
*/
readonly viewportSize: number;
/**
* Get item offset from start.
* @param index index of item
*/
getItemOffset(index: number): number;
/**
* Scroll to the item specified by index.
* @param index index of item
Expand Down Expand Up @@ -278,7 +283,7 @@
if (!onRangeChangeProp) return;

onRangeChangeProp(startIndex, endIndex);
}, [startIndex, endIndex]);

Check warning on line 286 in src/react/Virtualizer.tsx

View workflow job for this annotation

GitHub Actions / check

React Hook useEffect has a missing dependency: 'onRangeChangeProp'. Either include it or remove the dependency array. If 'onRangeChangeProp' changes too often, find the parent component that defines it and wrap that definition in useCallback

useImperativeHandle(
ref,
Expand All @@ -296,12 +301,13 @@
get viewportSize() {
return store._getViewportSize();
},
getItemOffset: store._getItemOffset,
scrollToIndex: scroller._scrollToIndex,
scrollTo: scroller._scrollTo,
scrollBy: scroller._scrollBy,
};
},
[]

Check warning on line 310 in src/react/Virtualizer.tsx

View workflow job for this annotation

GitHub Actions / check

React Hook useImperativeHandle has missing dependencies: 'scroller._scrollBy', 'scroller._scrollTo', 'scroller._scrollToIndex', and 'store'. Either include them or remove the dependency array
);

for (
Expand Down
6 changes: 6 additions & 0 deletions src/solid/Virtualizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
* Get current offsetHeight or offsetWidth.
*/
readonly viewportSize: number;
/**
* Get item offset from start.
* @param index index of item
*/
getItemOffset(index: number): number;
/**
* Scroll to the item specified by index.
* @param index index of item
Expand Down Expand Up @@ -141,7 +146,7 @@
onScroll: _onScroll,
onScrollEnd: _onScrollEnd,
onRangeChange: _onRangeChange,
} = props;

Check warning on line 149 in src/solid/Virtualizer.tsx

View workflow job for this annotation

GitHub Actions / check

The reactive variable 'props' should be used within JSX, a tracked scope (like createEffect), or inside an event handler function, or else changes will be ignored

const store = createVirtualStore(
props.data.length,
Expand Down Expand Up @@ -215,6 +220,7 @@
get viewportSize() {
return store._getViewportSize();
},
getItemOffset: store._getItemOffset,
scrollToIndex: scroller._scrollToIndex,
scrollTo: scroller._scrollTo,
scrollBy: scroller._scrollBy,
Expand Down
1 change: 1 addition & 0 deletions src/vue/VList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const VList = /*#__PURE__*/ defineComponent({
get viewportSize() {
return handle.value!.viewportSize;
},
getItemOffset: (...args) => handle.value!.getItemOffset(...args),
scrollToIndex: (...args) => handle.value!.scrollToIndex(...args),
scrollTo: (...args) => handle.value!.scrollTo(...args),
scrollBy: (...args) => handle.value!.scrollBy(...args),
Expand Down
6 changes: 6 additions & 0 deletions src/vue/Virtualizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export interface VirtualizerHandle {
* Get current offsetHeight or offsetWidth.
*/
readonly viewportSize: number;
/**
* Get item offset from start.
* @param index index of item
*/
getItemOffset(index: number): number;
/**
* Scroll to the item specified by index.
* @param index index of item
Expand Down Expand Up @@ -171,6 +176,7 @@ export const Virtualizer = /*#__PURE__*/ defineComponent({
get viewportSize() {
return store._getViewportSize();
},
getItemOffset: store._getItemOffset,
scrollToIndex: scroller._scrollToIndex,
scrollTo: scroller._scrollTo,
scrollBy: scroller._scrollBy,
Expand Down
Loading