-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Web] Not possible to interpolate / do SVG morphing with useAnimatedProps and 'react-native-svg' #1951
Comments
Issue validatorThe issue is valid! |
I have the same issue with these versions
|
Same issue here. I'm unable to animate SVG elements from 'react-native-svg' |
Same issue here |
As a temporary fix I forked the reanimated library and changed .\node_modules\react-native-reanimated\lib\reanimated2\js-reanimated\index.web.js code to this: // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
import JSReanimated from './JSReanimated';
const reanimatedJS = new JSReanimated();
global._frameTimestamp = null;
export const _updatePropsJS = (_viewTag, _viewName, updates, viewRef) => {
if (viewRef.current && viewRef.current._component) {
const [rawStyles] = Object.keys(updates).reduce((acc, key) => {
const value = updates[key];
const index = typeof value === 'function' ? 1 : 0;
acc[index][key] = value;
return acc;
}, [{}, {}]);
/* Previously it was only: viewRef.current._component.setNativeProps({ style: rawStyles });
which caused it to crash */
if (typeof viewRef.current._component.setNativeProps === 'function') {
viewRef.current._component.setNativeProps({ style: rawStyles });
} else if (viewRef.current._component.props.d) {
viewRef.current._component._touchableNode.setAttribute('d', rawStyles.d);
} else {
console.warn('It is not possible to manipulate component');
}
}
};
global._setGlobalConsole = (_val) => {
// noop
};
export default reanimatedJS; The fix does the job when morphing svg's on the web, but it is limited / focused to only manipulate the d property. |
Oh thanks, I was able to make it work. // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
import JSReanimated from './JSReanimated';
const reanimatedJS = new JSReanimated();
global._frameTimestamp = null;
export const _updatePropsJS = (_viewTag, _viewName, updates, viewRef) => {
if (viewRef.current && viewRef.current._component) {
const [rawStyles] = Object.keys(updates).reduce((acc, key) => {
const value = updates[key];
const index = typeof value === 'function' ? 1 : 0;
acc[index][key] = value;
return acc;
}, [{}, {}]);
if (typeof viewRef.current._component.setNativeProps === 'function') {
viewRef.current._component.setNativeProps({ style: rawStyles });
} else if (Object.keys(viewRef.current._component.props).length > 0) {
Object.keys(viewRef.current._component.props).forEach((key) => {
if (!rawStyles[key]) {
return;
}
const dashedKey = key.replace(/[A-Z]/g, m => "-" + m.toLowerCase());
viewRef.current._component._touchableNode.setAttribute(dashedKey, rawStyles[key]);
})
} else {
console.warn('It is not possible to manipulate component');
}
}
};
global._setGlobalConsole = (_val) => {
// noop
};
export default reanimatedJS; |
Same issue here. Patched reanimated with @Daavidaviid script and it worked. |
## Description Add the ability to animate svg components with `createAnimatedComponent` on the web. Cf : #1951 ## Checklist - [X] Ensured that CI passes
Thanks for the help! |
This fix seems to work with ReAnimated 2 SharedValues. However, when I try to get it working with Animated.Value from ReAnimated 1, it doesn't seem to do anything. Is there a way I can port this fix to ReAnimated 1 easily, without having to change my code to ReAnimated 2? |
@nandorojo The fix is introduced in latest 2.3.0-beta.2: |
Description
useAnimatedProps breaks when trying to interpolate / morph Path on web. While testing around with my own library and William Candillons I figured that the reason is located in ./react-native-reanimated/lib/reanimated2/js-reanimated/index.web.js.
setNativeProps is not a recognizable function anymore for web together with the library ‘react-native-svg’ since software-mansion/react-native-svg#1010.
Expected behavior
I expect a smooth morphing experience when interpolating path on web.
Video: http://somup.com/crfrIaFog8
Actual behavior & steps to reproduce
It currently crashes with the information:
How to reproduce:
Extra info: File where useAnimatedProps is implemented https://github.com/marcuzgabriel/reanimated-animation-library/blob/master/src/components/BottomSheet/MorphingArrow/index.tsx
Video: http://somup.com/crfrIxFogA
Snack or minimal code example
Working example:
Edit the following file in node_modules and remember to restart webpack otherwise changes wont take effect: '.\node_modules\react-native-reanimated\lib\reanimated2\js-reanimated\index.web.js' to:
Not working example:
Leave '.\node_modules\react-native-reanimated\lib\reanimated2\js-reanimated\index.web.js' intact so it is as original:
Problematic code
Line 14 in https://github.com/software-mansion/react-native-reanimated/blob/master/src/reanimated2/js-reanimated/index.web.ts:
viewRef.current._component.setNativeProps({ style: rawStyles });
Package versions
"react-native-web": "0.15.7",
Affected platforms
The text was updated successfully, but these errors were encountered: