Rotation via setNativeProps transform doesn't center
See original GitHub issueGreat library. I’m trying to work with 7.1.2 on iOS (no expo) to animate the rotation of a circle. The circle is definitely moving, but seems to be rotating around 0,0 - I need it to rotate around the center point (24, 24). Looks like originX/Y aren’t being applied in this scenario.
The code I’m currently using is below. Is this a way I can achieve center point rotation?
Happy to write a PR if the native code needs extending to support this.
Many thanks Tom
react-native-svg@7.1.2 react-native@0.57.1 xcode@10.0
import * as React from 'react'
import Svg, { Path, Circle } from 'react-native-svg'
import { Animated } from 'react-native'
const radius = 22.8
const circumference = radius * 2 * Math.PI
const offset = circumference - (40 / 100) * circumference
export class MicrophoneActiveIcon extends React.Component {
public circleRef: any
public state = {
rotation: new Animated.Value(-90)
}
public componentDidMount() {
Animated.loop(
Animated.timing(this.state.rotation, {
toValue: 270,
duration: 1000,
useNativeDriver: true
})
).start()
this.state.rotation.addListener(({ value }) => {
this.circleRef.setNativeProps({
transform: [{ rotate: value.toString() }]
})
})
}
public render() {
return (
<Svg width="48" height="48">
<Circle
ref={ref => {
this.circleRef = ref
}}
cx="24"
cy="24"
r={radius.toString()}
stroke="black"
strokeWidth={2}
fill="none"
originX="24"
originY="24"
strokeLinecap="round"
strokeDasharray={`${circumference.toString()} ${circumference.toString()}`}
strokeDashoffset={offset.toString()}
/>
</Svg>
)
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:7
Top Results From Across the Web
Rotation via setNativeProps transform doesn't center #815
Great library. I'm trying to work with 7.1.2 on iOS (no expo) to animate the rotation of a circle. The circle is definitely...
Read more >CSS rotation not centered - Stack Overflow
So I've got this circle that is rotating on hover but it's not centered and I don't know why (I did add the...
Read more >rotate() - CSS: Cascading Style Sheets - MDN Web Docs
The rotate() CSS function defines a transformation that rotates an element around a fixed point on the 2D plane, without deforming it.
Read more >CSS3 Transform not rotating from center - SitePoint
Hey guys! Anyone care to tell me why this link doesn't rotate from the center like the default specification states…. I'm stumped.
Read more >rotate | CSS-Tricks
While CSS already has another way to rotate elements using the rotate() function in the transform property, like this:
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for your detailed response @msand
I’ve tried all your suggestions and seem to be getting decent behaviour using this transform:
I’ve unset useNativeDriver as you suggest.
Favour owed, hit me up if you need PR work doing.
Or perhaps something like this:
Seems there’s something a bit unexpected with the transforms, will have to look into it later on.