diff --git a/docs/docs/components/stars.mdx b/docs/docs/components/stars.mdx index 8436990..c0c3992 100644 --- a/docs/docs/components/stars.mdx +++ b/docs/docs/components/stars.mdx @@ -44,6 +44,7 @@ You can also use a single star. Notice that you need to wrap the star with a `Ca | x | `number` | Initial x position of the star. | | y | `number` | Initial y position of the star. | | autoplay? | `boolean` | Whether the star should animate automatically or not (default is `true`). | +| color? | `boolean` | Star color (default is `rgba(255, 255, 0, 1)`). | ```js import { StyleSheet } from 'react-native'; diff --git a/example/src/App.tsx b/example/src/App.tsx index 3b2b92d..1925ace 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -74,7 +74,13 @@ function App() { setComponentToRender()} + onPress={() => + setComponentToRender( + + ) + } style={styles.pressable} > diff --git a/src/components/Star.tsx b/src/components/Star.tsx index 458d124..6aefa3b 100644 --- a/src/components/Star.tsx +++ b/src/components/Star.tsx @@ -7,9 +7,10 @@ export interface StarProps { x: number; y: number; autoplay?: boolean; + color?: string; } -function Star({ x, y, autoplay = true }: StarProps) { +function Star({ x, y, autoplay = true, color = palette.yellow }: StarProps) { const opacity = useValue(1); const changeOpacity = useCallback( @@ -30,7 +31,7 @@ function Star({ x, y, autoplay = true }: StarProps) { diff --git a/src/components/Stars.tsx b/src/components/Stars.tsx index 6935dbb..23a6bc9 100644 --- a/src/components/Stars.tsx +++ b/src/components/Stars.tsx @@ -1,4 +1,4 @@ -import React, { memo, useCallback, useEffect } from 'react'; +import React, { memo, useCallback, useEffect, useMemo } from 'react'; import { StyleSheet } from 'react-native'; import { Canvas, @@ -11,13 +11,24 @@ import { screenHeight } from '../constants/dimensions'; import { screenWidth } from '../constants/dimensions'; import Star from './Star'; import { shuffleArray } from '../utils/array'; +import { FiestaThemes } from '../constants/theming'; +import { colorsFromTheme } from '../utils/colors'; const xGap = 40; const optimalNumberOfStars = Math.floor(screenWidth / xGap); const starsToRenderArray = [...Array(optimalNumberOfStars)]; const yPositions = shuffleArray(starsToRenderArray.map((_, i) => i * xGap)); -function Stars() { +interface StarsProps { + theme?: string[]; +} + +function Stars({ theme = FiestaThemes.default }: StarsProps) { + const colors = useMemo( + () => colorsFromTheme(theme, optimalNumberOfStars), + [theme] + ); + const yPosition = useValue(screenHeight); const changeItemPosition = useCallback( @@ -45,7 +56,12 @@ function Stars() { {starsToRenderArray.map((_, index) => ( - + ))}