Created
July 3, 2020 09:41
-
-
Save femicodes/d279e46c1237c66d9cdbe291ee4b521a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import React, { useState } from 'react'; | |
| import { | |
| SafeAreaView, | |
| View, | |
| Animated, | |
| TouchableOpacity, | |
| Text | |
| } from 'react-native'; | |
| const App = () => { | |
| const opacity = useState(new Animated.Value(0))[0] | |
| const fadeIn = () => { | |
| Animated.timing(opacity, { | |
| toValue: 1, | |
| duration: 2000, | |
| useNativeDriver: true | |
| }).start() | |
| /* Animated.timing(value, { | |
| toValue: { x: 100, y: 100 }, | |
| duration: 1000, | |
| useNativeDriver: false | |
| }).start() */ | |
| }; | |
| const fadeOut = () => { | |
| Animated.timing(opacity, { | |
| toValue: 0, | |
| duration: 2000, | |
| useNativeDriver: true | |
| }).start() | |
| }; | |
| return ( | |
| <SafeAreaView style={{ flex: 1 }}> | |
| <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}> | |
| <Animated.View | |
| style={{ | |
| backgroundColor: 'red', | |
| width: 100, | |
| height: 100, | |
| borderRadius: 100 / 2, | |
| opacity, | |
| }} /> | |
| <TouchableOpacity onPress={fadeIn}> | |
| <Text>fade in</Text> | |
| </TouchableOpacity> | |
| <TouchableOpacity onPress={fadeOut}> | |
| <Text>fade out</Text> | |
| </TouchableOpacity> | |
| </View> | |
| </SafeAreaView> | |
| ); | |
| }; | |
| export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment