Skip to content

Commit

Permalink
Merge pull request #2 from OsamaAburabie/enabled-prop
Browse files Browse the repository at this point in the history
feat: add enabled prop in StaggerProps
  • Loading branch information
catalinmiron committed Feb 12, 2024
2 parents 2edd978 + 104771c commit 83ae6ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export function Example() {
| name | description | required | type | default |
| ---------------------- | ------------------------------------------------------------------------------------------------------------ | -------- | ------------------------------- | ------------- |
| `children` | Any component that you'd like to apply infinite scrolling / marquee effect | YES | `React.ReactNode` | 1 |
| `enabled` | Enable stagger animation | NO | `boolean` | true |
| `stagger` | Stagger duration between elements | NO | `number` | 50 |
| `duration` | Enter/Exit animation duration | NO | `number` | 400 |
| `enterDirection` | The direction of the animation. `1 -> top to bottom`, `-1 -> bottom to top` | NO | `number` | 0 |
Expand Down
11 changes: 10 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import Animated, {
} from 'react-native-reanimated';

export type StaggerProps = React.PropsWithChildren<{
enabled?: boolean;
/**
* to enable or disable the stagger animation
*/
stagger?: number;
/**
* The direction of the enter animation.
Expand Down Expand Up @@ -72,6 +76,7 @@ export type StaggerProps = React.PropsWithChildren<{
}>;
export function Stagger({
children,
enabled = true,
stagger = 50,
enterDirection = 1,
exitDirection = -1,
Expand All @@ -88,6 +93,10 @@ export function Stagger({
return null;
}

if (!enabled) {
return <Animated.View style={style}>{children}</Animated.View>;
}

return (
<Animated.View style={style} layout={Layout}>
{React.Children.map(children, (child, index) => {
Expand Down Expand Up @@ -142,4 +151,4 @@ export function Stagger({
})}
</Animated.View>
);
}
}

0 comments on commit 83ae6ba

Please sign in to comment.