Skip to content

Commit

Permalink
[fix] Animated fix transforms on null values
Browse files Browse the repository at this point in the history
Fix #2528
Fix #2523
Close #2546
Close #2530
  • Loading branch information
necolas committed Jun 28, 2023
1 parent d200276 commit 869c416
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
59 changes: 59 additions & 0 deletions packages/react-native-web-examples/pages/animated/index.js
Original file line number Diff line number Diff line change
@@ -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' }
});
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

1 comment on commit 869c416

@dan-doyon-endear
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

Please sign in to comment.