1- import { RefObject , UIEvent , useCallback , useLayoutEffect } from "react" ;
1+ import { RefObject , UIEvent , useCallback , useEffect , useLayoutEffect } from "react" ;
22import { useOnScreen } from "@mendix/widget-plugin-hooks/useOnScreen" ;
33import { useGridSizeStore } from "@mendix/datagrid-web/src/model/hooks/injection-hooks" ;
4-
5- const offsetBottom = 30 ;
4+ import { VIRTUAL_SCROLLING_OFFSET } from "../stores/GridSize.store" ;
65
76export function useInfiniteControl ( ) : [ trackBodyScrolling : ( ( e : any ) => void ) | undefined ] {
87 const gridSizeStore = useGridSizeStore ( ) ;
@@ -33,7 +32,7 @@ export function useInfiniteControl(): [trackBodyScrolling: ((e: any) => void) |
3332 * causing mismatch by 1 pixel point, thus, add magic number 2 as buffer.
3433 */
3534 const bottom =
36- Math . floor ( target . scrollHeight - offsetBottom - target . scrollTop ) <=
35+ Math . floor ( target . scrollHeight - VIRTUAL_SCROLLING_OFFSET - target . scrollTop ) <=
3736 Math . floor ( target . clientHeight ) + 2 ;
3837 if ( bottom ) {
3938 gridSizeStore . bumpPage ( ) ;
@@ -42,18 +41,9 @@ export function useInfiniteControl(): [trackBodyScrolling: ((e: any) => void) |
4241 [ gridSizeStore ]
4342 ) ;
4443
45- const gridBody = gridSizeStore . gridBodyRef . current ;
46- const { hasVirtualScrolling, gridBodyHeight, hasMoreItems } = gridSizeStore ;
47-
48- const lockGridBodyHeight = useCallback ( ( ) : void => {
49- if ( isVisible && hasVirtualScrolling && hasMoreItems && gridBodyHeight === undefined && gridBody ) {
50- gridSizeStore . setGridBodyHeight ( gridBody . clientHeight - offsetBottom ) ;
51- }
52- } , [ isVisible , hasVirtualScrolling , hasMoreItems , gridBodyHeight , gridBody , gridSizeStore ] ) ;
53-
54- useLayoutEffect ( ( ) => {
55- setTimeout ( ( ) => lockGridBodyHeight ( ) , 100 ) ;
56- } , [ lockGridBodyHeight ] ) ;
44+ useEffect ( ( ) => {
45+ setTimeout ( ( ) => isVisible && gridSizeStore . lockGridBodyHeight ( ) , 100 ) ;
46+ } , [ isVisible , gridSizeStore ] ) ;
5747
5848 useLayoutEffect ( ( ) => {
5949 const observeTarget = gridSizeStore . gridContainerRef . current ;
0 commit comments