Компоненты/Орбита-лоадер

Орбита-лоадер

31 января 2025

Пульсирующий центр и точки вокруг него

Установка

npx astra-rn add orbiting-dots
pnpm dlx astra-rn add orbiting-dots
yarn dlx astra-rn add orbiting-dots
bunx --bun astra-rn add orbiting-dots

Файлы

index.tsx
НазадВырез-менюДалееВвод OTP

Вручную

Поставьте зависимости:

npm install react-native-reanimated react-native-svg
pnpm add react-native-reanimated react-native-svg
yarn add react-native-reanimated react-native-svg
bun add react-native-reanimated react-native-svg

Скопируйте эти файлы в src/shared/components/molecules/orbiting-dots/:

Проверьте алиас путей. Импорты в коде выше записаны так, как их пишет astra-rn add: @/shared/components, @/shared/utils и @/shared/hooks. Нужен алиас "@/*": ["./src/*"] в tsconfig.json — или поправьте импорты под свои пути.

Использование

import { View, StyleSheet } from "react-native";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { StatusBar } from "expo-status-bar";
import { OrbitDotLoader } from "@/shared/components/molecules/orbiting-dots";
import { Showcase, useCustomize } from "~/showcase";

const DOT_COLOR_HEX = "#ffffff";
const DOT_COLOR = "#fff";

const CUSTOMIZE = [
  { key: "color", label: "Цвет точек", type: "color", default: DOT_COLOR_HEX },
  { key: "numDots", label: "Количество", type: "slider", min: 1, max: 8, step: 1, default: 3 },
  { key: "size", label: "Размер", type: "slider", min: 24, max: 120, step: 2, unit: "px", default: 72 },
  { key: "dotRadius", label: "Радиус точек", type: "slider", min: 1, max: 12, step: 0.5, unit: "px", default: 6 },
  { key: "centerRadius", label: "Радиус центра", type: "slider", min: 0, max: 16, step: 0.5, unit: "px", default: 8 },
  { key: "duration", label: "Оборот", type: "slider", min: 300, max: 3000, step: 50, unit: "ms", default: 900 },
] as const;

export default function App() {
  const custom = useCustomize(CUSTOMIZE);

  return (
    <Showcase>
      <GestureHandlerRootView style={styles.container}>
        <StatusBar style="light" />

        <View style={styles.content}>
          <OrbitDotLoader
            numDots={custom.numDots}
            size={custom.size}
            dotColor={custom.color === DOT_COLOR_HEX ? DOT_COLOR : custom.color}
            dotRadius={custom.dotRadius}
            centerRadius={custom.centerRadius}
            duration={custom.duration}
          />
        </View>
      </GestureHandlerRootView>
    </Showcase>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#0a0a0a",
    justifyContent: "center",
    alignItems: "center",
  },
  content: {},
});

Пропсы

Пропс
Описание
dotColor?

Тип string

dotRadius?

Тип number

centerRadius?

Тип number

size?

Тип number

duration?

Тип number

numDots?

Тип number

style?

Тип StyleProp<ViewStyle>