import { ReactElement, useId } from "react"; import { ColorValue, View } from "react-native"; import Animated from "react-native-reanimated"; import Svg, { Defs, G, LinearGradient, Path, Stop } from "react-native-svg"; import { useIOTheme } from "../../context"; import { IOColors } from "../../core/IOColors"; import { WithTestID } from "../../utils/types"; export type LoadingSpinner = WithTestID<{ color?: ColorValue; size?: IOLoadingSpinnerSizeScale; durationMs?: number; accessibilityLabel?: string; accessibilityHint?: string; }>; /** * Size scale */ export type IOLoadingSpinnerSizeScale = 24 | 48; const spinKeyframes = { from: { transform: [{ rotateZ: "0deg" }] }, to: { transform: [{ rotateZ: "360deg" }] } }; const strokeMap: Record = { 24: 3, 48: 5 }; export const LoadingSpinner = ({ color: customColor, size = 24, durationMs = 850, accessibilityHint, accessibilityLabel, testID = "LoadingSpinnerTestID" }: LoadingSpinner): ReactElement => { const theme = useIOTheme(); const id = useId(); const stroke = strokeMap[size]; const color = customColor ?? IOColors[theme["interactiveElem-default"]]; const secondHalfId = `${id}-secondHalf`; const firstHalfId = `${id}-firstHalf`; return ( {/* Thanks to Ben Ilegbodu for the article on how to create a a SVG gradient loading spinner. Below is a parameterized version of his code. Source: https://www.benmvp.com/blog/how-to-create-circle-svg-gradient-loading-spinner/ */} ); };