Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/axelra-ag/react-native-animateable-text
🆎 A fork of React Native's <Text/> component that supports Reanimated Shared Values as text!
https://github.com/axelra-ag/react-native-animateable-text
react-native reanimated reanimated2 text
Last synced: 3 days ago
JSON representation
🆎 A fork of React Native's <Text/> component that supports Reanimated Shared Values as text!
- Host: GitHub
- URL: https://github.com/axelra-ag/react-native-animateable-text
- Owner: axelra-ag
- License: mit
- Created: 2020-09-13T19:44:23.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-11-06T19:14:55.000Z (about 2 months ago)
- Last Synced: 2024-12-21T00:41:05.658Z (3 days ago)
- Topics: react-native, reanimated, reanimated2, text
- Language: C++
- Homepage: https://www.npmjs.com/package/react-native-animateable-text
- Size: 3.79 MB
- Stars: 389
- Watchers: 4
- Forks: 27
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# react-native-animateable-text
A fork of React Native's `` component that supports Reanimated Shared Values as text!
## Compatibility
(🚨 Make sure you use the correct version for your RN project)
Animateable Text Version
RN Version
Old Arch
New Arch (Fabric)
^0.14.2
^0.76.0
✅
✅
^0.13.0
^0.75.0
✅
🛑
^0.12.0
^0.74.0
✅
🛑
^0.11.0
^0.71.7
✅
🛑
^0.10.0
^0.68
✅
🛑
^0.9.1
^0.67
✅
🛑
^0.8.0
^0.66
✅
🛑
^0.7.0
^0.65
✅
🛑
^0.6.0
^0.64
✅
🛑
^0.5.9
^0.63
✅
🛑
## Installation
First make sure you have reanimated already installed and linked from [here](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started/) then run
```sh
yarn add react-native-animateable-text
```then for *Expo* managed projects you need to prebuild your project, and for *ReactNative* bare projects you should run
```sh
npx pod-install
```## Usage (Reanimated 2/3)
> Note about Reanimated 2: The library does not work with Alpha 9 until RC1. Make sure to update to RC2 or later!
Use it the same as a `` component, except instead of passing the text as a child node, pass it using the `text` props.
```tsx
import AnimateableText from 'react-native-animateable-text';const Example: React.FC = () => {
const reanimatedText = useSharedValue('World');const animatedProps = useAnimatedProps(() => {
return {
text: reanimatedText.value,
};
});return (
props are also available
/>;
};
```## [OMG, why would you build this?](https://www.npmjs.com/package/react-native-reanimated/v/1.4.0#omg-why-would-you-build-this-motivation)
We want to animate numbers based on gestures as fast as possible, for example for charts displaying financial data. Updating native state is too slow and not feasible for a smooth experience. Using `createAnimatedComponent` doesn't allow you to animate the text since the children of Text are separate nodes rather than just props.
The best way so far has been to use the `` component from [react-native-redash](https://wcandillon.github.io/react-native-redash-v1-docs/strings#retext), which allows you to render a string from a Reanimated Text node. However, under the hood, it uses a `` and animates it's `value` prop.
This naturally comes with a few edge cases, for example:
-
*Flicker*: When changing values too fast, the text can be cut off and show an ellipsis. The problem gets worse the slower the device and the more congested the render queue is. Watch this GIF at 0.2x speed carefully:
-
*Inconsistent styling*: When styling aTextInput
, you need to add more styles and spacing to make it align with the defaultText
styles. (Behavior in screenshot happens only on Android) -
*Lack of full capabilities*: Not all props are available. With Animateable Text, you can use props that you cannot use on a TextInput, such asselectable
(Android),dataDetectorType
oronTextLayout
.
## Contributing
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
## Credits
Written by [Jonny Burger](https://jonny.io) for our needs at [Axelra](https://axelra.com).
Thanks to Axelra for sponsoring my time to turn this into an open source project!
We are a Swiss Agency specializing in React Native, caring even about the smallest of details.
## License
MIT