Created
August 5, 2019 13:08
-
-
Save luandevpro/26c6b07ae10096dd03ee04e91b50c91e to your computer and use it in GitHub Desktop.
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
import React, { useState } from 'react'; | |
import { | |
View, Text, Animated, StyleSheet, TouchableWithoutFeedback, ScrollView, | |
} from 'react-native'; | |
import PropTypes from 'prop-types'; | |
export default function Home() { | |
const [animated, setAnimated] = useState(new Animated.Value(0)); | |
const animatedEvent = { | |
backgroundColor: animated.interpolate({ | |
inputRange: [0, 3000], | |
outputRange: ['blue', 'red'], | |
}), | |
}; | |
return ( | |
<ScrollView | |
scrollEventThrottle={16} | |
onScroll={(e) => { | |
animated.setValue(e.nativeEvent.contentOffset.y); | |
}} | |
> | |
<View style={styles.container}> | |
<Animated.View | |
style={[styles.box, animatedEvent]} | |
/> | |
</View> | |
</ScrollView> | |
); | |
} | |
Home.propTypes = { | |
navigation: PropTypes.object , // eslint-disable-line | |
}; | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
justifyContent: 'center', | |
alignItems: 'center', | |
}, | |
box: { | |
width: '100%', | |
height: 3000, | |
backgroundColor: 'blue', | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment