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, } ),