Skip to content

Commit

Permalink
fix(js): Fix position and offset calculations & adding a new page for…
Browse files Browse the repository at this point in the history
… usePagerView hook (#930)
  • Loading branch information
MrRefactor authored Nov 28, 2024
1 parent 4675e83 commit 54c935f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
11 changes: 1 addition & 10 deletions example/src/PagerHookExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,12 @@ export function PagerHookExample() {
return (
<SafeAreaView style={styles.container}>
<AnimatedPagerView
// @ts-ignore
testID="pager-view"
ref={ref}
style={styles.PagerView}
initialPage={0}
layoutDirection="ltr"
overdrag={rest.overdragEnabled}
scrollEnabled={rest.scrollEnabled}
onPageScroll={rest.onPageScroll}
onPageSelected={rest.onPageSelected}
onPageScrollStateChanged={rest.onPageScrollStateChanged}
{...rest}
pageMargin={10}
// Lib does not support dynamically orientation change
orientation="horizontal"
>
{useMemo(
() =>
Expand All @@ -49,7 +41,6 @@ export function PagerHookExample() {
[rest.pages]
)}
</AnimatedPagerView>
{/*@ts-ignore*/}
<NavigationPanel {...rest} />
</SafeAreaView>
);
Expand Down
12 changes: 7 additions & 5 deletions src/usePagerView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
});
}, []);

Expand Down Expand Up @@ -92,6 +88,12 @@ export function usePagerView(
},
],
{
listener: ({ nativeEvent: { offset, position } }) => {
setProgress({
position,
offset,
});
},
useNativeDriver: true,
}
),
Expand Down

0 comments on commit 54c935f

Please sign in to comment.