Skip to content

Commit 869c416

Browse files
committed
[fix] Animated fix transforms on null values
Fix #2528 Fix #2523 Close #2546 Close #2530
1 parent d200276 commit 869c416

File tree

2 files changed

+60
-1
lines changed
  • packages

2 files changed

+60
-1
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import React, { useRef } from 'react';
2+
import { Animated, Pressable, StyleSheet, Text, View } from 'react-native';
3+
import Example from '../../shared/example';
4+
5+
export default function AnimatedPage() {
6+
const anim = useRef(new Animated.Value(0));
7+
8+
const animateBox = () => {
9+
Animated.timing(anim.current, {
10+
toValue: 1,
11+
duration: 1000,
12+
useNativeDriver: false
13+
}).start();
14+
};
15+
16+
const transform = anim.current.interpolate({
17+
inputRange: [0, 1],
18+
outputRange: ['rotate(0deg)', 'rotate(45deg)']
19+
});
20+
21+
return (
22+
<Example title="Animated">
23+
<View style={styles.container}>
24+
<Animated.View style={[styles.animatedBox, { transform: transform }]} />
25+
<Pressable
26+
onPress={animateBox}
27+
style={({ pressed }) => [
28+
styles.button,
29+
{ opacity: pressed ? 0.4 : 1 }
30+
]}
31+
>
32+
<Text style={styles.buttonText}>Animate Box</Text>
33+
</Pressable>
34+
</View>
35+
</Example>
36+
);
37+
}
38+
39+
const styles = StyleSheet.create({
40+
container: {
41+
flex: 1,
42+
justifyContent: 'center',
43+
alignItems: 'center'
44+
},
45+
animatedBox: {
46+
width: 100,
47+
height: 100,
48+
backgroundColor: 'red',
49+
alignSelf: 'center'
50+
},
51+
button: {
52+
padding: 16,
53+
paddingVertical: 8,
54+
backgroundColor: 'blue',
55+
borderRadius: 8,
56+
marginTop: 24
57+
},
58+
buttonText: { color: 'white' }
59+
});

packages/react-native-web/src/vendor/react-native/Animated/nodes/AnimatedStyle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function createAnimatedStyle(inputStyle: any): Object {
2424
const animatedStyles = {}
2525
for (const key in style) {
2626
const value = style[key];
27-
if (key === 'transform') {
27+
if (key === 'transform' && Array.isArray(value)) {
2828
animatedStyles[key] = new AnimatedTransform(value);
2929
}
3030
else if (value instanceof AnimatedNode) {

0 commit comments

Comments
 (0)