Skip to content
项目

axelra-ag/react-native-animateable-text

在 GitHub 查看

关于

🆎 React Native <Text/> 组件的一个分支,可将 Reanimated Shared Values 作为文本使用!

网站与应用开发

这些数字如何统计

实测星标增长

24小时
0
7天
+1
15天
+1
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

react-native-animateable-text

A fork of React Native's <Text/> 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.19.3 ^0.85.3 🛑 ✅
^0.19.2 ^0.86.0 🛑 ✅
^0.18.1 ^0.83.2 🛑 ✅
^0.17.1 ^0.81.5 ✅ ✅
^0.16.0 ^0.79.0 ✅ ✅
^0.15.0 ^0.77.0 ✅ ✅
^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 then run

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

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 <Text/> component, except instead of passing the text as a child node, pass it using the text props.

import AnimateableText from 'react-native-animateable-text';

const Example: React.FC = () => {
  const reanimatedText = useSharedValue('World');

  const animatedProps = useAnimatedProps(() => {
    return {
      text: reanimatedText.value,
    };
  });

  return (
    <AnimateableText
      animatedProps={animatedProps}
      // all other <Text /> props are also available
    />;
};

OMG, why would you build this?

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 <ReText> component from react-native-redash, which allows you to render a string from a Reanimated Text node. However, under the hood, it uses a <TextInput/> 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 a TextInput, you need to add more styles and spacing to make it align with the default Text 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 as selectable (Android), dataDetectorType or onTextLayout.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

Credits

Written by Jonny Burger for our needs at Axelra.

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

探索相关项目

加载中…