@@ -32,6 +32,7 @@ https://github.com/user-attachments/assets/57f56b3f-3988-4235-af83-a5f2cfd82121
3232- Nested fragments merge into a single native text view
3333- Rendering Markdown and HTML (coming soon).
3434- Supports only the New Architecture
35+ - Animations with React Native Reanimated (text, fontSize, fontColor, letterSpacing)
3536
3637## Requirements
3738
@@ -139,6 +140,134 @@ export function MenuExample() {
139140}
140141```
141142
143+ ## Animations with React Native Reanimated
144+
145+ NitroText supports animating text properties using React Native Reanimated. Animations run directly on the UI thread for smooth, performant updates even when the JavaScript thread is busy.
146+
147+ ### Setup
148+
149+ First, install the required dependencies:
150+
151+ ``` bash
152+ yarn add react-native-reanimated react-native-worklets
153+ ```
154+
155+ Then, configure Babel to use the worklets plugin. Add it to your ` babel.config.js ` :
156+
157+ ``` js
158+ module .exports = {
159+ presets: [' module:@react-native/babel-preset' ],
160+ plugins: [
161+ // ... other plugins
162+ ' react-native-worklets/plugin' ,
163+ ],
164+ };
165+ ```
166+
167+ ### Supported Animated Props
168+
169+ The following props can be animated:
170+ - ` text ` - Animate the text content
171+ - ` fontSize ` - Animate font size
172+ - ` fontColor ` - Animate text color (as hex string, e.g., ` "#FF0000" ` )
173+ - ` letterSpacing ` - Animate letter spacing
174+
175+ ### Basic Example
176+
177+ Animate text content using ` animatedProps ` :
178+
179+ ``` tsx
180+ import { NitroText } from ' react-native-nitro-text'
181+ import Animated , { useAnimatedProps , useSharedValue , withTiming } from ' react-native-reanimated'
182+ import { useEffect } from ' react'
183+
184+ const AnimatedNitroText = Animated .createAnimatedComponent (NitroText )
185+
186+ export function AnimatedTextExample() {
187+ const progress = useSharedValue (0 )
188+
189+ useEffect (() => {
190+ progress .value = withTiming (1 , { duration: 1000 })
191+ }, [])
192+
193+ const animatedProps = useAnimatedProps (() => ({
194+ text: ` Progress: ${Math .round (progress .value * 100 )}% ` ,
195+ }))
196+
197+ return (
198+ <AnimatedNitroText
199+ animatedProps = { animatedProps }
200+ style = { { fontSize: 24 , fontWeight: ' bold' }}
201+ />
202+ )
203+ }
204+ ```
205+
206+ ### Advanced Example
207+
208+ Animate multiple properties simultaneously:
209+
210+ ``` tsx
211+ import { NitroText } from ' react-native-nitro-text'
212+ import Animated , {
213+ useAnimatedProps ,
214+ useSharedValue ,
215+ withRepeat ,
216+ withTiming ,
217+ Easing
218+ } from ' react-native-reanimated'
219+ import { useEffect } from ' react'
220+
221+ const AnimatedNitroText = Animated .createAnimatedComponent (NitroText )
222+
223+ export function AdvancedAnimationExample() {
224+ const scale = useSharedValue (1 )
225+ const color = useSharedValue (0 )
226+
227+ useEffect (() => {
228+ scale .value = withRepeat (
229+ withTiming (1.2 , { duration: 1000 , easing: Easing .inOut (Easing .ease ) }),
230+ - 1 ,
231+ true
232+ )
233+
234+ color .value = withRepeat (
235+ withTiming (1 , { duration: 2000 , easing: Easing .linear }),
236+ - 1 ,
237+ false
238+ )
239+ }, [])
240+
241+ const animatedProps = useAnimatedProps (() => {
242+ const fontSize = 16 + (scale .value - 1 ) * 8
243+ const hue = Math .round (color .value * 360 )
244+
245+ return {
246+ fontSize ,
247+ fontColor: ` hsl(${hue }, 70%, 50%) ` ,
248+ } as any
249+ })
250+
251+ return (
252+ <AnimatedNitroText
253+ animatedProps = { animatedProps }
254+ style = { { fontWeight: ' 600' }}
255+ >
256+ Animated Text
257+ </AnimatedNitroText >
258+ )
259+ }
260+ ```
261+
262+ ### Performance Benefits
263+
264+ Since animations run on the UI thread, NitroText animations remain smooth even when:
265+ - The JavaScript thread is blocked
266+ - Heavy computations are running
267+ - The app is processing large amounts of data
268+
269+ This makes NitroText ideal for real-time text updates, counters, and dynamic content that needs to stay responsive.
270+
142271## Platform Support
143272
144273- iOS
0 commit comments