Open itsramiel opened 10 months ago
Hello @itsramiel, I tried to reproduce the issue, but couldn't. Let us know if you still have that issue, Thank you.
Hey @bohdanprog. I tested with latest versions as shown on the bottom of the left side and the issue is still there. I used the same code as in the reproducable
Hi @itsramiel, I tried your code and can confirm that its not working on iOS. That is related to the fact that while initializing the SVG, the stroke length is 0. If you add a simple timeout around "getTotalLength()", you will get the actual length and the animation will work.
For example:
export const Test = () => {
const progress = useSharedValue(1);
const ref = useRef<Path>(null);
const [pathLength, setPathLength] = useState<null | number>(null);
useEffect(() => {
const timeout = setTimeout(() => {
const res = ref.current?.getTotalLength();
if (typeof res === 'number') {
setPathLength(res);
}
}, 0)
return () => clearTimeout(timeout)
}, []);
useEffect(() => {
if (typeof pathLength === 'number') {
progress.value = withTiming(0, { duration: 3000 });
}
}, [pathLength]);
const animatedProps = useAnimatedProps(() => ({ strokeDashoffset: pathLength === null ? 0 : progress.value * pathLength }), [pathLength]);
return (
<View style={{ flex: 1, position: 'absolute', top: -70, left: -70, justifyContent: 'center', zIndex: 99 }}>
<Svg style={{ width: 268, height: 268, aspectRatio: WIDTH / HEIGHT }}>
<AnimatedPath
ref={ref}
d={d}
stroke={pathLength === null ? 'none' : 'white'}
fill={'none'}
strokeWidth={2}
strokeDasharray={pathLength ?? undefined}
animatedProps={animatedProps}
/>
</Svg>
</View>
);
}
Bug
Animating
strokeDashoffset
of a path does not work on IOS but works on Android. It works if the value ofstrokeDashoffset
andstrokeDasharray
do not switch betweenundefined
and the actual value I want. However in my case I want to know the length of the path and use that to animate the path, so when the path length is unknown I assignstrokeDasharray
and..offset
to undefinedUnexpected behavior
The unexpected behavior is that ios does not animate when it should.
Environment info
React native info output:
Library version: 14.1.0
Steps To Reproduce
Describe what you expected to happen:
Short, Self Contained, Correct (Compilable), Example