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.

How to make the Image label rotate separately in svg

See original GitHub issue
import React, { Component } from 'react';
import {
  StyleSheet,
  View,
  Animated, Easing
} from 'react-native';

import Svg,{
  Text,
  Image,
} from 'react-native-svg';

const AnimatedSvg = Animated.createAnimatedComponent(Svg);

export default class App extends Component {
  constructor() {
    super();
    this.RotateValueHolder = new Animated.Value(0);
  }

  componentDidMount() {
    this.StartImageRotateFunction();
  }


  StartImageRotateFunction() {
    this.RotateValueHolder.setValue(0);
    Animated.timing(this.RotateValueHolder, {
      toValue: 1,
      duration: 10000,
      easing: Easing.linear,
      useNativeDriver:true
    }).start(()=>this.StartImageRotateFunction());
  }

  render() {
    return (
      <View style={styles.container}>
        <AnimatedSvg
        width="300"
        height="300"
        style={{
          transform: [
            {
              rotate: this.RotateValueHolder.interpolate({
                inputRange: [0, 1],
                outputRange: ['0deg', '360deg'],
              }),
            },
          ],
        }}
      >
      <Image
        width="100%"
        height="100%"
        href={require('./src/assets/bg.png')}
      />
      <Text
        x="50"
        y="50"
        textAnchor="middle"
        fontWeight="bold"
        fontSize="16"
        fill="blue"
    >HOGWARTS</Text>
      </AnimatedSvg>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },

});

How to make the iamge tag rotate alone not complete <Svg>? I have tried const AnimatedImage = Animated.createAnimatedComponent(Image); and put <svg> style move this const it’s not working

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:17

github_iconTop GitHub Comments

2reactions
lrengaocommented, Feb 19, 2019

I am going to try,

I am very honored to meet you. @msand

0reactions
juandiegombrcommented, Mar 20, 2019

Hello.

I arrived to this question after trying different approaches to animate the rotation of a Path in a Svg. I have tried the examples above in the expo playground and I have noticed a difference between using Svg from expo and from ‘react-native-svg’.

In my plain react-native project I got the rotate animation in a Svg component but not in any of the children. Without expo, AnimatedG or any other Animated component besides AnimatedSvg is not working to me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make the Image label rotate separately in svg #940
How to make the iamge tag rotate alone not complete ? I have tried const AnimatedImage = Animated.createAnimatedComponent(Image); and put style ...
Read more >
Transforms on SVG Elements | CSS-Tricks
In the case of SVG transform attributes, the rotation function is a bit different – rotate(angle[ x y]) . The angle value works...
Read more >
Reversing the flip and rotation of an image fill in a path that is ...
If the path is only rotated (in this case, 315 degrees), it's easy to unrotate the image by just reversing the angle in...
Read more >
SVG images, label rotation, mockups gallery wizard
This launches the website in a separate tab and lets you browse available components. Clicking a download link launches the Mockups Gallery ...
Read more >
SVG Tutorial – How to Code Images with 7 Examples
The SVG tag represents the frame of the image and every SVG element has to come within an SVG tag. The same is...
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