Компоненты/Текст по кругу

Текст по кругу

31 января 2025

Текст непрерывно вращается вокруг центра

Установка

npx astra-rn add circular-text
pnpm dlx astra-rn add circular-text
yarn dlx astra-rn add circular-text
bunx --bun astra-rn add circular-text

Файлы

index.tsx
НазадКинотитрыДалееСтрока по дуге

Вручную

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

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

Скопируйте эти файлы в src/shared/components/organisms/circular-text/:

Проверьте алиас путей. Импорты в коде выше записаны так, как их пишет 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 { CircularText } from "@/shared/components/organisms/circular-text";
import type { TPressEffect } from "@/shared/components/organisms/circular-text/types";
import { useFonts } from "expo-font";
import { Showcase, useCustomize } from "~/showcase";

const CUSTOMIZE = [
  { key: "text", label: "Текст", type: "text", default: " ✦ ⋆ ASTRA IS ✦ ⋆ AWESOME", maxLength: 60 },
  { key: "spinDuration", label: "Оборот", type: "slider", min: 2, max: 60, step: 1, unit: "s", default: 20 },
  { key: "pressEffect", label: "При нажатии", type: "select", options: [{ value: "accelerate", label: "Ускорить" }, { value: "slowDown", label: "Замедлить" }, { value: "pause", label: "Пауза" }], default: "accelerate" },
  { key: "radius", label: "Радиус", type: "slider", min: 40, max: 160, step: 1, unit: "px", default: 85 },
  { key: "fontSize", label: "Размер шрифта", type: "slider", min: 10, max: 48, step: 1, unit: "px", default: 24 },
  { key: "color", label: "Цвет текста", type: "color", default: "#ffffff" },
  { key: "background", label: "Фон", type: "color", default: "#0a0a0a" },
] as const;
export default function App() {
  const [fontLoaded] = useFonts({
    SfProRounded: require("@/assets/fonts/sf-pro-rounded.ttf"),
    HelveticaNowDisplay: require("@/assets/fonts/HelveticaNowDisplayMedium.ttf"),
    Coolvetica: require("@/assets/fonts/Coolvetica-Rg.otf"),
  });
  const custom = useCustomize(CUSTOMIZE);

  return (
    <Showcase>
      <GestureHandlerRootView
        style={[styles.container, { backgroundColor: custom.background }]}
      >
        <StatusBar style="light" />
        <View>
          <CircularText
            text={custom.text}
            pressEffect={custom.pressEffect as TPressEffect}
            spinDuration={custom.spinDuration}
            radius={custom.radius}
            fontSize={custom.fontSize}
            color={custom.color}
          />
        </View>
      </GestureHandlerRootView>
    </Showcase>
  );
}

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

Пропсы

Пропс
Описание
text

Тип string

spinDuration?

Тип number

pressEffect?

Тип TPressEffect

radius?

Тип number

fontSize?

Тип number

color?

Тип string

style?

Тип StyleProp<ViewStyle>

textStyle?

Тип StyleProp<TextStyle>