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
- Address renimated svg issue: https://github.com/software-mansion/react-native-reanimated/issues/3321#issuecomment-1256983430 — committed to draftbit/react-native-jigsaw by YoussefHenna a year ago
- Address renimated svg issue: https://github.com/software-mansion/react-native-reanimated/issues/3321#issuecomment-1256983430 — committed to draftbit/react-native-jigsaw by YoussefHenna a year ago
- Fix progress indicator issues on Snack (#704) * Wrap SVG container in a View to fix sizing on snack * Address renimated svg issue: https://github.com/software-mansion/react-native-reanimated/issues/... — committed to draftbit/react-native-jigsaw by YoussefHenna a year ago
- Fix progress indicator issues on Snack (47) (#705) * Wrap SVG container in a View to fix sizing on snack * Address renimated svg issue: https://github.com/software-mansion/react-native-reanimated/is... — committed to draftbit/react-native-jigsaw by YoussefHenna a year ago
I found workaround for this bug. Just set empty function for
onPress
prop of component you want to animate like this: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?