RN Animated Components
Components

AnimatedNumber

An animated number display with smooth transitions for both digits and separators

Features

  • Smoothly animates number updates with layout transitions
  • Animated comma or dot separators between every 3 digits
  • Supports two animation strategies: "translate" and "swap"
  • Supports customizable animation configs: "timing" and "spring"

Dependencies

This component requires React Native Reanimated:

npx expo install react-native-reanimated

Usage

This component is self-contained and can be used by simply copying the file.

Steps

  1. Copy and paste the AnimatedNumber.tsx file into your project

  2. Use it inside your component:

    import AnimatedNumber from "./AnimatedNumber"
    import { TextInput, View } from "react-native"
    import { useRef, useState } from "react"
    
    export default function App() {
      const [number, setNumber] = useState("")
      const inputRef = useRef(null)
    
      return (
        <View style={styles.container}>
          <AnimatedNumber
            number={number}
            textStyle={styles.text}
            containerStyle={{ width: "100%", justifyContent: "center" }}
            separatorAnimation="swap"
            separator="comma"
            animationConfig={{
              type: "spring",
              damping: 20,
              stiffness: 120
            }}
          />
          <TextInput
            ref={inputRef}
            autoFocus
            style={{ width: "100%", height: 0, backgroundColor: "transparent", position: "absolute", bottom: 0 }}
            onChangeText={setNumber}
            keyboardType="numeric"
          />
        </View>
      )
    }

Props

PropTypeDefault
number
string
-
separator?
"comma" | "dot"
"comma"
separatorAnimation?
"swap" | "translate"
"swap"
textStyle?
TextStyle
-
containerStyle?
ViewStyle
-
animationConfig?
AnimationConfigs
{ type: "timing", duration: 300 }
prefix?
string
-
suffix?
string
-

AnimationConfig

AnimationConfig can be one of two types. The type field determines which fields are applicable.

TimingOptions

PropTypeDefault
type
"timing"
-
duration?
number
300
easing?
EasingFunction
-

SpringOptions

PropTypeDefault
type
"spring"
-
damping?
number
20
mass?
number
1
stiffness?
number
100
overshootClamp?
boolean
false

For "timing" type, duration is exact. For "spring" type, duration is physics-based.
If you need exact sync with other animations, use "timing" or calculate an approximate spring duration.

Examples

// timing
animationConfig={{
  type: "timing",
  duration: 400,
  easing: Easing.out(Easing.exp)
}}

// spring
animationConfig={{
  type: "spring",
  damping: 20,
  stiffness: 120,
  overshootClamp: false
}}

Made with love by niche.guys
Let the numbers flow beautifully.