Text
Themed RN Text (Animated.Text, inline flow preserved) with variant + size and staggered entering/exiting motion.
Install
First install? Set up the registry in your app.
npx --yes --package=https://native.uipkge.dev/cli/uipkge-native-0.1.1.tgz uipkge-native add textSource files
Expand a file to read the source the installer copies into your app.
components/ui/text/Text.tsx
import * as React from 'react'
import { Platform, type TextProps as RNTextProps } from 'react-native'
import Animated, { useReducedMotion } from 'react-native-reanimated'
import { cssInterop } from 'react-native-css-interop'
import { cn } from '@/lib/utils'
import { enterFor, exitFor, type EnterPreset, type ExitPreset } from '@/lib/motion'
cssInterop(Animated.Text, { className: 'style' })
export type TextVariant = 'default' | 'muted' | 'secondary'
export type TextSize = 'xs' | 'sm' | 'default' | 'lg' | 'xl' | 'title'
export interface TextProps extends RNTextProps {
className?: string
variant?: TextVariant
size?: TextSize
/** Mount entrance with optional stagger delay. Uses Animated.Text so inline flow is preserved. */
enter?: EnterPreset
enterDelay?: number
/** Unmount exit with optional delay. */
exit?: ExitPreset
exitDelay?: number
}
const variantClasses: Record<TextVariant, string> = {
default: 'text-foreground',
muted: 'text-muted-foreground',
secondary: 'text-secondary-foreground',
}
const sizeClasses: Record<TextSize, string> = {
xs: 'text-[13px] leading-[18px]',
sm: 'text-[15px] leading-[21px]',
default: Platform.OS === 'ios' ? 'text-[17px] leading-[22px]' : 'text-[16px] leading-[24px]',
lg: 'text-[18px] leading-[28px]',
xl: 'text-[20px] font-semibold leading-[28px]',
title: 'text-[24px] font-bold leading-[32px]',
}
const Text = React.forwardRef<React.ComponentRef<typeof Animated.Text>, TextProps>(
(
{
className,
variant = 'default',
size = 'default',
enter = 'none',
enterDelay,
exit = 'none',
exitDelay,
...props
},
ref,
) => {
const reduced = useReducedMotion()
return (
<Animated.Text
ref={ref}
entering={reduced ? undefined : enterFor(enter, { delay: enterDelay })}
exiting={reduced ? undefined : exitFor(exit, { delay: exitDelay })}
className={cn(variantClasses[variant], sizeClasses[size], className)}
{...props}
/>
)
},
)
Text.displayName = 'Text'
export { Text }
components/ui/text/index.ts
export { Text, type TextProps, type TextSize, type TextVariant } from './Text'
Dependencies
Registry items
npm packages
react-native-reanimatedreact-native-css-interop