From 474109ad710f8362666d887d4497110b4ffdf198 Mon Sep 17 00:00:00 2001 From: Bohdan Artiukhov <69891500+bohdanprog@users.noreply.github.com> Date: Thu, 13 Jun 2024 11:32:11 +0200 Subject: [PATCH] fixed pars on Android platform prop strokeDasharray (#2294) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Summary Closes #2248. Add the ability to parse `strokeDasharray` string value on the Android platform ## Test Plan Manually test both platforms. ## Compatibility | OS | Implemented | | ------- | :---------: | | iOS | ✅ | | Android | ✅ | --- TestsExample/App.js | 1 + TestsExample/src/Test2248.tsx | 59 +++++++++++++++++++ .../java/com/horcrux/svg/RenderableView.java | 10 +--- 3 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 TestsExample/src/Test2248.tsx diff --git a/TestsExample/App.js b/TestsExample/App.js index 4b665cbb..39724f5f 100644 --- a/TestsExample/App.js +++ b/TestsExample/App.js @@ -13,6 +13,7 @@ import Test2080 from './src/Test2080'; import Test2089 from './src/Test2089'; import Test2148 from './src/Test2148'; import Test2196 from './src/Test2196'; +import Test2248 from './src/Test2248'; import Test2266 from './src/Test2266'; import Test2276 from './src/Test2276'; diff --git a/TestsExample/src/Test2248.tsx b/TestsExample/src/Test2248.tsx new file mode 100644 index 00000000..51810e76 --- /dev/null +++ b/TestsExample/src/Test2248.tsx @@ -0,0 +1,59 @@ +import React, {useEffect, useRef} from 'react'; +import {Path, Svg} from 'react-native-svg'; +import {Animated} from 'react-native'; + +const AnimatedPath = Animated.createAnimatedComponent(Path as any); + +type Props = { + value: number; + color: string; +}; +const Test2248 = ({value = 86, color = '#ED745F'}: Props) => { + const animationValue = useRef(new Animated.Value(0)).current; + + useEffect(() => { + const animatePath = () => { + Animated.loop( + Animated.timing(animationValue, { + toValue: 1, + duration: 2000, + useNativeDriver: true, + }), + ).start(); + }; + + animatePath(); + + return () => { + animationValue.setValue(0); + }; + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + + return ( + + + + + ); +}; + +export default Test2248; diff --git a/android/src/main/java/com/horcrux/svg/RenderableView.java b/android/src/main/java/com/horcrux/svg/RenderableView.java index 316b19fb..e58e8c1d 100644 --- a/android/src/main/java/com/horcrux/svg/RenderableView.java +++ b/android/src/main/java/com/horcrux/svg/RenderableView.java @@ -254,13 +254,9 @@ public abstract class RenderableView extends VirtualView implements ReactHitSlop } public void setStrokeDasharray(Dynamic dynamicStrokeDasharray) { - if (!dynamicStrokeDasharray.isNull()) { - ReadableArray strokeDasharray = dynamicStrokeDasharray.asArray(); - int fromSize = strokeDasharray.size(); - this.strokeDasharray = new SVGLength[fromSize]; - for (int i = 0; i < fromSize; i++) { - this.strokeDasharray[i] = SVGLength.from(strokeDasharray.getDynamic(i)); - } + ArrayList arrayList = SVGLength.arrayFrom(dynamicStrokeDasharray); + if (arrayList != null) { + this.strokeDasharray = arrayList.toArray(new SVGLength[0]); } else { this.strokeDasharray = null; }