From 71b51f8b438d68560755f5c09a90ad3c4a16fa0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Sun, 21 Aug 2022 11:48:45 +0200 Subject: [PATCH] feat(stars): wrapping stars using popper --- src/components/Stars.tsx | 84 +++++----------------------------------- 1 file changed, 10 insertions(+), 74 deletions(-) diff --git a/src/components/Stars.tsx b/src/components/Stars.tsx index 5e6a4b6..086d1e3 100644 --- a/src/components/Stars.tsx +++ b/src/components/Stars.tsx @@ -1,82 +1,18 @@ -import React, { memo, useCallback, useEffect, useMemo } from 'react'; -import { StyleSheet } from 'react-native'; -import { - Canvas, - Group, - runSpring, - useComputedValue, - useValue, -} from '@shopify/react-native-skia'; -import { screenHeight } from '../constants/dimensions'; -import { screenWidth } from '../constants/dimensions'; +import React, { memo } from 'react'; import Star from './Star'; -import { shuffleArray } from '../utils/array'; -import { FiestaThemes } from '../constants/theming'; -import { colorsFromTheme } from '../utils/colors'; +import Popper, { PopperProps } from './Popper'; -const xGap = 40; -const optimalNumberOfStars = Math.floor(screenWidth / xGap); -const starsToRenderArray = [...Array(optimalNumberOfStars)]; -const yPositions = shuffleArray(starsToRenderArray.map((_, i) => i * xGap)); - -export interface StarsProps { - theme?: string[]; -} - -function Stars({ theme = FiestaThemes.default }: StarsProps) { - const colors = useMemo( - () => colorsFromTheme(theme, optimalNumberOfStars), - [theme] - ); - - const yPosition = useValue(screenHeight); - - const changeItemPosition = useCallback( - () => - runSpring(yPosition, -screenHeight, { - stiffness: 0.5, - }), - [yPosition] - ); - - const transform = useComputedValue( - () => [ - { - translateY: yPosition.current, - }, - ], - [yPosition] - ); - - useEffect(() => { - changeItemPosition(); - }, [changeItemPosition]); +export interface StarsProps extends Omit {} +function Stars(props: StarsProps) { return ( - - - {starsToRenderArray.map((_, index) => ( - - ))} - - + ( + + )} + {...props} + /> ); } -const styles = StyleSheet.create({ - canvas: { - position: 'absolute', - top: 0, - left: 0, - right: 0, - bottom: 0, - zIndex: -1, - }, -}); - export default memo(Stars);