react-native-reanimated: useAnimatedProps with svg not working

Description

following the example here directly, the code is erroring in our project with TypeError: Cannot read properties of undefined (reading 'setAttribute')

it’s occurring here in react-native-reanimated/lib/reanimated2/js-reanimated/index.js:

  if (typeof component.setNativeProps === 'function') {
      setNativeProps(component, rawStyles);
    } else if (Object.keys(component.props).length > 0) {
      Object.keys(component.props).forEach((key) => {
        if (!rawStyles[key]) {
          return;
        }
        const dashedKey = key.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase());
        component._touchableNode.setAttribute(dashedKey, rawStyles[key]);
      });

Expected behavior

the example outlined in the docs should work

Actual behavior & steps to reproduce

errors with cannot read property “setAttribute” of undefined

Snack or minimal code example

see the docs - we’ve copied the code there exactly

Package versions

name version
react-native 0.68
react-native-reanimated 2.8.0
NodeJS 16.15.0
expo 45

Affected platforms

  • Android
  • iOS
  • Web

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 7
  • Comments: 18 (2 by maintainers)

Commits related to this issue

Most upvoted comments

I found workaround for this bug. Just set empty function for onPress prop of component you want to animate like this:

<AnimatedCircle
  cx="50%"
  cy="50%"
  r="5"
  animatedProps={circleProps}
  onPress={() => {}}
/>

I guess this is because _touchableNode(which is referenced in this line) for the svg component is only added when touchable related props exist(related line in react-native-svg).

Can you check if applying https://github.com/software-mansion/react-native-svg/pull/1886 to react-native-svg fixes the issue?