[fix] Animated fix transforms on null values

Fix #2528
Fix #2523
Close #2546
Close #2530
This commit is contained in:
Nicolas Gallagher
2023-06-26 17:22:23 -07:00
parent d200276659
commit 869c416a36
2 changed files with 60 additions and 1 deletions
@@ -0,0 +1,59 @@
import React, { useRef } from 'react';
import { Animated, Pressable, StyleSheet, Text, View } from 'react-native';
import Example from '../../shared/example';
export default function AnimatedPage() {
const anim = useRef(new Animated.Value(0));
const animateBox = () => {
Animated.timing(anim.current, {
toValue: 1,
duration: 1000,
useNativeDriver: false
}).start();
};
const transform = anim.current.interpolate({
inputRange: [0, 1],
outputRange: ['rotate(0deg)', 'rotate(45deg)']
});
return (
<Example title="Animated">
<View style={styles.container}>
<Animated.View style={[styles.animatedBox, { transform: transform }]} />
<Pressable
onPress={animateBox}
style={({ pressed }) => [
styles.button,
{ opacity: pressed ? 0.4 : 1 }
]}
>
<Text style={styles.buttonText}>Animate Box</Text>
</Pressable>
</View>
</Example>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
animatedBox: {
width: 100,
height: 100,
backgroundColor: 'red',
alignSelf: 'center'
},
button: {
padding: 16,
paddingVertical: 8,
backgroundColor: 'blue',
borderRadius: 8,
marginTop: 24
},
buttonText: { color: 'white' }
});
@@ -24,7 +24,7 @@ function createAnimatedStyle(inputStyle: any): Object {
const animatedStyles = {}
for (const key in style) {
const value = style[key];
if (key === 'transform') {
if (key === 'transform' && Array.isArray(value)) {
animatedStyles[key] = new AnimatedTransform(value);
}
else if (value instanceof AnimatedNode) {