-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transform <G> with setNativeProps possible? #556
Comments
@msageryd You probably need to use something like: |
Thank you so much! It works great. |
BTW. I had this on SO as well. I you'd like to chime in there I'll accept your answer. |
Great, posted a slightly more thorough answer there: https://stackoverflow.com/a/47995367/1925631 |
Cross-posting here for reference: The VirtualNode (android) and RNSVGNode (ios) implementations have setMatrix methods. Give new property values by sending a column-major array representation of a transform matrix definition over the bridge. As in:
|
The thing to note is that the composition of skews, rotations and translations is non-commutative, i.e., the result depends on the order of the transforms. And the six values do not correspond to parsing any kind of composition of these or angle interpretations, merely as scalar values using straight matrix interpretation. Thus the labels are slightly misleading, but gives at least some clues for how to interpret/adjust them if you want to bypass the transform parser. |
Hi @msand , if you have time can you please post a simple example of a component (Circle in a G) using an Animated value. Thanks |
https://snack.expo.io/@msand/shallow-celery import React, { Component } from 'react';
import { StyleSheet, View, Animated } from 'react-native';
import { Svg, Circle, G } from 'react-native-svg';
const AnimatedCircle = Animated.createAnimatedComponent(Circle);
function getInitialState() {
const anim = new Animated.Value(0);
const fillOpacity = anim.interpolate({
inputRange: [0, 1],
outputRange: [0, 1],
});
const offset = anim.interpolate({
inputRange: [0, 1],
outputRange: [0, 10],
});
const strokeOpacity = anim.interpolate({
inputRange: [0, 0.9],
outputRange: [0, 1],
extrapolateRight: 'clamp',
});
const strokeWidth = anim.interpolate({
inputRange: [0, 1],
outputRange: ['0', '5'],
});
return { anim, fillOpacity, offset, strokeOpacity, strokeWidth };
}
export default class App extends Component {
state = getInitialState();
componentDidMount() {
const { anim } = this.state;
Animated.timing(anim, {
toValue: 1,
duration: 3000,
useNativeDriver: true,
}).start();
}
render() {
const { fillOpacity, offset, strokeOpacity, strokeWidth } = this.state;
return (
<View style={styles.container}>
<Svg width="100%" height="100%" viewBox="0 0 100 100">
<G>
<AnimatedCircle
cx="50"
cy="50"
r="45"
height="90"
stroke="blue"
fill="green"
strokeDasharray="1 1"
strokeWidth={strokeWidth}
strokeDashoffset={offset}
strokeOpacity={strokeOpacity}
fillOpacity={fillOpacity}
/>
</G>
</Svg>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
backgroundColor: '#ecf0f1',
flex: 1,
},
}); |
I need to move and scale individual
<G>
elements with setNativeProps. Nothing I've tried seems to work.I tried:
If I use setNativeProps directly on a
<Circle>
for example, everything works fine.G
implement setNativeProps?The text was updated successfully, but these errors were encountered: