react-native-reanimated icon indicating copy to clipboard operation
react-native-reanimated copied to clipboard

useAnimatedProps with svg not working

Open louisholley opened this issue 2 years ago • 5 comments

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
  • [x] Web

louisholley avatar Jun 24 '22 15:06 louisholley

Any update on this? Anyone know if there is an older version I can revert to that works?

tannersatch avatar Aug 23 '22 18:08 tannersatch

Hey! 👋

The issue doesn't seem to contain a minimal reproduction.

Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?

github-actions[bot] avatar Aug 23 '22 18:08 github-actions[bot]

Same issue

tgreco avatar Sep 03 '22 18:09 tgreco

Same for me, ios [email protected]

can be tested on this example: Circular Progress Bar https://github.com/enzomanuelmangano/animate-with-reanimated/blob/main/08-circular-progress-bar/App.tsx

Frit avatar Sep 04 '22 15:09 Frit

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).

wjaykim avatar Sep 24 '22 14:09 wjaykim

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

WoLewicki avatar Oct 14 '22 09:10 WoLewicki

react-native-svg v 13.5.0 worked for me in the web using useAnmatedProps But it still throws some error only in the console Error: attribute transform: Expected transform function, "undefined".

saeedblanchette avatar Feb 10 '23 16:02 saeedblanchette

I'm experiencing this issue when running Jest tests with react-native-svg 12.5.1 and react-native-reanimated 2.14.4. Adding an onPress handler didn't fix the issue for me unfortunately.

soulfresh avatar Feb 22 '23 21:02 soulfresh

This is happening to. me to. have the version react-native-reanimated 3.0.2 react-native-svg 13.8.0. Any news on how. to fix this. It is reproducable with. this https://github.com/enzomanuelmangano/animate-with-reanimated/blob/main/08-circular-progress-bar/App.tsx

@saeedblanchette @soulfresh Were you able to fix this somehow?

acollazomayer avatar Mar 14 '23 13:03 acollazomayer

I also have the same problem with these rnreanimated and rnsvg libs versions

Isrrr avatar Mar 14 '23 13:03 Isrrr

@Isrrr did you found a fix?

acollazomayer avatar Mar 20 '23 18:03 acollazomayer

I've created a repository that replicates the issue that I am having hope this helps. https://github.com/acollazomayer/ReanimatedSVGBug

acollazomayer avatar Mar 20 '23 20:03 acollazomayer

I found a 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).

I just used a workaround and I did work for @acollazomayer

saeedblanchette avatar Mar 25 '23 16:03 saeedblanchette

Hey! 👋

The issue doesn't seem to contain a minimal reproduction.

Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?

github-actions[bot] avatar Mar 25 '23 16:03 github-actions[bot]

@Isrrr did you found a fix?

Nope

Isrrr avatar Mar 25 '23 16:03 Isrrr

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).

This works but I get a lot of warnings as errors for all touch related props in the console titled Warning: Unknown event handler property onStartShouldSetResponder. It will be ignored. at circle

Any workaround for the errors? or Proper fix?

geetesh-gupta avatar Apr 01 '23 17:04 geetesh-gupta

I had the problem with the setAttribute error on web on react-native-svg: 13.4.0. Updating to 13.9.0 fixed it for me.

Now it works but i have a bunch of errors in the console for: Error: <circle> attribute transform: Expected transform function, "undefined".

My react-native-reanimated version is: 2.14.4

etiennelacoursiere avatar Apr 13 '23 15:04 etiennelacoursiere

The issue isn't present in Reanimated 3.6.1.

tjzel avatar Dec 15 '23 14:12 tjzel

This is still present in 3.6.1 on web. I tried to update react-native-svg to the latest one(14.1.0) but it doesn't work. Also I tried the workaround setting onPress with empty function, but didn't work too.

I found this happened because I used react-native-svg-web. Since react-native-svg supports web now, just removing the alias to it fixed the issue.

mk0116 avatar Jan 02 '24 01:01 mk0116