Open esbenvb opened 1 month ago
Not sure if it's related, but I found a similar issue in my app after upgrading React Native from 0.73 to 0.76.3. This code, which is a gradient component for modals, worked fine on both iOS and Android before:
<Svg width="100%" height="100%" >
<Defs>
<LinearGradient id="grad" x1="0%" y1="0%" x2="0%" y2="100%">
<Stop offset="14.83%" stopColor={fromColor} />
<Stop offset="83.89%" stopColor={toColor} />
</LinearGradient>
</Defs>
<Rect width="100%" height="100%" fill="url(#grad)" />
</Svg>
With React Native 0.76 (old architecture), I encountered strange behavior with this: .
Randomly, it started rendering with something like width="80%". However, after making changes in the code (e.g., updating the width from 100 to 90 and then back to 100 during hot reload), it rendered properly as it should have initially at full width (100%).
I found a solution by using onLayout to set the SVG dimensions correctly.
const [svgWidth, setSvgWidth] = useState(0);
const [svgHeight, setSvgHeight] = useState(0);
const handleLayout = (event: LayoutChangeEvent) => {
const { width, height } = event.nativeEvent.layout;
setSvgWidth(width);
setSvgHeight(height);
};
return (
<View style={[styles.container, containerStyle]} onLayout={handleLayout}>
<View style={styles.backgroundContainer}>
<Svg width={svgWidth} height={svgHeight}>
<Defs>
<LinearGradient id="grad" x1="0%" y1="0%" x2="0%" y2="100%">
<Stop offset="14.83%" stopColor={fromColor} />
<Stop offset="83.89%" stopColor={toColor} />
</LinearGradient>
</Defs>
<Rect width="100%" height="100%" fill="url(#grad)" />
</Svg>
</View>
{children}
</View>
Description
Animated ClipPaths does not seem to update visually on Android.
If I change other SVG props, it seems to re-render based on the current animated value, the animation of a ClipPath property itself does not cause the SVG to re-render.
I have attached example code using the latest RN and RNSVG modules.
There's a related issue from 2022, but unfortunately I can't downgrade to the mentioned version as it won't build with React Native 0.75
https://github.com/software-mansion/react-native-svg/issues/1719
Steps to reproduce
Clone repo from the attached link or do the following:
Replace App.tsx with the code below and try the different variations. All works on iOS, but animated ClipPath does not work on Android.
Snack or a link to a repository
https://github.com/esbenvb/rnsvg-android-animated-clippath-issue-reproduction
SVG version
15.7.1
React Native version
0.75.4
Platforms
Android
JavaScript runtime
Hermes
Workflow
React Native
Architecture
Paper (Old Architecture)
Build type
Release app & production bundle
Device
Real device
Device model
Pixel 8 pro - Android 14, Samsung A14 - Android 14
Acknowledgements
Yes