question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Animating Svg component does not work on android

See original GitHub issue

Description

I am working on a progress loader component. The animation works on ios, but it doesn’t work on android. I have tried it on a couple of different emulators as well as as actual devices, the the animation just does not render Screen Shot 2022-09-05 at 11 18 51 AM

Steps to reproduce

Below is the code for the whole component

import React, { useEffect } from "react";
import { Modal, StyleSheet, Text, View } from "react-native";
import Animated, {
  useAnimatedProps,
  useSharedValue,
  withRepeat,
  withTiming,
} from "react-native-reanimated";
import Svg, { Circle } from "react-native-svg";


const CIRCLE_LENGTH = 201; // 2 * PI * r
const RADIUS = CIRCLE_LENGTH / (2 * Math.PI); // C / (2 * PI)
const STROKE_LENGTH = 4;

const AnimatedCircle = Animated.createAnimatedComponent(Circle);

export default function App() {
  const progress = useSharedValue(0);

  useEffect(() => {
    progress.value = withRepeat(withTiming(1, { duration: 5000 }), 100, true);
  }, [progress]);

  const animatedProps = useAnimatedProps(() => ({
    strokeDashoffset: CIRCLE_LENGTH * (1 - progress.value),
    strokeDasharray: CIRCLE_LENGTH,
  }));
  const baseCircleProps = {
    cx: RADIUS + STROKE_LENGTH / 2,
    cy: RADIUS + STROKE_LENGTH / 2,
    r: RADIUS,
    strokeWidth: STROKE_LENGTH,
    stroke: "#EEEEEE",
    // strokeLinecap: "round",
  };
  const baseAnimatedCircleProps = {
    ...baseCircleProps,
    stroke: "#161925",
    transform: `rotate(${-90},${RADIUS + STROKE_LENGTH / 2},${
      RADIUS + STROKE_LENGTH / 2
    })`,
  };

  return (
    <Modal animationType="fade" transparent={true} visible={true}>
      <View style={styles.background}>
        <View style={styles.progressContainer}>
          <Svg>
            <Circle {...baseCircleProps} />
            <AnimatedCircle
              animatedProps={animatedProps}
              {...baseAnimatedCircleProps}
            />
          </Svg>
          <Text numberOfLines={1} style={styles.loadingText}>
            Signing in...
          </Text>
        </View>
      </View>
    </Modal>
  );
}

const styles = StyleSheet.create({
  background: {
    backgroundColor: "#FFFFFF",
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
  },
  progressContainer: {
    width: RADIUS * 2 + STROKE_LENGTH,
    height: RADIUS * 2 + STROKE_LENGTH,
  },
  loadingText: {
    lineHeight: 20,
    fontSize: 16,
    textAlign: "center",
    marginTop: 27,
    overflow: "visible",
  },
});

Snack or a link to a repository

https://snack.expo.dev/@ianyimiah/reanimated-circular-progress-loader

Reanimated version

2.9.1

React Native version

0.69.5

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:17 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
iM-GeeKycommented, Nov 4, 2022

I’m posting here in the case this is an upstream issue, but I’m getting the error posted in the screenshot here and posted some findings here. Any insight would be appreciated.

1reaction
iM-GeeKycommented, Nov 4, 2022

The error from video should be resolved by adding this line: 8cf4068#diff-73bfcd6b9672fc9694913b10a232038470557fd02a8d688932f64cdc4dc26fbfR111. Can you check if it is present in your project files? It should be there in 13.5.0

Upgrading to 13.5.0 did resolve the issue. I appreciate the quick response! 🙌🏻

Read more comments on GitHub >

github_iconTop Results From Across the Web

android - Animated SVG file not animating - Stack Overflow
I have an animated .SVG that animates perfectly in the browser, but when I import it into Andoroid Studio via the Vector Asset...
Read more >
SVG animation not working; am I missing something? - GSAP
Hi, I am new to GSAP and HTML5/Javascript animation; I'm used to timeline animation in Flash and After Effects, but I think it's...
Read more >
<animate> - SVG: Scalable Vector Graphics - MDN Web Docs
The SVG element provides a way to animate an attribute of an element over time.
Read more >
Animate drawable graphics - Android Developers
Animated vector drawables can animate the attributes of the <group> and <path> elements. The <group> element defines a set of paths or subgroups,...
Read more >
Work with SVG files in Animate - Adobe Support
It is recommended that you view SVG on modern browsers with latest updates only. This is because, some graphic filters and color effects...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found