import { useEffect, useState } from 'react'; import { Dimensions, SafeAreaView, ScrollView, StyleSheet, Text, TouchableOpacity, View, } from 'react-native'; import { BUILTIN_INDICATOR_NAMES, LoaderKitProgress, LoaderKitView, defineIndicator, param, type BuiltinIndicatorName, } from 'react-native-loader-kit'; const { width: screenWidth } = Dimensions.get('window'); const Blink = defineIndicator({ name: 'Blink', duration: 0.9, params: { count: 4, low: 0.15 }, layout: { type: 'row', count: param('count'), gap: 0.08 }, shape: { type: 'rect', cornerRadius: 0.25 }, stagger: { each: 0.15 }, tracks: [ { property: 'opacity', keyTimes: [0, 0.5, 1], values: [1, param('low'), 1], easing: 'easeInOut', }, { property: 'scaleY', keyTimes: [0, 0.5, 1], values: [1, 0.5, 1], easing: 'easeInOut', }, ], }); const displayName = (name: string) => name.replace(/([A-Z])/g, ' $1').trim(); /** Progress of a fake download: uneven steps, then a pause before it starts again. */ function useDownload(running: boolean) { const [value, setValue] = useState(0); useEffect(() => { if (!running) return; const timer = setInterval(() => { setValue((v) => (v >= 1 ? 0 : Math.min(1, v + Math.random() * 0.12))); }, 400); return () => clearInterval(timer); }, [running]); return value; } function Button({ label, onPress }: { label: string; onPress: () => void }) { return ( {label} ); } export default function App() { const [speed, setSpeed] = useState(1); const [animating, setAnimating] = useState(true); const [cycleProgress, setCycleProgress] = useState( undefined ); const [multicolor, setMulticolor] = useState(false); const [count, setCount] = useState(4); const [indeterminate, setIndeterminate] = useState(false); const download = useDownload(!indeterminate); const progressValue = indeterminate ? null : download; const columns = 3; const spacing = 10; const itemWidth = (screenWidth - spacing * (columns + 1)) / columns; const common = { speed, animating, cycleProgress, color: 'white', colors: multicolor ? ['#ffce54', '#a0d468', '#4fc1e9'] : undefined, style: styles.indicator, }; const renderBuiltin = (name: BuiltinIndicatorName, index: number) => ( {index + 1}. {displayName(name)} ); return ( Speed {speed.toFixed(1)}x