Skip to content

[PoC] feat: support for animating text inside Animated.Text#8595

Draft
tomekzaw wants to merge 69 commits intomainfrom
@tomekzaw/animated-text
Draft

[PoC] feat: support for animating text inside Animated.Text#8595
tomekzaw wants to merge 69 commits intomainfrom
@tomekzaw/animated-text

Conversation

@tomekzaw
Copy link
Member

@tomekzaw tomekzaw commented Nov 13, 2025

Summary

Work in progress.

Fixes the issue with cropped TextInput and visible ellipsis.

TODO: update docs https://docs.swmansion.com/react-native-reanimated/docs/guides/performance/#-animate-textinput-instead-of-re-rendering-text-component

Test plan

@tomekzaw tomekzaw force-pushed the @tomekzaw/animated-text branch from 7270154 to 485fd5a Compare November 17, 2025 09:42
@RodolfoSilva
Copy link
Contributor

What will be the right way to sync the animation shared value with React state?

Should we use a useDerivedValue based on the React state, or do we need a useEffect to handle the changes?
(In other words, should we use useEffect or useLayoutEffect to sync React state with a shared value?)

I mean, this is the most common scenario when using this pattern for example, when receiving a number from an API to animate the text.

@tomekzaw
Copy link
Member Author

tomekzaw commented Dec 6, 2025

@RodolfoSilva I think the best way to go is to do it like this:

const myValueFromAPI = useValueFromAPI();

const sv = useSharedValue<number>(myValueFromAPI);

useEffect(() => {
  sv.value = withTiming(myValueFromAPI);
}, [myValueFromAPI]);

const textSv = useDerivedValue(() => {
  return sv.value.toFixed(2);
});

return <Animated.Text text={textSv} />;

@novatech
Copy link

novatech commented Dec 22, 2025

how much % to completion this is? i'm been testing this feature for my implementation by patching the library.
so far it works well, except i need to be careful not to pass undefined/null sharedValue to <Animated.Text> otherwise it will crash at following line when there is an update

5 XXXMobile-UAT.debug.dylib 0x1078f1c60 reanimated::AnimatedPropsRegistry::update(facebook::jsi::Runtime&, facebook::jsi::Value const&, double) + 724 (AnimatedPropsRegistry.cpp:34)
following the comment above, this is how i use it,

// useSingleValueFromRedux is just a hook to useSelector
const value = useSingleValueFromRedux({
  key: key,
  field: sseField,
});
const textSv = useSharedValue(value ?? '--');

useEffect(() => {
  textSv.value = value ?? '--';
}, [textSv, value]);

return <Animated.Text text={textSv} />;

@tomekzaw
Copy link
Member Author

tomekzaw commented Dec 22, 2025

@novatech Thanks for the feedback! There's one thing that needs to be fixed prior to merging – the incorrect behavior of <Animated.Text text={sv} /> during a re-render (after which the component is blank). We'd like to ship this PR in 4.3.0 most likely some time in January 2026.

@WadhahEssam
Copy link

Would love from this to be merged this month, that would make our lives easier as react native 82 in android dropped the support of extending internal classes and now our package 'react-native-animateable-text' is very hard to implement in android

axelra-ag/react-native-animateable-text#76

so if this is merged soon, we will direct our users to use this solution instead.

@mateuszmazurek
Copy link

@tomekzaw 🙏

@tomekzaw
Copy link
Member Author

tomekzaw commented Feb 8, 2026

Bug 1: <Animated.Text text={textSv} /> doesn't work at all.

Screen.Recording.2026-02-08.at.19.37.55.mov

Note: I was able to fix it (only for between the first and second render) by passing true as isAnimatedProps in InlinePropManager.ts:

        const updaterFunction = () => {
         'worklet';
         const update = getInlinePropsUpdate(newInlineProps);
-        updateProps(shareableViewDescriptors, update);
+        updateProps(shareableViewDescriptors, update, true);
       };

@tomekzaw
Copy link
Member Author

tomekzaw commented Feb 8, 2026

Bug 2: <Animated.Text animatedProps={stringAnimatedProps} /> is stuck with empty text content after commenting out and restoring animatedProps argument using fast refresh (hot reload).

Screen.Recording.2026-02-08.at.19.41.23.mov

Actually, all animated texts are broken in such scenario:

Screenshot 2026-02-08 at 19 43 16

Edit: It looks like this is a general regression of useAnimatedProps, unrelated to this specific PR.

@novatech
Copy link

novatech commented Mar 12, 2026

is this coming into next release anytime soon? 🙏

github-merge-queue bot pushed a commit that referenced this pull request Mar 18, 2026
## Summary

This PR mentions
#8595 in
the docs as well as adds info about SwiftUI numeric transitions.

## Test plan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants