React-native-reanimated: TextInput's value stopped updating with animatedProps after upgrade to alpha.9

Created on 17 Nov 2020  路  3Comments  路  Source: software-mansion/react-native-reanimated

Description

I used to change texts without rerendering the component using the following code. It works in alpha.8, but after upgrading to alpha.9 it stopped working. Shared value is changing, but the TextInput showing the same 'Initial text'.
I tried to play with different props (children, value, text) and components (Text, TextInput), but without any results.

How can I tweak the code to make it work? Or is there another way to do the job?
Thanks

Code

import React from 'react';
import { View, TextInput, Button } from 'react-native';
import Animated, { useAnimatedProps, useSharedValue } from 'react-native-reanimated';
const AnimatedText = Animated.createAnimatedComponent(TextInput);

const App = () => {
    const sharedText = useSharedValue('Initial text');
    const textAnimatedProps = useAnimatedProps(() => {
        return { text: sharedText.value };
    });
    let numPresses = 0;
    const onButtonPress = () => {
        console.log(sharedText.value);
        numPresses++;
        sharedText.value = `Pressed ${numPresses} times`;
    };
    return (
        <View style={{flex: 1, alignItems: 'center', justifyContent: 'center' }}>
            <AnimatedText editable={false} value={sharedText.value} animatedProps={textAnimatedProps} />
            <Button title="Button" onPress={onButtonPress} />
        </View>
    );
};
export default App;

AnimatedTextScreenshot

Package versions

  • React: 16.13.1
  • React Native: 0.63.3
  • React Native Reanimated: 2.0.0-alpha.9
鉂換uestion 馃彔 Reanimated2

All 3 comments

I think some of the internal configurations were updated so now you will need to explicitly add text to the whitelisted native props.

Animated.addWhitelistedNativeProps({ text: true });

Then it will work

Then it will work

It certainly did work. Thank you

Here's the PR changing this behavior for context: #1409.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

robertgonzales picture robertgonzales  路  3Comments

WeTruck picture WeTruck  路  3Comments

sa8ab picture sa8ab  路  3Comments

alexfov picture alexfov  路  3Comments

jwhscholten picture jwhscholten  路  4Comments