Skip to content

Commit

Permalink
feat(birthday): allowing autoplay
Browse files Browse the repository at this point in the history
  • Loading branch information
mateoguzmana committed Aug 10, 2022
1 parent 31fc371 commit cde4d76
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/components/Balloon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ function Balloon({ x, y = 0, color, r = 40 }: BalloonProps) {
[x]
);

const skewX =
SKEW_X_VALUES[Math.floor(Math.random() * SKEW_X_VALUES.length)] ?? 0;
const skewX = useMemo(
() => SKEW_X_VALUES[Math.floor(Math.random() * SKEW_X_VALUES.length)] ?? 0,
[]
);

return (
<Group
Expand Down
10 changes: 7 additions & 3 deletions src/components/Birthday.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { screenHeight, screenWidth } from '../constants/dimensions';

interface BirthdayProps {
theme?: string[];
autoplay?: boolean;
}

const xGap = 60;
Expand All @@ -22,7 +23,10 @@ const BOTTOM = -350;
const optimalNumberOfBalloons = Math.floor(screenWidth / xGap);
const ballonsToRenderArray = [...Array(optimalNumberOfBalloons)];

function Birthday({ theme = FiestaThemes.default }: BirthdayProps) {
function Birthday({
theme = FiestaThemes.default,
autoplay = true,
}: BirthdayProps) {
const randomisedColors = useMemo(() => shuffleArray(theme), [theme]);

const xPosition = useValue(screenHeight - BOTTOM + 0);
Expand All @@ -49,8 +53,8 @@ function Birthday({ theme = FiestaThemes.default }: BirthdayProps) {
);

useEffect(() => {
pushBalloons();
}, [pushBalloons]);
autoplay && pushBalloons();
}, [pushBalloons, autoplay]);

return (
<Canvas style={styles.canvas}>
Expand Down

0 comments on commit cde4d76

Please sign in to comment.