Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add useful options to surface information to end user #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type PageProps = {
index: number;
focusAnim: Animated.DerivedValue<number>;
isActive: boolean;
isAdjacentToActive: boolean;
pageWidthAnim: Animated.SharedValue<number>;
pageHeightAnim: Animated.SharedValue<number>;
pageAnim: Animated.SharedValue<number>;
Expand All @@ -72,6 +73,7 @@ type Props = {
pageCallbackNode?: Animated.SharedValue<number>;
onPageChange?: (page: number) => void;
pageBuffer?: number; // number of pages to render on either side of active page
updatePagesInBuffer?: number; // number of pages to re-render on either side of active page after transition
style?: AnyStyle;
pageWrapperStyle?: AnyStyle;
pageInterpolator?: typeof defaultPageInterpolator;
Expand All @@ -89,6 +91,7 @@ type ImperativeApiOptions = {
};

export type InfinitePagerImperativeApi = {
getCurrentPage: () => number;
setPage: (index: number, options: ImperativeApiOptions) => void;
incrementPage: (options: ImperativeApiOptions) => void;
decrementPage: (options: ImperativeApiOptions) => void;
Expand All @@ -101,6 +104,7 @@ function InfinitePager(
pageCallbackNode,
onPageChange,
pageBuffer = 1,
updatePagesInBuffer,
style,
pageWrapperStyle,
minIndex = -Infinity,
Expand Down Expand Up @@ -156,6 +160,7 @@ function InfinitePager(
useImperativeHandle(
ref,
() => ({
getCurrentPage: () => curIndexRef.current,
setPage,
incrementPage: (options?: ImperativeApiOptions) => {
setPage(curIndexRef.current + 1, options);
Expand Down Expand Up @@ -251,6 +256,11 @@ function InfinitePager(
pageWidth={pageWidth}
pageHeight={pageHeight}
isActive={pageIndex === curIndex}
isAdjacentToActive={
updatePagesInBuffer
? Math.abs(pageIndex - curIndex) <= updatePagesInBuffer
: false
}
PageComponent={PageComponent}
renderPage={renderPage}
style={pageWrapperStyle}
Expand All @@ -273,6 +283,7 @@ type PageWrapperProps = {
PageComponent?: PageComponentType;
renderPage?: PageComponentType;
isActive: boolean;
isAdjacentToActive: boolean;
style?: AnyStyle;
pageInterpolatorRef: React.MutableRefObject<typeof defaultPageInterpolator>;
pageBuffer: number;
Expand All @@ -298,6 +309,7 @@ const PageWrapper = React.memo(
PageComponent,
renderPage,
isActive,
isAdjacentToActive,
style,
pageInterpolatorRef,
pageBuffer,
Expand Down Expand Up @@ -362,6 +374,7 @@ const PageWrapper = React.memo(
<PageComponent
index={index}
isActive={isActive}
isAdjacentToActive={isAdjacentToActive}
focusAnim={focusAnim}
pageWidthAnim={pageWidth}
pageHeightAnim={pageHeight}
Expand All @@ -371,6 +384,7 @@ const PageWrapper = React.memo(
renderPage?.({
index,
isActive,
isAdjacentToActive,
focusAnim,
pageWidthAnim: pageWidth,
pageHeightAnim: pageHeight,
Expand Down