From 5ad1dd9a70c828ed590b34138f1185beacce7b31 Mon Sep 17 00:00:00 2001 From: "tyler.lu" <> Date: Wed, 29 Nov 2023 14:19:29 +0800 Subject: [PATCH 1/2] feat: add offset --- src/index.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index eecb525..581f9b8 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -185,7 +185,7 @@ function VTable(props: any, otherParams): JSX.Element { const { style, children, ...rest } = props const { width, ...rest_style } = style - const { vid, scrollY, reachEnd, onScroll, resetScrollTopWhenDataChange } = + const { vid, scrollY, offset, reachEnd, onScroll, resetScrollTopWhenDataChange } = otherParams ?? {} const [state, dispatch] = useReducer(reducer, initialState) @@ -318,7 +318,7 @@ function VTable(props: any, otherParams): JSX.Element { if (scrollTop === scrollHeight) { // reachEnd && reachEnd() } else if ( - scrollTop + clientHeight >= scrollHeight && + scrollTop + clientHeight + offset >= scrollHeight && historyScrollHeight !== scrollHeight ) { // 相同的tableData情况下, 上次reachEnd执行后, scrollHeight不变, 则不会再次请求reachEnd @@ -414,6 +414,8 @@ export function VList(props: { // 重置scrollTop 当数据变更的时候. 默认为true // reset scrollTop when data change resetTopWhenDataChange?: boolean + // 偏移量,可提前到到底部,请求接口 + offset?: number }): any { const { vid = DEFAULT_VID, @@ -423,6 +425,7 @@ export function VList(props: { onListRender, debounceListRenderMS, resetTopWhenDataChange = true, + offset } = props const resetScrollTopWhenDataChange = onReachEnd @@ -448,6 +451,7 @@ export function VList(props: { onScroll, onListRender, resetScrollTopWhenDataChange, + offset }), body: { wrapper: VWrapper, From 487f6ff38223f7a210eea47e46571d2c6d2c8cfc Mon Sep 17 00:00:00 2001 From: "tyler.lu" <> Date: Wed, 29 Nov 2023 14:22:18 +0800 Subject: [PATCH 2/2] feat: add offset default value --- src/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.tsx b/src/index.tsx index 581f9b8..8f4f6f6 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -185,7 +185,7 @@ function VTable(props: any, otherParams): JSX.Element { const { style, children, ...rest } = props const { width, ...rest_style } = style - const { vid, scrollY, offset, reachEnd, onScroll, resetScrollTopWhenDataChange } = + const { vid, scrollY, offset = 0, reachEnd, onScroll, resetScrollTopWhenDataChange } = otherParams ?? {} const [state, dispatch] = useReducer(reducer, initialState)