-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] Animated fix transforms on null values
- Loading branch information
Showing
2 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
packages/react-native-web-examples/pages/animated/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' } | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
869c416
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks