Skip to content

Commit

Permalink
feat: added "parallaxAdjacentItemScale" property into parallax layout
Browse files Browse the repository at this point in the history
  • Loading branch information
yepMad committed Feb 27, 2022
1 parent 94c0f89 commit 7e98433
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/layouts/ParallaxLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const ParallaxLayout: React.FC<
loop?: boolean;
parallaxScrollingOffset?: number;
parallaxScrollingScale?: number;
parallaxAdjacentItemScale?: number;
handlerOffsetX: Animated.SharedValue<number>;
index: number;
data: unknown[];
Expand All @@ -26,6 +27,7 @@ export const ParallaxLayout: React.FC<
handlerOffsetX,
parallaxScrollingOffset = 100,
parallaxScrollingScale = 0.8,
parallaxAdjacentItemScale = Math.pow(parallaxScrollingScale, 2),
index,
width,
height,
Expand Down Expand Up @@ -76,9 +78,9 @@ export const ParallaxLayout: React.FC<
value,
[-1, 0, 1],
[
Math.pow(parallaxScrollingScale, 2),
parallaxAdjacentItemScale,
parallaxScrollingScale,
Math.pow(parallaxScrollingScale, 2),
parallaxAdjacentItemScale,
],
Extrapolate.CLAMP
);
Expand Down
15 changes: 11 additions & 4 deletions src/layouts/parallax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ interface ILayoutConfig {
* @default 0.8
*/
parallaxScrollingScale?: number;
/**
* When use default Layout props,this prop can be control prev/next item offset.
* @default Math.pow(parallaxScrollingScale, 2)
*/
parallaxAdjacentItemScale?: number;
}

export type TParallaxModeProps = ComputedDirectionTypes<{
Expand All @@ -32,8 +37,10 @@ export function parallaxLayout(
modeConfig: ILayoutConfig = {}
) {
const { size, vertical } = baseConfig;
const { parallaxScrollingOffset = 100, parallaxScrollingScale = 0.8 } =
modeConfig;
const { parallaxScrollingOffset = 100,
parallaxScrollingScale = 0.8,
parallaxAdjacentItemScale = Math.pow(parallaxScrollingScale, 2),
} = modeConfig;

return (value: number) => {
'worklet';
Expand All @@ -54,9 +61,9 @@ export function parallaxLayout(
value,
[-1, 0, 1],
[
Math.pow(parallaxScrollingScale, 2),
parallaxAdjacentItemScale,
parallaxScrollingScale,
Math.pow(parallaxScrollingScale, 2),
parallaxAdjacentItemScale,
],
Extrapolate.CLAMP
);
Expand Down

0 comments on commit 7e98433

Please sign in to comment.