From b20c0b464f5a25bb4d8009971b8ac4abec8f8edc Mon Sep 17 00:00:00 2001 From: MrRefactor Date: Wed, 27 Nov 2024 17:51:12 +0100 Subject: [PATCH] fix(js): Fix position and offset calculations and adding a new page for usePagerView hook --- example/src/PagerHookExample.tsx | 11 +---------- src/usePagerView.ts | 12 +++++++----- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/example/src/PagerHookExample.tsx b/example/src/PagerHookExample.tsx index cec2f54d..c8b4261f 100644 --- a/example/src/PagerHookExample.tsx +++ b/example/src/PagerHookExample.tsx @@ -11,20 +11,12 @@ export function PagerHookExample() { return ( {useMemo( () => @@ -49,7 +41,6 @@ export function PagerHookExample() { [rest.pages] )} - {/*@ts-ignore*/} ); diff --git a/src/usePagerView.ts b/src/usePagerView.ts index 01f7746b..a6f9fac7 100644 --- a/src/usePagerView.ts +++ b/src/usePagerView.ts @@ -48,11 +48,7 @@ export function usePagerView( const addPage = useCallback(() => { setPages((prevPages) => { - const lastPageNumber = prevPages[prevPages.length - 1]; - if (lastPageNumber) { - return [...prevPages, lastPageNumber + 1]; - } - return prevPages; + return [...prevPages, prevPages.length]; }); }, []); @@ -92,6 +88,12 @@ export function usePagerView( }, ], { + listener: ({ nativeEvent: { offset, position } }) => { + setProgress({ + position, + offset, + }); + }, useNativeDriver: true, } ),