Created
August 5, 2019 13:16
-
-
Save luandevpro/f1c82ed28e826bceb6fadbd6828bfda0 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', 'yellow'], | |
}), | |
}; | |
return ( | |
<ScrollView | |
scrollEventThrottle={16} | |
onScroll={Animated.event([ | |
{ | |
nativeEvent: { | |
contentOffset: { | |
y: animated, | |
}, | |
}, | |
}, | |
])} | |
> | |
<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