When using one AnimatedValue to interpolate several properties in one
View, it caused several redundant AnimatedNodes to be created for the
same AnimatedProps.
Additionally, the connections to the AnimatedProps were made before the
native node for the AnimatedProps was created, causing them not to work.
This splits the connection creation out from the makeNative call,
and calls it after all the required nodes are created.
Test App.js:
```jsx
import React, { Component } from 'react';
import { StyleSheet, View, Dimensions, Animated } from 'react-native';
import { Svg, Rect, Path } from 'react-native-svg';
const { width, height } = Dimensions.get('window');
const AnimatedRect = Animated.createAnimatedComponent(Rect);
const AnimatedPath = Animated.createAnimatedComponent(Path);
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, 1],
outputRange: [0, 1],
extrapolateRight: 'clamp',
});
const path = anim.interpolate({
inputRange: [0, 1],
outputRange: ['M20,20L20,80L80,80L80,20Z', 'M40,40L33,60L60,60L65,40Z'],
});
const fill = anim.interpolate({
inputRange: [0, 1],
outputRange: ['rgba(255, 0, 0, 0.5)', 'rgba(0, 255, 0, 0.99)'],
});
const oneToFivePx = anim.interpolate({
inputRange: [0, 1],
outputRange: ['1px', '5px'],
});
return { anim, fillOpacity, offset, strokeOpacity, path, fill, oneToFivePx };
}
export default class App extends Component {
state = getInitialState();
componentDidMount() {
const { anim } = this.state;
Animated.timing(anim, {
toValue: 1,
duration: 10000,
useNativeDriver: true,
}).start();
}
render() {
const { fillOpacity, offset, strokeOpacity, path, fill, oneToFivePx } = this.state;
return (
<View style={styles.container}>
<Svg width={width} height={height} viewBox="0 0 100 100">
<AnimatedRect
x="5"
y="5"
width="90"
height="90"
stroke="blue"
fill={fill}
strokeDasharray="1 1"
strokeWidth={oneToFivePx}
strokeDashoffset={offset}
strokeOpacity={strokeOpacity}
fillOpacity={fillOpacity}
/>
<AnimatedPath
d={path}
stroke="blue"
/>
</Svg>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
backgroundColor: '#ecf0f1',
},
});
```